From 21fba33462fc61676300bd389c5670878011c76e Mon Sep 17 00:00:00 2001 From: giancarlo Date: Fri, 12 Apr 2024 21:30:13 +0800 Subject: [PATCH] Add account deletion process and improve tests The commit introduces a message to indicate the account deletion process. It also enhances the tests by reducing code redundancy in the e2e tests, creating a more random name for team accounts, and improving the navigation process after account deletions. The commit also includes code cleanup tasks, such as the removal of unused imports. --- apps/e2e/tests/account/account.spec.ts | 6 +----- apps/e2e/tests/team-accounts/team-accounts.po.ts | 6 +----- apps/e2e/tests/team-accounts/team-accounts.spec.ts | 10 ++-------- apps/web/public/locales/en/account.json | 1 + .../personal-account-settings/account-danger-zone.tsx | 6 +++++- .../src/server/personal-accounts-server-actions.ts | 5 +++-- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/apps/e2e/tests/account/account.spec.ts b/apps/e2e/tests/account/account.spec.ts index c9654b7f7..461f6bd38 100644 --- a/apps/e2e/tests/account/account.spec.ts +++ b/apps/e2e/tests/account/account.spec.ts @@ -55,10 +55,6 @@ test.describe('Account Deletion', () => { await account.setup(); await account.deleteAccount(); - await page.waitForURL('http://localhost:3000', { - timeout: 5000, - }); - - expect(page.url()).toEqual('http://localhost:3000/'); + await account.auth.goToSignIn(); }); }); \ No newline at end of file diff --git a/apps/e2e/tests/team-accounts/team-accounts.po.ts b/apps/e2e/tests/team-accounts/team-accounts.po.ts index b202650aa..e494eda22 100644 --- a/apps/e2e/tests/team-accounts/team-accounts.po.ts +++ b/apps/e2e/tests/team-accounts/team-accounts.po.ts @@ -37,10 +37,6 @@ export class TeamAccountsPageObject { await this.page.click('[data-test="create-team-account-trigger"]'); await this.page.fill('[data-test="create-team-form"] input', teamName); await this.page.click('[data-test="create-team-form"] button:last-child'); - - await this.page.waitForURL(`http://localhost:3000/home/${slug}`, { - timeout: 5000, - }); } async updateName(name: string) { @@ -58,7 +54,7 @@ export class TeamAccountsPageObject { } createTeamName() { - const random = (Math.random() * 10).toFixed(0); + const random = (Math.random() * 100000000).toFixed(0); const teamName = `Team-Name-${random}`; const slug = `team-name-${random}`; diff --git a/apps/e2e/tests/team-accounts/team-accounts.spec.ts b/apps/e2e/tests/team-accounts/team-accounts.spec.ts index 1d75c13d3..d018e9f07 100644 --- a/apps/e2e/tests/team-accounts/team-accounts.spec.ts +++ b/apps/e2e/tests/team-accounts/team-accounts.spec.ts @@ -8,11 +8,11 @@ test.describe('Team Accounts', () => { test.beforeAll(async ({ browser }) => { page = await browser.newPage(); teamAccounts = new TeamAccountsPageObject(page); - - await teamAccounts.setup(); }); test('user can update their team name (and slug)', async () => { + await teamAccounts.setup(); + const {teamName, slug} = teamAccounts.createTeamName(); await teamAccounts.goToSettings(); @@ -35,12 +35,6 @@ test.describe('Account Deletion', () => { await teamAccounts.deleteAccount(params.teamName); - await page.waitForURL('http://localhost:3000/home', { - timeout: 5000, - }); - - expect(page.url()).toEqual('http://localhost:3000/home'); - await expect(await teamAccounts.getTeamFromSelector(params.slug)).not.toBeVisible(); }); }); \ No newline at end of file diff --git a/apps/web/public/locales/en/account.json b/apps/web/public/locales/en/account.json index cd64b82a6..07631d74f 100644 --- a/apps/web/public/locales/en/account.json +++ b/apps/web/public/locales/en/account.json @@ -131,6 +131,7 @@ "dangerZone": "Danger Zone", "dangerZoneDescription": "Some actions cannot be undone. Please be careful.", "deleteAccount": "Delete your Account", + "deletingAccount": "Deleting account. Please wait...", "deleteAccountDescription": "This will delete your account and the organizations you own. Furthermore, we will immediately cancel any active subscriptions. This action cannot be undone. You will be asked to confirm this action in the next step.", "deleteProfileConfirmationInputLabel": "Type DELETE to confirm", "deleteAccountErrorHeading": "Sorry, we couldn't delete your account", diff --git a/packages/features/accounts/src/components/personal-account-settings/account-danger-zone.tsx b/packages/features/accounts/src/components/personal-account-settings/account-danger-zone.tsx index b97a5d935..f8a0192d8 100644 --- a/packages/features/accounts/src/components/personal-account-settings/account-danger-zone.tsx +++ b/packages/features/accounts/src/components/personal-account-settings/account-danger-zone.tsx @@ -142,7 +142,11 @@ function DeleteAccountSubmitButton() { name={'action'} variant={'destructive'} > - + {pending ? ( + + ) : ( + + )} ); } diff --git a/packages/features/accounts/src/server/personal-accounts-server-actions.ts b/packages/features/accounts/src/server/personal-accounts-server-actions.ts index 2d3f40707..5a6523429 100644 --- a/packages/features/accounts/src/server/personal-accounts-server-actions.ts +++ b/packages/features/accounts/src/server/personal-accounts-server-actions.ts @@ -1,7 +1,7 @@ 'use server'; import { revalidatePath } from 'next/cache'; -import { RedirectType, redirect } from 'next/navigation'; +import { redirect } from 'next/navigation'; import { z } from 'zod'; @@ -66,10 +66,11 @@ export async function deletePersonalAccountAction(formData: FormData) { // sign out the user after deleting their account await client.auth.signOut(); + // clear the cache for all pages revalidatePath('/', 'layout'); // redirect to the home page - redirect('/', RedirectType.replace); + redirect('/'); } function getEmailSettingsFromEnvironment() {