diff --git a/packages/nocodb/src/run/testDocker.ts b/packages/nocodb/src/run/testDocker.ts index aaaebf517f..d8984b002a 100644 --- a/packages/nocodb/src/run/testDocker.ts +++ b/packages/nocodb/src/run/testDocker.ts @@ -36,7 +36,7 @@ process.env[`DEBUG`] = 'xc*'; console.log(admin_response.data); } - for (let i = 0; i < 8; i++) { + for (let i = 0; i < 4; i++) { if (!(await User.getByEmail(`user-${i}@nocodb.com`))) { const response = await axios.post( `http://localhost:${ diff --git a/tests/playwright/pages/Account/Users.ts b/tests/playwright/pages/Account/Users.ts index f18224f8a8..a95ab580f9 100644 --- a/tests/playwright/pages/Account/Users.ts +++ b/tests/playwright/pages/Account/Users.ts @@ -25,9 +25,7 @@ export class AccountUsersPage extends BasePage { return this.accountPage.get().locator(`[data-testid="nc-super-user-list"]`); } - async invite({ email: _email, role }: { email: string; role: string }) { - const email = this.prefixEmail(_email); - + async invite({ email, role }: { email: string; role: string }) { await this.inviteUserBtn.click(); await this.inviteUserModal.locator(`input[placeholder="E-mail"]`).fill(email); await this.inviteUserModal.locator(`.nc-user-roles`).click(); @@ -50,21 +48,18 @@ export class AccountUsersPage extends BasePage { await this.inviteUserModal.locator(`button.ant-btn-icon-only:visible`).first().click(); } - getUserRow({ email: _email }: { email: string }) { - const email = this.prefixEmail(_email); + async getUserRow({ email }: { email: string }) { + // ensure page is loaded + await this.get().waitFor(); return this.get().locator(`tr:has-text("${email}")`); } async updateRole({ email, role }: { email: string; role: string }) { - const userRow = this.getUserRow({ email }); - + const userRow = await this.getUserRow({ email }); await userRow.locator(`.nc-user-roles`).click(); - - // todo: replace delay with waitForSelector - await new Promise(resolve => setTimeout(resolve, 400)); - - await this.rootPage.locator(`.nc-users-list-role-option:visible:has-text("${role}")`).click(); - await this.verifyToast({ message: 'Successfully updated the user details' }); + await this.rootPage.locator(`.nc-users-list-role-option:visible:has-text("${role}")`).waitFor(); + await this.rootPage.locator(`.nc-users-list-role-option:visible:has-text("${role}")`).last().click(); + await this.rootPage.locator(`.nc-users-list-role-option`).last().waitFor({ state: 'hidden' }); } async inviteMore() { @@ -72,7 +67,7 @@ export class AccountUsersPage extends BasePage { } async openRowActionMenu({ email }: { email: string }) { - const userRow = this.getUserRow({ email }); + const userRow = await this.getUserRow({ email }); return userRow.locator(`.nc-user-row-action`).click(); } diff --git a/tests/playwright/tests/db/usersAccounts/accountUserManagement.spec.ts b/tests/playwright/tests/db/usersAccounts/accountUserManagement.spec.ts index 890b91142b..ff64850176 100644 --- a/tests/playwright/tests/db/usersAccounts/accountUserManagement.spec.ts +++ b/tests/playwright/tests/db/usersAccounts/accountUserManagement.spec.ts @@ -1,31 +1,55 @@ -import { test } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import { AccountPage } from '../../../pages/Account'; import { AccountUsersPage } from '../../../pages/Account/Users'; import { SignupPage } from '../../../pages/SignupPage'; import setup, { unsetup } from '../../../setup'; -import { WorkspacePage } from '../../../pages/WorkspacePage'; import { getDefaultPwd } from '../../../tests/utils/general'; +import { Api } from 'nocodb-sdk'; +import { DashboardPage } from '../../../pages/Dashboard'; +import { LoginPage } from '../../../pages/LoginPage'; +let api: Api; const roleDb = [ - { email: 'creator@nocodb.com', role: 'Organization Level Creator', url: '' }, - { email: 'viewer@nocodb.com', role: 'Organization Level Viewer', url: '' }, + { email: 'org_creator@nocodb.com', role: 'Organization Level Creator', url: '' }, + { email: 'org_viewer@nocodb.com', role: 'Organization Level Viewer', url: '' }, ]; -test.describe.skip('User roles', () => { +test.describe('User roles', () => { let accountUsersPage: AccountUsersPage; let accountPage: AccountPage; let signupPage: SignupPage; - let workspacePage: WorkspacePage; + let loginPage: LoginPage; + let dashboard: DashboardPage; // @ts-ignore let context: any; test.beforeEach(async ({ page }) => { - context = await setup({ page, isEmptyProject: true }); + context = await setup({ page, isEmptyProject: true, isSuperUser: true }); + dashboard = new DashboardPage(page, context.project); accountPage = new AccountPage(page); accountUsersPage = new AccountUsersPage(accountPage); - signupPage = new SignupPage(accountPage.rootPage); - workspacePage = new WorkspacePage(accountPage.rootPage); + loginPage = new LoginPage(accountPage.rootPage); + + try { + api = new Api({ + baseURL: `http://localhost:8080/`, + headers: { + 'xc-auth': context.token, + }, + }); + } catch (e) { + console.log(e); + } + + // check if user already exists; if so- remove them + for (let i = 0; i < roleDb.length; i++) { + const user = await api.orgUsers.list(); + if (user.list.length > 0) { + const u = user.list.find((u: any) => u.email === roleDb[i].email); + if (u) await api.orgUsers.delete(u.id); + } + } }); test.afterEach(async () => { @@ -44,12 +68,21 @@ test.describe.skip('User roles', () => { role: roleDb[i].role, }); await accountUsersPage.closeInvite(); - await signupAndVerify(i); - await accountPage.rootPage.reload({ waitUntil: 'networkidle' }); - await accountUsersPage.goto(); } - // update role + await signupAndVerify(0); + await accountUsersPage.goto(); + await signupAndVerify(1); + + await dashboard.signOut(); + await loginPage.signIn({ + email: 'user@nocodb.com', + password: getDefaultPwd(), + withoutPrefix: true, + }); + + await accountUsersPage.goto(); + // change role for (let i = 0; i < roleDb.length; i++) { await accountUsersPage.updateRole({ email: roleDb[i].email, @@ -74,10 +107,16 @@ test.describe.skip('User roles', () => { await signupPage.signUp({ email: roleDb[roleIdx].email, password: getDefaultPwd(), + withoutPrefix: true, }); - await workspacePage.checkWorkspaceCreateButton({ - exists: roleDb[roleIdx].role === 'Organization Level Creator', - }); + // wait for page rendering to complete after sign up + await dashboard.rootPage.waitForTimeout(1000); + + if (roleDb[roleIdx].role === 'Organization Level Creator') { + expect(await dashboard.leftSidebar.btn_newProject.isVisible()).toBeTruthy(); + } else { + expect(await dashboard.leftSidebar.btn_newProject.isVisible()).toBeFalsy(); + } } }); diff --git a/tests/playwright/tests/db/usersAccounts/rolesCreate.spec.ts b/tests/playwright/tests/db/usersAccounts/rolesCreate.spec.ts index 42305c7229..5ead07dd41 100644 --- a/tests/playwright/tests/db/usersAccounts/rolesCreate.spec.ts +++ b/tests/playwright/tests/db/usersAccounts/rolesCreate.spec.ts @@ -1,11 +1,10 @@ import { test } from '@playwright/test'; import { DashboardPage } from '../../../pages/Dashboard'; import setup, { unsetup } from '../../../setup'; -import { SettingsPage } from '../../../pages/Dashboard/Settings'; import { SignupPage } from '../../../pages/SignupPage'; import { ProjectsPage } from '../../../pages/ProjectsPage'; import { getDefaultPwd } from '../../../tests/utils/general'; -import { WorkspacePage } from '../../../pages/WorkspacePage'; +import { isEE } from '../../../setup/db'; const roleDb = [ { email: 'creator@nocodb.com', role: 'creator', url: '' }, @@ -15,27 +14,26 @@ const roleDb = [ ]; test.describe.skip('User roles', () => { + if (isEE()) { + test.skip(); + } let dashboard: DashboardPage; - let settings: SettingsPage; let signupPage: SignupPage; let projectsPage: ProjectsPage; - let workspacePage: WorkspacePage; let context: any; test.beforeEach(async ({ page }) => { context = await setup({ page, isEmptyProject: false }); dashboard = new DashboardPage(page, context.project); - settings = dashboard.settings; signupPage = new SignupPage(page); projectsPage = new ProjectsPage(page); - workspacePage = new WorkspacePage(page); }); test.afterEach(async () => { await unsetup(context); }); - test.skip('Create role', async () => { + test('Create role', async () => { test.slow(); for (let i = 0; i < roleDb.length; i++) {