diff --git a/scripts/playwright/pages/Dashboard/index.ts b/scripts/playwright/pages/Dashboard/index.ts index fc3a79cc80..81f462acbd 100644 --- a/scripts/playwright/pages/Dashboard/index.ts +++ b/scripts/playwright/pages/Dashboard/index.ts @@ -117,6 +117,45 @@ export class DashboardPage extends BasePage { await this.rootPage.locator(".nc-menu-translate").click(); } + async openPasswordChangeModal() { + // open change password portal + await this.rootPage.locator(".nc-menu-accounts").click(); + await this.rootPage + .locator( + `.nc-dropdown-user-accounts-menu >> [data-cy="nc-menu-accounts__user-settings"]` + ) + .click(); + } + + async changePassword({ + oldPass, + newPass, + repeatPass, + }: { + oldPass: string; + newPass: string; + repeatPass: string; + }) { + // change password + const currentPassword = await this.rootPage.locator( + 'input[data-cy="nc-user-settings-form__current-password"]' + ); + const newPassword = await this.rootPage.locator( + 'input[data-cy="nc-user-settings-form__new-password"]' + ); + const confirmPassword = await this.rootPage.locator( + 'input[data-cy="nc-user-settings-form__new-password-repeat"]' + ); + + await currentPassword.fill(oldPass); + await newPassword.fill(newPass); + await confirmPassword.fill(repeatPass); + + await this.rootPage + .locator('button[data-cy="nc-user-settings-form__submit"]') + .click(); + } + async selectLanguage({ index }: { index: number }) { let modal = await this.rootPage.locator(".nc-dropdown-menu-translate"); await modal.locator(`.ant-dropdown-menu-item`).nth(index).click(); diff --git a/scripts/playwright/tests/authChangePassword.spec.ts b/scripts/playwright/tests/authChangePassword.spec.ts new file mode 100644 index 0000000000..72d8470ea3 --- /dev/null +++ b/scripts/playwright/tests/authChangePassword.spec.ts @@ -0,0 +1,62 @@ +import { test } from "@playwright/test"; +import { DashboardPage } from "../pages/Dashboard"; +import setup from "../setup"; +import { ToolbarPage } from "../pages/Dashboard/common/Toolbar"; +import { LoginPage } from "../pages/LoginPage"; + +test.describe("Auth", () => { + let dashboard: DashboardPage; + let toolbar: ToolbarPage; + let context: any; + + test.beforeEach(async ({ page }) => { + context = await setup({ page }); + dashboard = new DashboardPage(page, context.project); + toolbar = dashboard.grid.toolbar; + }); + + test("Change password", async ({ page }) => { + await dashboard.clickHome(); + await dashboard.openPasswordChangeModal(); + + // Existing active pass incorrect + await dashboard.changePassword({ + oldPass: "123456789", + newPass: "123456789", + repeatPass: "123456789", + }); + await dashboard.rootPage + .locator( + '[data-cy="nc-user-settings-form__error"]:has-text("Current password is wrong")' + ) + .waitFor(); + + // New pass and repeat pass mismatch + await dashboard.changePassword({ + oldPass: "Password123.", + newPass: "123456789", + repeatPass: "987654321", + }); + await dashboard.rootPage + .locator( + '.ant-form-item-explain-error:has-text("Passwords do not match")' + ) + .waitFor(); + + // All good + await dashboard.changePassword({ + oldPass: "Password123.", + newPass: "NewPasswordConfigured", + repeatPass: "NewPasswordConfigured", + }); + + const loginPage = new LoginPage(page); + await loginPage.fillEmail("user@nocodb.com"); + await loginPage.fillPassword("NewPasswordConfigured"); + await loginPage.submit(); + + await page + .locator('.nc-project-page-title:has-text("My Projects")') + .waitFor(); + }); +});