From b5866a19c9adf025da25b33d156e9321cffe286b Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Thu, 27 Jun 2024 12:36:33 -0300 Subject: [PATCH] test: close pages properly (#32681) --- apps/meteor/tests/e2e/admin-room.spec.ts | 12 +- .../tests/e2e/channel-management.spec.ts | 273 +++++++++--------- .../fragments/home-flextab-members.ts | 5 + 3 files changed, 145 insertions(+), 145 deletions(-) diff --git a/apps/meteor/tests/e2e/admin-room.spec.ts b/apps/meteor/tests/e2e/admin-room.spec.ts index 2e79a0e745ea..ff560e9013ed 100644 --- a/apps/meteor/tests/e2e/admin-room.spec.ts +++ b/apps/meteor/tests/e2e/admin-room.spec.ts @@ -17,16 +17,8 @@ test.describe.serial('admin-rooms', () => { await page.goto('/admin/rooms'); }); - test.beforeAll(async ({ browser, api }) => { - [channel, privateRoom] = await Promise.all([ - createTargetChannel(api), - createTargetPrivateChannel(api), - browser.newPage({ storageState: Users.admin.state }).then(async (page) => { - await page.goto('/home'); - await page.waitForSelector('[data-qa-id="home-header"]'); - return page; - }), - ]); + test.beforeAll(async ({ api }) => { + [channel, privateRoom] = await Promise.all([createTargetChannel(api), createTargetPrivateChannel(api)]); }); test('should display the Rooms Table', async ({ page }) => { diff --git a/apps/meteor/tests/e2e/channel-management.spec.ts b/apps/meteor/tests/e2e/channel-management.spec.ts index 8d682efe095a..ee06baf84b83 100644 --- a/apps/meteor/tests/e2e/channel-management.spec.ts +++ b/apps/meteor/tests/e2e/channel-management.spec.ts @@ -67,122 +67,6 @@ test.describe.serial('channel-management', () => { await expect(poHomeChannel.getSystemMessageByText('added user1')).toBeVisible(); }); - test('should ignore user1 messages', async ({ browser }) => { - await poHomeChannel.sidenav.openChat(targetChannel); - await poHomeChannel.tabs.btnTabMembers.click(); - await poHomeChannel.tabs.members.showAllUsers(); - await poHomeChannel.tabs.members.ignoreUser('user1'); - - await poHomeChannel.tabs.members.openMoreActions(); - await expect(poHomeChannel.tabs.members.getMenuItemAction('Unignore')).toBeVisible(); - - const user1Page = await browser.newPage({ storageState: Users.user1.state }); - const user1Channel = new HomeChannel(user1Page); - await user1Page.goto(`/channel/${targetChannel}`); - await user1Channel.waitForChannel(); - await user1Channel.content.sendMessage('message to check ignore'); - - await expect(poHomeChannel.content.lastUserMessageBody).toContainText('This message was ignored'); - - await user1Page.close(); - }); - - test('should unignore single user1 message', async ({ browser }) => { - await poHomeChannel.sidenav.openChat(targetChannel); - - const user1Page = await browser.newPage({ storageState: Users.user1.state }); - const user1Channel = new HomeChannel(user1Page); - await user1Page.goto(`/channel/${targetChannel}`); - await user1Channel.waitForChannel(); - await user1Channel.content.sendMessage('only message to be unignored'); - - await poHomeChannel.sidenav.openChat(targetChannel); - - await expect(poHomeChannel.content.lastUserMessageBody).toContainText('This message was ignored'); - await poHomeChannel.content.lastIgnoredUserMessage.click(); - await expect(poHomeChannel.content.lastUserMessageBody).toContainText('only message to be unignored'); - - await user1Page.close(); - }); - - test('should unignore user1 messages', async ({ browser }) => { - const user1Page = await browser.newPage({ storageState: Users.user1.state }); - const user1Channel = new HomeChannel(user1Page); - await user1Page.goto(`/channel/${targetChannel}`); - await user1Channel.waitForChannel(); - await user1Channel.content.sendMessage('message before being unignored'); - - await poHomeChannel.sidenav.openChat(targetChannel); - await expect(poHomeChannel.content.lastUserMessageBody).toContainText('This message was ignored'); - - await poHomeChannel.tabs.btnTabMembers.click(); - await poHomeChannel.tabs.members.showAllUsers(); - await poHomeChannel.tabs.members.unignoreUser('user1'); - - await poHomeChannel.tabs.members.openMoreActions(); - await expect(poHomeChannel.tabs.members.getMenuItemAction('Ignore')).toBeVisible(); - - await user1Channel.content.sendMessage('message after being unignored'); - - await expect(poHomeChannel.content.nthMessage(-2)).toContainText('message before being unignored'); - await expect(poHomeChannel.content.lastUserMessageBody).toContainText('message after being unignored'); - - await user1Page.close(); - }); - - test('should mute user1', async ({ browser }) => { - await poHomeChannel.sidenav.openChat(targetChannel); - await poHomeChannel.tabs.btnTabMembers.click(); - await poHomeChannel.tabs.members.showAllUsers(); - await poHomeChannel.tabs.members.muteUser('user1'); - - await expect(poHomeChannel.getSystemMessageByText('muted user1')).toBeVisible(); - - const user1Page = await browser.newPage({ storageState: Users.user1.state }); - const user1Channel = new HomeChannel(user1Page); - await user1Page.goto(`/channel/${targetChannel}`); - await user1Channel.waitForChannel(); - await expect(user1Channel.readOnlyFooter).toBeVisible(); - - await user1Page.close(); - }); - - test('should set user1 as moderator', async ({ browser }) => { - await poHomeChannel.sidenav.openChat(targetChannel); - await poHomeChannel.tabs.btnTabMembers.click(); - await poHomeChannel.tabs.members.showAllUsers(); - await poHomeChannel.tabs.members.setUserAsModerator('user1'); - - await expect(poHomeChannel.getSystemMessageByText('set user1 as moderator')).toBeVisible(); - - const user1Page = await browser.newPage({ storageState: Users.user1.state }); - const user1Channel = new HomeChannel(user1Page); - await user1Page.goto(`/channel/${targetChannel}`); - await user1Channel.waitForChannel(); - await user1Channel.tabs.btnRoomInfo.click(); - await expect(user1Channel.tabs.room.btnEdit).toBeVisible(); - - await user1Page.close(); - }); - - test('should set user1 as owner', async ({ browser }) => { - await poHomeChannel.sidenav.openChat(targetChannel); - await poHomeChannel.tabs.btnTabMembers.click(); - await poHomeChannel.tabs.members.showAllUsers(); - await poHomeChannel.tabs.members.setUserAsOwner('user1'); - - await expect(poHomeChannel.getSystemMessageByText('set user1 as owner')).toBeVisible(); - - const user1Page = await browser.newPage({ storageState: Users.user1.state }); - const user1Channel = new HomeChannel(user1Page); - await user1Page.goto(`/channel/${targetChannel}`); - await user1Channel.waitForChannel(); - await user1Channel.tabs.btnRoomInfo.click(); - await expect(user1Channel.tabs.room.btnDelete).toBeVisible(); - - await user1Page.close(); - }); - test('should edit topic of targetChannel', async ({ page }) => { await poHomeChannel.sidenav.openChat(targetChannel); await poHomeChannel.tabs.btnRoomInfo.click(); @@ -302,24 +186,143 @@ test.describe.serial('channel-management', () => { await expect(poHomeChannel.tabs.notificationPreferences.getPreferenceByDevice('Email')).toContainText('Mentions'); }); - let regularUserPage: Page; - test('should readOnlyChannel show join button', async ({ browser }) => { - const channelName = faker.string.uuid(); - - await poHomeChannel.sidenav.openNewByLabel('Channel'); - await poHomeChannel.sidenav.inputChannelName.fill(channelName); - await poHomeChannel.sidenav.checkboxPrivateChannel.click(); - await poHomeChannel.sidenav.checkboxReadOnly.click(); - await poHomeChannel.sidenav.btnCreate.click(); - - regularUserPage = await browser.newPage({ storageState: Users.user2.state }); - - const channel = new HomeChannel(regularUserPage); - - await regularUserPage.goto(`/channel/${channelName}`); - await channel.waitForChannel(); - await expect(regularUserPage.locator('button >> text="Join"')).toBeVisible(); - - await regularUserPage.close(); + test.describe.serial('cross user tests', () => { + let user1Page: Page; + test.beforeEach(async ({ browser }) => { + user1Page = await browser.newPage({ storageState: Users.user1.state }); + }); + + test.afterEach(async () => { + await user1Page.close(); + }); + + test('should mute user1', async () => { + await poHomeChannel.sidenav.openChat(targetChannel); + await poHomeChannel.tabs.btnTabMembers.click(); + await poHomeChannel.tabs.members.showAllUsers(); + await poHomeChannel.tabs.members.muteUser('user1'); + + await expect(poHomeChannel.getSystemMessageByText('muted user1')).toBeVisible(); + + const user1Channel = new HomeChannel(user1Page); + await user1Page.goto(`/channel/${targetChannel}`); + await user1Channel.waitForChannel(); + await expect(user1Channel.readOnlyFooter).toBeVisible(); + }); + + test('should unmuteUser user1', async () => { + await poHomeChannel.sidenav.openChat(targetChannel); + await poHomeChannel.tabs.btnTabMembers.click(); + await poHomeChannel.tabs.members.showAllUsers(); + await poHomeChannel.tabs.members.unmuteUser('user1'); + + await expect(poHomeChannel.getSystemMessageByText('unmuted user1')).toBeVisible(); + + const user1Channel = new HomeChannel(user1Page); + await user1Page.goto(`/channel/${targetChannel}`); + await user1Channel.waitForChannel(); + await expect(user1Channel.composer).toBeVisible(); + }); + + test('should set user1 as moderator', async () => { + await poHomeChannel.sidenav.openChat(targetChannel); + await poHomeChannel.tabs.btnTabMembers.click(); + await poHomeChannel.tabs.members.showAllUsers(); + await poHomeChannel.tabs.members.setUserAsModerator('user1'); + + await expect(poHomeChannel.getSystemMessageByText('set user1 as moderator')).toBeVisible(); + + const user1Channel = new HomeChannel(user1Page); + await user1Page.goto(`/channel/${targetChannel}`); + await user1Channel.waitForChannel(); + await user1Channel.tabs.btnRoomInfo.click(); + await expect(user1Channel.tabs.room.btnEdit).toBeVisible(); + }); + + test('should set user1 as owner', async () => { + await poHomeChannel.sidenav.openChat(targetChannel); + await poHomeChannel.tabs.btnTabMembers.click(); + await poHomeChannel.tabs.members.showAllUsers(); + await poHomeChannel.tabs.members.setUserAsOwner('user1'); + + await expect(poHomeChannel.getSystemMessageByText('set user1 as owner')).toBeVisible(); + + const user1Channel = new HomeChannel(user1Page); + await user1Page.goto(`/channel/${targetChannel}`); + await user1Channel.waitForChannel(); + await user1Channel.tabs.btnRoomInfo.click(); + await expect(user1Channel.tabs.room.btnDelete).toBeVisible(); + + await user1Page.close(); + }); + test('should ignore user1 messages', async () => { + await poHomeChannel.sidenav.openChat(targetChannel); + await poHomeChannel.tabs.btnTabMembers.click(); + await poHomeChannel.tabs.members.showAllUsers(); + await poHomeChannel.tabs.members.ignoreUser('user1'); + + await poHomeChannel.tabs.members.openMoreActions(); + await expect(poHomeChannel.tabs.members.getMenuItemAction('Unignore')).toBeVisible(); + + const user1Channel = new HomeChannel(user1Page); + await user1Page.goto(`/channel/${targetChannel}`); + await user1Channel.waitForChannel(); + await user1Channel.content.sendMessage('message to check ignore'); + + await expect(poHomeChannel.content.lastUserMessageBody).toContainText('This message was ignored'); + }); + + test('should unignore single user1 message', async () => { + await poHomeChannel.sidenav.openChat(targetChannel); + + const user1Channel = new HomeChannel(user1Page); + await user1Page.goto(`/channel/${targetChannel}`); + await user1Channel.waitForChannel(); + await user1Channel.content.sendMessage('only message to be unignored'); + + await poHomeChannel.sidenav.openChat(targetChannel); + + await expect(poHomeChannel.content.lastUserMessageBody).toContainText('This message was ignored'); + await poHomeChannel.content.lastIgnoredUserMessage.click(); + await expect(poHomeChannel.content.lastUserMessageBody).toContainText('only message to be unignored'); + }); + + test('should unignore user1 messages', async () => { + const user1Channel = new HomeChannel(user1Page); + await user1Page.goto(`/channel/${targetChannel}`); + await user1Channel.waitForChannel(); + await user1Channel.content.sendMessage('message before being unignored'); + + await poHomeChannel.sidenav.openChat(targetChannel); + await expect(poHomeChannel.content.lastUserMessageBody).toContainText('This message was ignored'); + + await poHomeChannel.tabs.btnTabMembers.click(); + await poHomeChannel.tabs.members.showAllUsers(); + await poHomeChannel.tabs.members.unignoreUser('user1'); + + await poHomeChannel.tabs.members.openMoreActions(); + await expect(poHomeChannel.tabs.members.getMenuItemAction('Ignore')).toBeVisible(); + + await user1Channel.content.sendMessage('message after being unignored'); + + await expect(poHomeChannel.content.nthMessage(-2)).toContainText('message before being unignored'); + await expect(poHomeChannel.content.lastUserMessageBody).toContainText('message after being unignored'); + }); + + test('should readOnlyChannel show join button', async () => { + const channelName = faker.string.uuid(); + + await poHomeChannel.sidenav.openNewByLabel('Channel'); + await poHomeChannel.sidenav.inputChannelName.fill(channelName); + await poHomeChannel.sidenav.checkboxPrivateChannel.click(); + await poHomeChannel.sidenav.checkboxReadOnly.click(); + await poHomeChannel.sidenav.btnCreate.click(); + + const channel = new HomeChannel(user1Page); + + await user1Page.goto(`/channel/${channelName}`); + await channel.waitForChannel(); + await expect(user1Page.locator('button >> text="Join"')).toBeVisible(); + }); }); }); diff --git a/apps/meteor/tests/e2e/page-objects/fragments/home-flextab-members.ts b/apps/meteor/tests/e2e/page-objects/fragments/home-flextab-members.ts index 508362429b22..d4a9638691be 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/home-flextab-members.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/home-flextab-members.ts @@ -46,6 +46,11 @@ export class HomeFlextabMembers { await this.page.getByRole('dialog').getByRole('button').first().click(); } + async unmuteUser(username: string) { + await this.openMemberOptionMoreActions(username); + await this.getMenuItemAction('Unmute user').click(); + } + async setUserAsModerator(username: string) { await this.openMemberOptionMoreActions(username); await this.getMenuItemAction('Set as moderator').click();