From e16a3b53055c9c4565d9be93e56b3bd2516939dd Mon Sep 17 00:00:00 2001 From: Ramon Souza Date: Wed, 18 May 2022 22:46:55 -0300 Subject: [PATCH 1/9] test: add doLogout --- apps/meteor/tests/e2e/utils/pageobjects/SideNav.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/meteor/tests/e2e/utils/pageobjects/SideNav.ts b/apps/meteor/tests/e2e/utils/pageobjects/SideNav.ts index 195bda6856f4..ca3a5d4c9057 100644 --- a/apps/meteor/tests/e2e/utils/pageobjects/SideNav.ts +++ b/apps/meteor/tests/e2e/utils/pageobjects/SideNav.ts @@ -246,6 +246,12 @@ class SideNav extends BasePage { await this.searchInput().type(userName, { delay: 300 }); await this.getPage().keyboard.press(ENTER); } + + public async doLogout(): Promise { + await this.getPage().goto('/home'); + await this.sidebarUserMenu().click(); + await this.logout().click(); + } } export default SideNav; From 107b9639372feaa2d6c418cbdc887557730d438e Mon Sep 17 00:00:00 2001 From: Ramon Souza Date: Wed, 18 May 2022 22:47:27 -0300 Subject: [PATCH 2/9] test: add doReload --- apps/meteor/tests/e2e/utils/pageobjects/MainContent.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/meteor/tests/e2e/utils/pageobjects/MainContent.ts b/apps/meteor/tests/e2e/utils/pageobjects/MainContent.ts index 3b1be1b7a1f6..a929610b3097 100644 --- a/apps/meteor/tests/e2e/utils/pageobjects/MainContent.ts +++ b/apps/meteor/tests/e2e/utils/pageobjects/MainContent.ts @@ -436,6 +436,11 @@ class MainContent extends BasePage { public viewUserProfile(): Locator { return this.getPage().locator('[data-qa="UserCard"] a'); } + + public async doReload(): Promise { + await this.getPage().reload({ waitUntil: 'load' }); + await this.getPage().waitForSelector('.messages-box'); + } } export default MainContent; From fa9272bc89ca8419ba31524d00810ef6576f04fd Mon Sep 17 00:00:00 2001 From: Ramon Souza Date: Wed, 18 May 2022 22:48:14 -0300 Subject: [PATCH 3/9] test: add doAddRole --- apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts b/apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts index 038d0e00d794..00fc75ee1bfe 100644 --- a/apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts +++ b/apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts @@ -548,6 +548,11 @@ class FlexTab extends BasePage { 'div.thread-list.js-scroll-thread ul.thread [data-qa-type="message"]:last-child div.message-body-wrapper [data-qa-type="message-body"]', ); } + + public async doAddRole(role: string): Promise { + await this.usersAddUserRoleList().click(); + await this.getPage().locator(`li[value=${role}]`).click(); + } } export default FlexTab; From 22f46ccfd2bb3091ee1530591493cc3574ab3003 Mon Sep 17 00:00:00 2001 From: Ramon Souza Date: Wed, 18 May 2022 22:48:44 -0300 Subject: [PATCH 4/9] test: fix usersAddUserEmail locator --- apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts b/apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts index 00fc75ee1bfe..ca31a404944d 100644 --- a/apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts +++ b/apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts @@ -316,7 +316,7 @@ class FlexTab extends BasePage { } public usersAddUserEmail(): Locator { - return this.getPage().locator('//label[text()="Email"]/following-sibling::span//input/following-sibling::span//i'); + return this.getPage().locator('//label[text()="Email"]/following-sibling::span//input').first(); } public usersAddUserRoleList(): Locator { From f172fd8d4f78aa54211b4cef0b2c60ee67bdb4c5 Mon Sep 17 00:00:00 2001 From: Ramon Souza Date: Wed, 18 May 2022 22:49:30 -0300 Subject: [PATCH 5/9] test: add getCheckboxPermission, inputPermissionsSearch and userInTable --- .../tests/e2e/utils/pageobjects/Administration.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/meteor/tests/e2e/utils/pageobjects/Administration.ts b/apps/meteor/tests/e2e/utils/pageobjects/Administration.ts index 729dc4607bd9..c571fdcda89f 100644 --- a/apps/meteor/tests/e2e/utils/pageobjects/Administration.ts +++ b/apps/meteor/tests/e2e/utils/pageobjects/Administration.ts @@ -119,6 +119,10 @@ export default class Administration extends BasePage { return this.getPage().locator('input[placeholder="Search Users"]'); } + public userInTable(id: string): Locator { + return this.getPage().locator(`tr > td:has-text("${id}")`); + } + public rolesNewRolesButton(): Locator { return this.getPage().locator('button[aria-label="New"]'); } @@ -688,4 +692,12 @@ export default class Administration extends BasePage { public async adminSaveChanges(): Promise { await this.buttonSave().click(); } + + public inputPermissionsSearch(): Locator { + return this.getPage().locator('.main-content input[placeholder="Search"]'); + } + + public getCheckboxPermission(label: string, column = 6): Locator { + return this.getPage().locator(`tr td:has-text("${label}") ~ td:nth-child(${column})`).locator('label').first(); + } } From a23d2ae9689d4d67b839eaafff453e0295c02708 Mon Sep 17 00:00:00 2001 From: Ramon Souza Date: Wed, 18 May 2022 22:50:06 -0300 Subject: [PATCH 6/9] test: add username? field in IRegister --- apps/meteor/tests/e2e/utils/interfaces/Login.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/meteor/tests/e2e/utils/interfaces/Login.ts b/apps/meteor/tests/e2e/utils/interfaces/Login.ts index fdba700a1851..d49214aa628a 100644 --- a/apps/meteor/tests/e2e/utils/interfaces/Login.ts +++ b/apps/meteor/tests/e2e/utils/interfaces/Login.ts @@ -7,4 +7,5 @@ export interface IRegister { email: string; password: string; name: string; + username?: string; } From 0d6d29a1029e372b994a576fc0402a905378dd9d Mon Sep 17 00:00:00 2001 From: Ramon Souza Date: Wed, 18 May 2022 22:50:31 -0300 Subject: [PATCH 7/9] test: add registerUser factory --- apps/meteor/tests/e2e/utils/mocks/userAndPasswordMock.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/meteor/tests/e2e/utils/mocks/userAndPasswordMock.ts b/apps/meteor/tests/e2e/utils/mocks/userAndPasswordMock.ts index 5ea25bf9d950..3b40da08d720 100644 --- a/apps/meteor/tests/e2e/utils/mocks/userAndPasswordMock.ts +++ b/apps/meteor/tests/e2e/utils/mocks/userAndPasswordMock.ts @@ -27,6 +27,13 @@ export const registerUser: IRegister = { name: faker.name.findName(), }; +export const createRegisterUser = (): IRegister => ({ + email: validEmail, + password: 'any_password', + name: faker.name.findName(), + username: faker.internet.userName(), +}); + export const validUser: ILogin = { email: validEmail, password: 'any_password', From 9c882bf5f34036f03fbd6fd4d74c45a6e0602d02 Mon Sep 17 00:00:00 2001 From: Ramon Souza Date: Wed, 18 May 2022 22:51:00 -0300 Subject: [PATCH 8/9] test: create page objects index --- apps/meteor/tests/e2e/utils/pageobjects/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 apps/meteor/tests/e2e/utils/pageobjects/index.ts diff --git a/apps/meteor/tests/e2e/utils/pageobjects/index.ts b/apps/meteor/tests/e2e/utils/pageobjects/index.ts new file mode 100644 index 000000000000..3a0e4236cff2 --- /dev/null +++ b/apps/meteor/tests/e2e/utils/pageobjects/index.ts @@ -0,0 +1,9 @@ +export { default as Administration } from './Administration'; +export { default as ChannelCreation } from './ChannelCreation'; +export { default as FlexTab } from './FlexTab'; +export { default as Global } from './Global'; +export { default as LoginPage } from './LoginPage'; +export { default as MainContent } from './MainContent'; +export { default as PreferencesMainContent } from './PreferencesMainContent'; +export { default as SetupWizard } from './SetupWizard'; +export { default as SideNav } from './SideNav'; From 73acc94ab8eacf3a9d553ad2cb07b7b733402b23 Mon Sep 17 00:00:00 2001 From: Ramon Souza Date: Wed, 18 May 2022 22:51:44 -0300 Subject: [PATCH 9/9] test: create 13-permissions suite --- apps/meteor/tests/e2e/13-permissions.spec.ts | 97 ++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 apps/meteor/tests/e2e/13-permissions.spec.ts diff --git a/apps/meteor/tests/e2e/13-permissions.spec.ts b/apps/meteor/tests/e2e/13-permissions.spec.ts new file mode 100644 index 000000000000..0b4edda751b7 --- /dev/null +++ b/apps/meteor/tests/e2e/13-permissions.spec.ts @@ -0,0 +1,97 @@ +import { Page, test, expect } from '@playwright/test'; +import { v4 as uuid } from 'uuid'; + +import { LoginPage, FlexTab, Administration, MainContent, SideNav } from './utils/pageobjects'; +import { adminLogin, createRegisterUser } from './utils/mocks/userAndPasswordMock'; +import { BACKSPACE } from './utils/mocks/keyboardKeyMock'; + +test.describe('[Permissions]', () => { + let page: Page; + + let loginPage: LoginPage; + let admin: Administration; + let flexTab: FlexTab; + let sideNav: SideNav; + let mainContent: MainContent; + + const userToBeCreated = createRegisterUser(); + + test.beforeAll(async ({ browser }) => { + const context = await browser.newContext(); + page = await context.newPage(); + + loginPage = new LoginPage(page); + admin = new Administration(page); + flexTab = new FlexTab(page); + sideNav = new SideNav(page); + mainContent = new MainContent(page); + + await page.goto('/'); + await loginPage.login(adminLogin); + await sideNav.general().click(); + await page.goto('/admin/users'); + }); + + test('expect create a user via admin view', async () => { + await flexTab.usersAddUserTab().click(); + await flexTab.usersAddUserName().type(userToBeCreated.name); + await flexTab.usersAddUserUsername().type(userToBeCreated.username ?? ''); + await flexTab.usersAddUserEmail().type(userToBeCreated.email); + await flexTab.usersAddUserVerifiedCheckbox().click(); + await flexTab.usersAddUserPassword().type(userToBeCreated.password); + await flexTab.doAddRole('user'); + await flexTab.usersButtonSave().click(); + }); + + test('expect user be show on list', async () => { + await admin.usersFilter().type(userToBeCreated.email, { delay: 200 }); + expect(await admin.userInTable(userToBeCreated.email).isVisible()).toBeTruthy(); + }); + + test.describe('disable "userToBeCreated" permissions', () => { + test('expect open permissions table', async () => { + await admin.permissionsLink().click(); + }); + + test('expect remove "mention all" permission from user', async () => { + await admin.inputPermissionsSearch().type('all'); + + if (await admin.getCheckboxPermission('Mention All').locator('input').isChecked()) { + await admin.getCheckboxPermission('Mention All').click(); + } + }); + + test('expect remove "delete message" permission from user', async () => { + await admin.inputPermissionsSearch().click({ clickCount: 3 }); + await page.keyboard.press(BACKSPACE); + await admin.inputPermissionsSearch().type('delete'); + + if (await admin.getCheckboxPermission('Delete Own Message').locator('input').isChecked()) { + await admin.getCheckboxPermission('Delete Own Message').click(); + } + }); + }); + + test.describe('assert "userToBeCreated" permissions', () => { + test.beforeAll(async () => { + await sideNav.doLogout(); + await loginPage.goto('/'); + await loginPage.login(userToBeCreated); + await sideNav.general().click(); + }); + + test('expect not be abble to "mention all"', async () => { + await mainContent.sendMessage('@all any_message'); + + expect(mainContent.lastMessage()).toContainText('not allowed'); + }); + + test('expect not be abble to "delete own message"', async () => { + await mainContent.doReload(); + await mainContent.sendMessage(`any_message_${uuid()}`); + await mainContent.openMessageActionMenu(); + + expect(await page.isVisible('[data-qa-id="delete-message"]')).toBeFalsy(); + }); + }); +});