1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-27 21:53:25 +00:00

Add login component services tests.

This commit is contained in:
Alec Rippberger
2024-10-01 21:17:03 -05:00
parent 2d5f4dfb70
commit d47ffdfe8f
3 changed files with 207 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
import { TestBed } from "@angular/core/testing";
import { MockProxy } from "jest-mock-extended";
import { DefaultLoginComponentService } from "@bitwarden/auth/angular";
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { DesktopLoginComponentService } from "./desktop-login-component.service";
(global as any).ipc = {
platform: {
isAppImage: jest.fn(),
isSnapStore: jest.fn(),
isDev: jest.fn(),
localhostCallbackService: {
openSsoPrompt: jest.fn(),
},
},
};
describe("DesktopLoginComponentService", () => {
let service: DesktopLoginComponentService;
let i18nService: MockProxy<I18nService>;
let toastService: MockProxy<ToastService>;
let ssoLoginService: MockProxy<SsoLoginServiceAbstraction>;
let passwordGenerationService: MockProxy<PasswordGenerationServiceAbstraction>;
let cryptoFunctionService: MockProxy<CryptoFunctionService>;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
DesktopLoginComponentService,
{ provide: DefaultLoginComponentService, useClass: DesktopLoginComponentService },
{ provide: I18nService, useValue: i18nService },
{ provide: ToastService, useValue: toastService },
{ provide: SsoLoginServiceAbstraction, useValue: ssoLoginService },
{ provide: PasswordGenerationServiceAbstraction, useValue: passwordGenerationService },
{ provide: CryptoFunctionService, useValue: cryptoFunctionService },
],
});
service = TestBed.inject(DesktopLoginComponentService);
jest.spyOn(service, "launchSsoBrowserWindow").mockImplementation(async () => {});
});
it("creates the service", () => {
expect(service).toBeTruthy();
});
it("calls launchSsoBrowserWindow if isAppImage, isSnapStore, and isDev are false", async () => {
(global as any).ipc.platform.isAppImage.mockReturnValue(false);
(global as any).ipc.platform.isSnapStore.mockReturnValue(false);
(global as any).ipc.platform.isDev.mockReturnValue(false);
await service.launchSsoBrowserWindow("user@example.com", "desktop");
expect(service.launchSsoBrowserWindow).toHaveBeenCalledWith("user@example.com", "desktop");
});
});