Fix broken valut-settings-v2 tests (#18029)

This commit is contained in:
Shane Melton
2025-12-17 10:30:33 -08:00
committed by GitHub
parent cbd80d0186
commit a12c7a31fd

View File

@@ -77,11 +77,17 @@ describe("VaultSettingsV2Component", () => {
}; };
beforeEach(async () => { beforeEach(async () => {
// Reset BehaviorSubjects to initial values
mockUserCanArchive$.next(false);
mockHasArchiveFlagEnabled$.next(true);
mockArchivedCiphers$.next([]);
mockShowNudgeBadge$.next(false);
mockCipherArchiveService = mock<CipherArchiveService>({ mockCipherArchiveService = mock<CipherArchiveService>({
userCanArchive$: jest.fn().mockReturnValue(mockUserCanArchive$), userCanArchive$: jest.fn().mockReturnValue(mockUserCanArchive$),
hasArchiveFlagEnabled$: jest.fn().mockReturnValue(mockHasArchiveFlagEnabled$),
archivedCiphers$: jest.fn().mockReturnValue(mockArchivedCiphers$), archivedCiphers$: jest.fn().mockReturnValue(mockArchivedCiphers$),
}); });
mockCipherArchiveService.hasArchiveFlagEnabled$ = mockHasArchiveFlagEnabled$.asObservable();
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [VaultSettingsV2Component], imports: [VaultSettingsV2Component],
@@ -133,7 +139,7 @@ describe("VaultSettingsV2Component", () => {
const archiveLink = queryByTestId("archive-link"); const archiveLink = queryByTestId("archive-link");
expect(archiveLink.nativeElement.getAttribute("routerLink")).toBe("/archive"); expect(archiveLink?.nativeElement.getAttribute("routerLink")).toBe("/archive");
}); });
it("routes to archive when user has archived items but cannot archive", async () => { it("routes to archive when user has archived items but cannot archive", async () => {
@@ -141,7 +147,7 @@ describe("VaultSettingsV2Component", () => {
const premiumArchiveLink = queryByTestId("premium-archive-link"); const premiumArchiveLink = queryByTestId("premium-archive-link");
premiumArchiveLink.nativeElement.click(); premiumArchiveLink?.nativeElement.click();
await fixture.whenStable(); await fixture.whenStable();
expect(router.navigate).toHaveBeenCalledWith(["/archive"]); expect(router.navigate).toHaveBeenCalledWith(["/archive"]);
@@ -150,14 +156,14 @@ describe("VaultSettingsV2Component", () => {
it("prompts for premium when user cannot archive and has no archived items", async () => { it("prompts for premium when user cannot archive and has no archived items", async () => {
setArchiveState(false, []); setArchiveState(false, []);
const badge = component["premiumBadgeComponent"](); const badge = component["premiumBadgeComponent"]();
jest.spyOn(badge, "promptForPremium"); jest.spyOn(badge!, "promptForPremium");
const premiumArchiveLink = queryByTestId("premium-archive-link"); const premiumArchiveLink = queryByTestId("premium-archive-link");
premiumArchiveLink.nativeElement.click(); premiumArchiveLink?.nativeElement.click();
await fixture.whenStable(); await fixture.whenStable();
expect(badge.promptForPremium).toHaveBeenCalled(); expect(badge!.promptForPremium).toHaveBeenCalled();
}); });
}); });