Skip to content

Commit

Permalink
[PM-14426] Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shane-melton committed Feb 13, 2025
1 parent eb6b10e commit eec3775
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { ToastService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";
import {
ChangeLoginPasswordService,
DefaultChangeLoginPasswordService,
Expand All @@ -28,6 +28,7 @@ import {

import { PopupHeaderComponent } from "../../../../platform/popup/layout/popup-header.component";
import { PopupPageComponent } from "../../../../platform/popup/layout/popup-page.component";
import { AtRiskCarouselDialogResult } from "../at-risk-carousel-dialog/at-risk-carousel-dialog.component";

import { AtRiskPasswordPageService } from "./at-risk-password-page.service";
import { AtRiskPasswordsComponent } from "./at-risk-passwords.component";
Expand Down Expand Up @@ -73,6 +74,7 @@ describe("AtRiskPasswordsComponent", () => {
const mockToastService = mock<ToastService>();
const mockAtRiskPasswordPageService = mock<AtRiskPasswordPageService>();
const mockChangeLoginPasswordService = mock<ChangeLoginPasswordService>();
const mockDialogService = mock<DialogService>();

beforeEach(async () => {
mockTasks$ = new BehaviorSubject<SecurityTask[]>([
Expand Down Expand Up @@ -109,6 +111,7 @@ describe("AtRiskPasswordsComponent", () => {
calloutDismissed$ = new BehaviorSubject<boolean>(false);
setInlineMenuVisibility.mockClear();
mockToastService.showToast.mockClear();
mockDialogService.open.mockClear();
mockAtRiskPasswordPageService.isCalloutDismissed.mockReturnValue(calloutDismissed$);

await TestBed.configureTestingModule({
Expand Down Expand Up @@ -162,13 +165,15 @@ describe("AtRiskPasswordsComponent", () => {
providers: [
AtRiskPasswordPageService,
{ provide: ChangeLoginPasswordService, useClass: DefaultChangeLoginPasswordService },
DialogService,
],
},
add: {
imports: [MockPopupHeaderComponent, MockPopupPageComponent],
providers: [
{ provide: AtRiskPasswordPageService, useValue: mockAtRiskPasswordPageService },
{ provide: ChangeLoginPasswordService, useValue: mockChangeLoginPasswordService },
{ provide: DialogService, useValue: mockDialogService },
],
},
})
Expand Down Expand Up @@ -269,4 +274,31 @@ describe("AtRiskPasswordsComponent", () => {
});
});
});

describe("getting started carousel", () => {
it("should open the carousel automatically if the user has not dismissed it", async () => {
mockAtRiskPasswordPageService.isGettingStartedDismissed.mockReturnValue(of(false));
mockDialogService.open.mockReturnValue({ closed: of(undefined) } as any);
await component.ngOnInit();
expect(mockDialogService.open).toHaveBeenCalled();
});

it("should not open the carousel automatically if the user has already dismissed it", async () => {
mockDialogService.open.mockClear(); // Need to clear the mock since the component is already initialized once
mockAtRiskPasswordPageService.isGettingStartedDismissed.mockReturnValue(of(true));
mockDialogService.open.mockReturnValue({ closed: of(undefined) } as any);
await component.ngOnInit();
expect(mockDialogService.open).not.toHaveBeenCalled();
});

it("should mark the carousel as dismissed when the user dismisses it", async () => {
mockAtRiskPasswordPageService.isGettingStartedDismissed.mockReturnValue(of(false));
mockDialogService.open.mockReturnValue({
closed: of(AtRiskCarouselDialogResult.Dismissed),
} as any);
await component.ngOnInit();
expect(mockDialogService.open).toHaveBeenCalled();
expect(mockAtRiskPasswordPageService.dismissGettingStarted).toHaveBeenCalled();
});
});
});

0 comments on commit eec3775

Please sign in to comment.