Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaasen-livefront committed Jan 3, 2025
1 parent 2094fd4 commit 2b315cc
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TestBed } from "@angular/core/testing";
import qrcodeParser from "qrcode-parser";

import { BrowserApi } from "../../../platform/browser/browser-api";
import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils";

import { BrowserTotpCaptureService } from "./browser-totp-capture.service";

Expand All @@ -13,12 +14,14 @@ describe("BrowserTotpCaptureService", () => {
let testBed: TestBed;
let service: BrowserTotpCaptureService;
let mockCaptureVisibleTab: jest.SpyInstance;
let mockBrowserPopupUtilsInPopout: jest.SpyInstance;

const validTotpUrl = "otpauth://totp/label?secret=123";

beforeEach(() => {
mockCaptureVisibleTab = jest.spyOn(BrowserApi, "captureVisibleTab");
mockCaptureVisibleTab.mockResolvedValue("screenshot");
mockBrowserPopupUtilsInPopout = jest.spyOn(BrowserPopupUtils, "inPopout");

testBed = TestBed.configureTestingModule({
providers: [BrowserTotpCaptureService],
Expand Down Expand Up @@ -66,4 +69,16 @@ describe("BrowserTotpCaptureService", () => {

expect(result).toBeNull();
});

describe("canCaptureTotp", () => {
it("should return true when not in a popout window", () => {
mockBrowserPopupUtilsInPopout.mockReturnValue(false);
expect(service.canCaptureTotp({} as Window)).toBe(true);
});

it("should return false when in a popout window", () => {
mockBrowserPopupUtilsInPopout.mockReturnValue(true);
expect(service.canCaptureTotp({} as Window)).toBe(false);
});
});
});

0 comments on commit 2b315cc

Please sign in to comment.