diff --git a/apps/desktop/src/auth/delete-account.component.spec.ts b/apps/desktop/src/auth/delete-account.component.spec.ts index b5ebfb886c6..4016e2d5836 100644 --- a/apps/desktop/src/auth/delete-account.component.spec.ts +++ b/apps/desktop/src/auth/delete-account.component.spec.ts @@ -8,7 +8,7 @@ import { AccountApiService } from "@bitwarden/common/auth/abstractions/account-a import { VerificationWithSecret } from "@bitwarden/common/auth/types/verification"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { ToastService } from "@bitwarden/components"; +import { DialogRef, ToastService } from "@bitwarden/components"; import { DeleteAccountComponent } from "./delete-account.component"; @@ -20,6 +20,7 @@ describe("DeleteAccountComponent", () => { let accountApiService: MockProxy; let toastService: MockProxy; let configService: MockProxy; + let dialogRef: MockProxy; beforeEach(async () => { jest.clearAllMocks(); @@ -29,6 +30,7 @@ describe("DeleteAccountComponent", () => { accountApiService = mock(); toastService = mock(); configService = mock(); + dialogRef = mock(); i18nService.t.mockImplementation((key: any) => key); @@ -41,6 +43,7 @@ describe("DeleteAccountComponent", () => { { provide: AccountApiService, useValue: accountApiService }, { provide: ToastService, useValue: toastService }, { provide: ConfigService, useValue: configService }, + { provide: DialogRef, useValue: dialogRef }, ], }).compileComponents(); }); @@ -73,6 +76,7 @@ describe("DeleteAccountComponent", () => { message: "accountDeletedDesc", }); expect(component["invalidSecret"]()).toBe(false); + expect(dialogRef.close).toHaveBeenCalled(); }); it("should set invalidSecret to true and show error toast when deletion fails", async () => { @@ -87,6 +91,7 @@ describe("DeleteAccountComponent", () => { message: "userVerificationFailed", }); expect(component["invalidSecret"]()).toBe(true); + expect(dialogRef.close).not.toHaveBeenCalled(); }); it("should reset invalidSecret to false before attempting deletion", async () => { @@ -120,6 +125,7 @@ describe("DeleteAccountComponent", () => { title: "accountDeleted", message: "accountDeletedDesc", }); + expect(dialogRef.close).not.toHaveBeenCalled(); }); it("should not set invalidSecret when deletion fails", async () => { diff --git a/apps/desktop/src/auth/delete-account.component.ts b/apps/desktop/src/auth/delete-account.component.ts index 9d4e176b8ee..f3169157458 100644 --- a/apps/desktop/src/auth/delete-account.component.ts +++ b/apps/desktop/src/auth/delete-account.component.ts @@ -44,6 +44,7 @@ export class DeleteAccountComponent { private accountApiService = inject(AccountApiService); private toastService = inject(ToastService); private configService = inject(ConfigService); + private dialogRef = inject(DialogRef); deleteForm = this.formBuilder.group({ verification: undefined as VerificationWithSecret | undefined, @@ -91,6 +92,7 @@ export class DeleteAccountComponent { title: this.i18nService.t("accountDeleted"), message: this.i18nService.t("accountDeletedDesc"), }); + this.dialogRef.close(); } catch { this.invalidSecret.set(true); this.toastService.showToast({