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: Migrate 13-permissions from cypress to playwright #25558

Merged
merged 10 commits into from
May 19, 2022
32 changes: 16 additions & 16 deletions apps/meteor/tests/e2e/12-settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(edit) not be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.sendMessage(`any_message_${uuid()}`);
await mainContent.openMessageActionMenu();

Expand All @@ -77,7 +77,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(edit) be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.sendMessage(`any_message_${uuid()}`);
await mainContent.openMessageActionMenu();

Expand All @@ -98,7 +98,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(delete) not be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.sendMessage(`any_message_${uuid()}`);
await mainContent.openMessageActionMenu();

Expand All @@ -117,7 +117,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(delete) be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.sendMessage(`any_message_${uuid()}`);
await mainContent.openMessageActionMenu();

Expand All @@ -138,7 +138,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(upload audio) not be visible', async () => {
await mainContent.reload();
await mainContent.doReload();

expect(await mainContent.recordBtn().isVisible()).toBeFalsy();
});
Expand All @@ -155,7 +155,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(upload audio) be visible', async () => {
await mainContent.reload();
await mainContent.doReload();

expect(await mainContent.recordBtn().isVisible()).toBeTruthy();
});
Expand All @@ -174,7 +174,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(upload video) not be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.openMoreActionMenu();

expect(await page.isVisible('.rc-popover__content [data-id="video-message"]')).toBeFalsy();
Expand All @@ -192,7 +192,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(upload video) be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.openMoreActionMenu();

expect(await page.isVisible('.rc-popover__content [data-id="video-message"]')).toBeTruthy();
Expand Down Expand Up @@ -225,7 +225,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect badword be censored', async () => {
await mainContent.reload();
await mainContent.doReload();

await mainContent.sendMessage(unauthorizedWord);
await mainContent.waitForLastMessageEqualsText('*'.repeat(unauthorizedWord.length));
Expand All @@ -243,7 +243,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect badword not be censored', async () => {
await mainContent.reload();
await mainContent.doReload();

await mainContent.sendMessage(unauthorizedWord);
await mainContent.waitForLastMessageEqualsText(unauthorizedWord);
Expand All @@ -263,7 +263,7 @@ test.describe.skip('[Settings]', async () => {
});

test.skip('(UI) expect option(star message) not be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.sendMessage(`any_message_${uuid()}`);
await mainContent.openMessageActionMenu();

Expand All @@ -282,7 +282,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(star message) be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.sendMessage(`any_message_${uuid()}`);
await mainContent.openMessageActionMenu();

Expand All @@ -303,7 +303,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(upload file) not be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.openMoreActionMenu();

expect(await page.isVisible('[data-qa-id="file-upload"]')).toBeFalsy();
Expand All @@ -321,7 +321,7 @@ test.describe.skip('[Settings]', async () => {
});

test('(UI) expect option(upload file) be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.openMoreActionMenu();

expect(await page.isVisible('[data-qa-id="file-upload"]')).toBeTruthy();
Expand Down Expand Up @@ -436,7 +436,7 @@ test.describe.skip('[Settings (admin)]', async () => {
});

test('(UI) expect option(pin message) not be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.sendMessage(`any_message_${uuid()}`);
await mainContent.openMessageActionMenu();

Expand All @@ -455,7 +455,7 @@ test.describe.skip('[Settings (admin)]', async () => {
});

test('(UI) expect option(pin message) be visible', async () => {
await mainContent.reload();
await mainContent.doReload();
await mainContent.sendMessage(`any_message_${uuid()}`);
await mainContent.openMessageActionMenu();

Expand Down
97 changes: 97 additions & 0 deletions apps/meteor/tests/e2e/13-permissions.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
1 change: 1 addition & 0 deletions apps/meteor/tests/e2e/utils/interfaces/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export interface IRegister {
email: string;
password: string;
name: string;
username?: string;
}
7 changes: 7 additions & 0 deletions apps/meteor/tests/e2e/utils/mocks/userAndPasswordMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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',
Expand Down
8 changes: 8 additions & 0 deletions apps/meteor/tests/e2e/utils/pageobjects/Administration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,14 @@ export default class Administration extends BasePage {
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();
}

public userInfoActions(): Locator {
return this.getPage().locator('[data-qa-id="UserInfoActions"]');
}
Expand Down
7 changes: 6 additions & 1 deletion apps/meteor/tests/e2e/utils/pageobjects/FlexTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<void> {
await this.usersAddUserRoleList().click();
await this.getPage().locator(`li[value=${role}]`).click();
}
}

export default FlexTab;
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/utils/pageobjects/MainContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export default class MainContent extends BasePage {
return this.getPage().locator('[data-qa="UserCard"] a');
}

public async reload(): Promise<void> {
public async doReload(): Promise<void> {
await this.getPage().reload({ waitUntil: 'load' });
await this.getPage().waitForSelector('.messages-box');
}
Expand Down
6 changes: 6 additions & 0 deletions apps/meteor/tests/e2e/utils/pageobjects/SideNav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ class SideNav extends BasePage {
await this.searchInput().type(target, { delay: 300 });
await this.getPage().keyboard.press(ENTER);
}

public async doLogout(): Promise<void> {
await this.getPage().goto('/home');
await this.sidebarUserMenu().click();
await this.logout().click();
}
}

export default SideNav;
9 changes: 9 additions & 0 deletions apps/meteor/tests/e2e/utils/pageobjects/index.ts
Original file line number Diff line number Diff line change
@@ -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';