From 389f5763d3da083e6ed8d7540513fd690090acfc Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 14 Nov 2022 15:40:02 +0530 Subject: [PATCH] test(playwright): improve invite only signup settings test Signed-off-by: Pranav C --- packages/nc-gui/pages/signup/[[token]].vue | 2 +- tests/playwright/pages/Account/Settings.ts | 8 ++- tests/playwright/pages/Account/Token.ts | 2 +- tests/playwright/pages/Account/Users.ts | 2 +- tests/playwright/pages/Account/index.ts | 10 ++++ tests/playwright/pages/SigninPage/index.ts | 52 +++++++++++++++++++ tests/playwright/pages/SignupPage/index.ts | 23 ++++++-- tests/playwright/setup/index.ts | 2 +- .../tests/accountUserManagement.spec.ts | 6 +-- .../tests/accountUserSettings.spec.ts | 32 +++++++++++- 10 files changed, 124 insertions(+), 15 deletions(-) create mode 100644 tests/playwright/pages/SigninPage/index.ts diff --git a/packages/nc-gui/pages/signup/[[token]].vue b/packages/nc-gui/pages/signup/[[token]].vue index a9204c852d..8db60c72e9 100644 --- a/packages/nc-gui/pages/signup/[[token]].vue +++ b/packages/nc-gui/pages/signup/[[token]].vue @@ -99,7 +99,7 @@ function resetError() { -
+
{{ error }}
diff --git a/tests/playwright/pages/Account/Settings.ts b/tests/playwright/pages/Account/Settings.ts index 82683bdd39..c8a79999ea 100644 --- a/tests/playwright/pages/Account/Settings.ts +++ b/tests/playwright/pages/Account/Settings.ts @@ -11,7 +11,7 @@ export class AccountSettingsPage extends BasePage { } async goto() { - await this.rootPage.goto('/?dummy=settings#/account/users/settings'); + await this.rootPage.goto('/#/account/users/settings', { waitUntil: 'networkidle' }); } get() { @@ -22,8 +22,12 @@ export class AccountSettingsPage extends BasePage { return this.get().locator(`.nc-invite-only-signup-checkbox`); } + async getInviteOnlyCheckboxValue() { + return this.get().locator(`.nc-invite-only-signup-checkbox`).isChecked(); + } + async checkInviteOnlySignupCheckbox(value: boolean) { - return expect(await this.get().locator(`.nc-invite-only-signup-checkbox`).isChecked()).toBe(value); + return expect(await this.getInviteOnlyCheckboxValue()).toBe(value); } async toggleInviteOnlyCheckbox() { diff --git a/tests/playwright/pages/Account/Token.ts b/tests/playwright/pages/Account/Token.ts index 5b9ae03081..3abed37ee4 100644 --- a/tests/playwright/pages/Account/Token.ts +++ b/tests/playwright/pages/Account/Token.ts @@ -15,7 +15,7 @@ export class AccountTokenPage extends BasePage { } async goto() { - await this.rootPage.goto('/?dummy=users#/account/tokens'); + await this.rootPage.goto('/#/account/tokens', { waitUntil: 'networkidle' }); } get() { diff --git a/tests/playwright/pages/Account/Users.ts b/tests/playwright/pages/Account/Users.ts index 4e119c4ac8..cfccd459a1 100644 --- a/tests/playwright/pages/Account/Users.ts +++ b/tests/playwright/pages/Account/Users.ts @@ -15,7 +15,7 @@ export class AccountUsersPage extends BasePage { } async goto() { - await this.rootPage.goto('/?dummy=users#/account/users/list'); + await this.rootPage.goto('/#/account/users/list', { waitUntil: 'networkidle' }); } get() { diff --git a/tests/playwright/pages/Account/index.ts b/tests/playwright/pages/Account/index.ts index b76747c5dc..c2f4da62bb 100644 --- a/tests/playwright/pages/Account/index.ts +++ b/tests/playwright/pages/Account/index.ts @@ -9,4 +9,14 @@ export class AccountPage extends BasePage { get() { return this.rootPage.locator('body'); } + + async openAppMenu() { + await this.rootPage.locator('.nc-menu-accounts').click(); + } + + async signOut() { + await this.openAppMenu(); + await this.rootPage.locator('div.nc-project-menu-item:has-text("Sign Out"):visible').click(); + await this.rootPage.locator('[data-testid="nc-form-signin"]:visible').waitFor(); + } } diff --git a/tests/playwright/pages/SigninPage/index.ts b/tests/playwright/pages/SigninPage/index.ts new file mode 100644 index 0000000000..6a1cc05cc8 --- /dev/null +++ b/tests/playwright/pages/SigninPage/index.ts @@ -0,0 +1,52 @@ +import { Page } from '@playwright/test'; +import BasePage from '../Base'; +import { ProjectsPage } from '../ProjectsPage'; +import { expect } from '@playwright/test'; + +export class SigninPage extends BasePage { + readonly projectsPage: ProjectsPage; + + constructor(rootPage: Page) { + super(rootPage); + this.projectsPage = new ProjectsPage(rootPage); + } + + prefixEmail(email: string) { + const parallelId = process.env.TEST_PARALLEL_INDEX ?? '0'; + return `nc_test_${parallelId}_${email}`; + } + + goto() { + return this.rootPage.goto('/#/signin/', { waitUntil: 'networkidle' }); + } + + get() { + return this.rootPage.locator('html'); + } + + async signIn({ + email, + password, + withoutPrefix, + expectedError, + }: { + email: string; + password: string; + withoutPrefix?: boolean; + expectedError?: string; + }) { + if (!withoutPrefix) email = this.prefixEmail(email); + + const signUp = this.get(); + await signUp.locator('button:has-text("SIGN IN")').waitFor(); + + await signUp.locator(`input[placeholder="Enter your work email"]`).fill(email); + await signUp.locator(`input[placeholder="Enter your password"]`).fill(password); + await signUp.locator(`button:has-text("SIGN IN")`).click(); + if (expectedError) { + await expect(signUp.getByTestId('nc-signin-error')).toHaveText(expectedError); + } else { + await this.projectsPage.waitToBeRendered(); + } + } +} diff --git a/tests/playwright/pages/SignupPage/index.ts b/tests/playwright/pages/SignupPage/index.ts index 95416f7725..5c9b415507 100644 --- a/tests/playwright/pages/SignupPage/index.ts +++ b/tests/playwright/pages/SignupPage/index.ts @@ -1,6 +1,7 @@ import { Page } from '@playwright/test'; import BasePage from '../Base'; import { ProjectsPage } from '../ProjectsPage'; +import { expect } from '@playwright/test'; export class SignupPage extends BasePage { readonly projectsPage: ProjectsPage; @@ -16,22 +17,36 @@ export class SignupPage extends BasePage { } goto() { - return this.rootPage.goto('/#/signup/'); + return this.rootPage.goto('/#/signup/', { waitUntil: 'networkidle' }); } get() { return this.rootPage.locator('html'); } - async signUp({ email, password, withoutPrefix }: { email: string; password: string; withoutPrefix?: boolean }) { + async signUp({ + email, + password, + withoutPrefix, + expectedError, + }: { + email: string; + password: string; + withoutPrefix?: boolean; + expectedError?: string; + }) { if (!withoutPrefix) email = this.prefixEmail(email); - const signUp = this.rootPage; + const signUp = this.get(); await signUp.locator('button:has-text("SIGN UP")').waitFor(); await signUp.locator(`input[placeholder="Enter your work email"]`).fill(email); await signUp.locator(`input[placeholder="Enter your password"]`).fill(password); await signUp.locator(`button:has-text("SIGN UP")`).click(); - await this.projectsPage.waitToBeRendered(); + if (expectedError) { + await expect(signUp.getByTestId('nc-signup-error')).toHaveText(expectedError); + } else { + await this.projectsPage.waitToBeRendered(); + } } } diff --git a/tests/playwright/setup/index.ts b/tests/playwright/setup/index.ts index 764d36795f..a738d5c095 100644 --- a/tests/playwright/setup/index.ts +++ b/tests/playwright/setup/index.ts @@ -57,7 +57,7 @@ const setup = async ({ page, isEmptyProject }: { page: Page; isEmptyProject?: bo const project = response.data.project; - await page.goto(`/#/nc/${project.id}/auth`); + await page.goto(`/#/nc/${project.id}/auth`, { waitUntil: 'networkidle' }); return { project, token, dbType } as NcContext; }; diff --git a/tests/playwright/tests/accountUserManagement.spec.ts b/tests/playwright/tests/accountUserManagement.spec.ts index 44a04fd631..37c7df00cd 100644 --- a/tests/playwright/tests/accountUserManagement.spec.ts +++ b/tests/playwright/tests/accountUserManagement.spec.ts @@ -4,8 +4,8 @@ import { AccountUsersPage } from '../pages/Account/Users'; import setup from '../setup'; const roleDb = [ - { email: 'creator@nocodb.com', role: 'Organization level creator', url: '' }, - { email: 'viewer@nocodb.com', role: 'Organization level viewer', url: '' }, + { email: 'creator@nocodb.com', role: 'Organization Level Creator', url: '' }, + { email: 'viewer@nocodb.com', role: 'Organization Level Viewer', url: '' }, ]; test.describe('User roles', () => { @@ -38,7 +38,7 @@ test.describe('User roles', () => { for (let i = 0; i < roleDb.length; i++) { await accountUsersPage.updateRole({ email: roleDb[i].email, - role: 'Organization level viewer', + role: 'Organization Level Viewer', }); } diff --git a/tests/playwright/tests/accountUserSettings.spec.ts b/tests/playwright/tests/accountUserSettings.spec.ts index 67d67861ec..1974301343 100644 --- a/tests/playwright/tests/accountUserSettings.spec.ts +++ b/tests/playwright/tests/accountUserSettings.spec.ts @@ -1,6 +1,7 @@ import { test } from '@playwright/test'; import { AccountPage } from '../pages/Account'; import { AccountSettingsPage } from '../pages/Account/Settings'; +import { SignupPage } from '../pages/SignupPage'; import setup from '../setup'; test.describe('App settings', () => { @@ -19,10 +20,37 @@ test.describe('App settings', () => { test.slow(); await accountSettingsPage.goto(); - await accountSettingsPage.checkInviteOnlySignupCheckbox(false); - await accountSettingsPage.toggleInviteOnlyCheckbox(); + + // enable invite only signup + if (!(await accountSettingsPage.getInviteOnlyCheckboxValue())) { + await accountSettingsPage.toggleInviteOnlyCheckbox(); + await accountSettingsPage.checkInviteOnlySignupCheckbox(true); + } + + await accountPage.signOut(); + + const signupPage = new SignupPage(accountPage.rootPage); + await signupPage.goto(); + + await signupPage.signUp({ + email: 'test-user-1@nocodb.com', + password: 'Password123.', + expectedError: 'Not allowed to signup, contact super admin.', + }); + + await signupPage.rootPage.reload({ waitUntil: 'networkidle' }); + + await accountSettingsPage.goto(); + await accountSettingsPage.checkInviteOnlySignupCheckbox(true); await accountSettingsPage.toggleInviteOnlyCheckbox(); await accountSettingsPage.checkInviteOnlySignupCheckbox(false); + + await signupPage.goto(); + + await signupPage.signUp({ + email: 'test-user-1@nocodb.com', + password: 'Password123.' + }); }); });