Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Mention @all @here flaky test #32731

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 74 additions & 60 deletions apps/meteor/tests/e2e/message-mentions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getMentionText = (username: string, kind?: number): string => {
return `Hello @${username}, how are you`;
};

test.describe.serial('message-mentions', () => {
test.describe.serial('Should not allow to send @all mention if permission to do so is disabled', () => {
let poHomeChannel: HomeChannel;

test.beforeEach(async ({ page }) => {
Expand All @@ -29,82 +29,96 @@ test.describe.serial('message-mentions', () => {
await page.goto('/home');
});

test('expect show "all" and "here" options', async () => {
await poHomeChannel.sidenav.openChat('general');
await poHomeChannel.content.inputMessage.type('@');
let targetChannel2: string;
test.beforeAll(async ({ api }) => {
expect((await api.post('/permissions.update', { permissions: [{ _id: 'mention-all', roles: [] }] })).status()).toBe(200);
});

await expect(poHomeChannel.content.messagePopupUsers.locator('role=listitem >> text="all"')).toBeVisible();
await expect(poHomeChannel.content.messagePopupUsers.locator('role=listitem >> text="here"')).toBeVisible();
test.afterAll(async ({ api }) => {
expect(
(
await api.post('/permissions.update', { permissions: [{ _id: 'mention-all', roles: ['admin', 'owner', 'moderator', 'user'] }] })
).status(),
).toBe(200);
await deleteChannel(api, targetChannel2);
});

test.describe('Should not allow to send @all mention if permission to do so is disabled', () => {
let targetChannel2: string;
test.beforeAll(async ({ api }) => {
expect((await api.post('/permissions.update', { permissions: [{ _id: 'mention-all', roles: [] }] })).status()).toBe(200);
});
test('expect to receive an error as notification when sending @all while permission is disabled', async ({ page }) => {
const adminPage = new HomeChannel(page);

test.afterAll(async ({ api }) => {
expect(
(
await api.post('/permissions.update', { permissions: [{ _id: 'mention-all', roles: ['admin', 'owner', 'moderator', 'user'] }] })
).status(),
).toBe(200);
await deleteChannel(api, targetChannel2);
await test.step('create private room', async () => {
targetChannel2 = faker.string.uuid();

await poHomeChannel.sidenav.openNewByLabel('Channel');
await poHomeChannel.sidenav.inputChannelName.type(targetChannel2);
await poHomeChannel.sidenav.btnCreate.click();

await expect(page).toHaveURL(`/group/${targetChannel2}`);
});
await test.step('receive notify message', async () => {
await adminPage.content.dispatchSlashCommand('@all');
await expect(adminPage.content.lastUserMessage).toContainText('Notify all in this room is not allowed');
});
});
});

test('expect to receive an error as notification when sending @all while permission is disabled', async ({ page }) => {
const adminPage = new HomeChannel(page);
test.describe.serial('Should not allow to send @here mention if permission to do so is disabled', () => {
let poHomeChannel: HomeChannel;

await test.step('create private room', async () => {
targetChannel2 = faker.string.uuid();
test.beforeEach(async ({ page }) => {
poHomeChannel = new HomeChannel(page);

await poHomeChannel.sidenav.openNewByLabel('Channel');
await poHomeChannel.sidenav.inputChannelName.type(targetChannel2);
await poHomeChannel.sidenav.btnCreate.click();
await page.goto('/home');
});

await expect(page).toHaveURL(`/group/${targetChannel2}`);
});
await test.step('receive notify message', async () => {
await adminPage.sidenav.openChat(targetChannel2);
await adminPage.content.dispatchSlashCommand('@all');
await expect(adminPage.content.lastUserMessage).toContainText('Notify all in this room is not allowed');
});
});
let targetChannel2: string;
test.beforeAll(async ({ api }) => {
expect((await api.post('/permissions.update', { permissions: [{ _id: 'mention-here', roles: [] }] })).status()).toBe(200);
});

test.describe('Should not allow to send @here mention if permission to do so is disabled', () => {
let targetChannel2: string;
test.beforeAll(async ({ api }) => {
expect((await api.post('/permissions.update', { permissions: [{ _id: 'mention-here', roles: [] }] })).status()).toBe(200);
});
test.afterAll(async ({ api }) => {
expect(
(
await api.post('/permissions.update', { permissions: [{ _id: 'mention-here', roles: ['admin', 'owner', 'moderator', 'user'] }] })
).status(),
).toBe(200);
await deleteChannel(api, targetChannel2);
});

test.afterAll(async ({ api }) => {
expect(
(
await api.post('/permissions.update', { permissions: [{ _id: 'mention-here', roles: ['admin', 'owner', 'moderator', 'user'] }] })
).status(),
).toBe(200);
await deleteChannel(api, targetChannel2);
test('expect to receive an error as notification when sending here while permission is disabled', async ({ page }) => {
const adminPage = new HomeChannel(page);

await test.step('create private room', async () => {
targetChannel2 = faker.string.uuid();

await poHomeChannel.sidenav.openNewByLabel('Channel');
await poHomeChannel.sidenav.inputChannelName.type(targetChannel2);
await poHomeChannel.sidenav.btnCreate.click();

await expect(page).toHaveURL(`/group/${targetChannel2}`);
});
await test.step('receive notify message', async () => {
await adminPage.content.dispatchSlashCommand('@here');
await expect(adminPage.content.lastUserMessage).toContainText('Notify all in this room is not allowed');
});
});
});

test('expect to receive an error as notification when sending here while permission is disabled', async ({ page }) => {
const adminPage = new HomeChannel(page);
test.describe.serial('message-mentions', () => {
let poHomeChannel: HomeChannel;

await test.step('create private room', async () => {
targetChannel2 = faker.string.uuid();
test.beforeEach(async ({ page }) => {
poHomeChannel = new HomeChannel(page);

await poHomeChannel.sidenav.openNewByLabel('Channel');
await poHomeChannel.sidenav.inputChannelName.type(targetChannel2);
await poHomeChannel.sidenav.btnCreate.click();
await page.goto('/home');
});

await expect(page).toHaveURL(`/group/${targetChannel2}`);
});
await test.step('receive notify message', async () => {
await adminPage.sidenav.openChat(targetChannel2);
await adminPage.content.dispatchSlashCommand('@here');
await expect(adminPage.content.lastUserMessage).toContainText('Notify all in this room is not allowed');
});
});
test('expect show "all" and "here" options', async () => {
await poHomeChannel.sidenav.openChat('general');
await poHomeChannel.content.inputMessage.type('@');

await expect(poHomeChannel.content.messagePopupUsers.locator('role=listitem >> text="all"')).toBeVisible();
await expect(poHomeChannel.content.messagePopupUsers.locator('role=listitem >> text="here"')).toBeVisible();
});

test.describe('users not in channel', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class HomeContent {
async dispatchSlashCommand(text: string): Promise<void> {
await this.joinRoomIfNeeded();
await this.page.waitForSelector('[name="msg"]:not([disabled])');
await this.page.locator('[name="msg"]').fill('');
await this.page.locator('[name="msg"]').type(text);
await this.page.keyboard.press('Enter');
await this.page.keyboard.press('Enter');
Expand Down
Loading