Skip to content

Commit

Permalink
[PM-11393] Remove the need for TotpCaptureService in Autofill Options…
Browse files Browse the repository at this point in the history
… View component (#11093)
  • Loading branch information
shane-melton authored Sep 17, 2024
1 parent 1a961ee commit 99ba567
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ import { CollectionView } from "@bitwarden/common/vault/models/view/collection.v
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
import {
AsyncActionsModule,
SearchModule,
ButtonModule,
IconButtonModule,
DialogService,
IconButtonModule,
SearchModule,
ToastService,
} from "@bitwarden/components";
import { TotpCaptureService } from "@bitwarden/vault";

import { CipherViewComponent } from "../../../../../../../../libs/vault/src/cipher-view";
import { PopOutComponent } from "../../../../../platform/popup/components/pop-out.component";
import { BrowserTotpCaptureService } from "../../../services/browser-totp-capture.service";

import { PopupFooterComponent } from "./../../../../../platform/popup/layout/popup-footer.component";
import { PopupHeaderComponent } from "./../../../../../platform/popup/layout/popup-header.component";
Expand All @@ -41,7 +39,6 @@ import { VaultPopupAutofillService } from "./../../../services/vault-popup-autof
selector: "app-view-v2",
templateUrl: "view-v2.component.html",
standalone: true,
providers: [{ provide: TotpCaptureService, useClass: BrowserTotpCaptureService }],
imports: [
CommonModule,
SearchModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ describe("BrowserTotpCaptureService", () => {
let testBed: TestBed;
let service: BrowserTotpCaptureService;
let mockCaptureVisibleTab: jest.SpyInstance;
let createNewTabSpy: jest.SpyInstance;

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

beforeEach(() => {
const tabReturn = new Promise<chrome.tabs.Tab>((resolve) =>
resolve({ url: "google.com", active: true } as chrome.tabs.Tab),
);
createNewTabSpy = jest.spyOn(BrowserApi, "createNewTab").mockReturnValue(tabReturn);
mockCaptureVisibleTab = jest.spyOn(BrowserApi, "captureVisibleTab");
mockCaptureVisibleTab.mockResolvedValue("screenshot");

Expand Down Expand Up @@ -71,10 +66,4 @@ describe("BrowserTotpCaptureService", () => {

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

it("should call BrowserApi.createNewTab with a given loginURI", async () => {
await service.openAutofillNewTab("www.google.com");

expect(createNewTabSpy).toHaveBeenCalledWith("www.google.com");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@ export class BrowserTotpCaptureService implements TotpCaptureService {
}
return null;
}

async openAutofillNewTab(loginUri: string) {
await BrowserApi.createNewTab(loginUri);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* TODO: PM-10727 - Rename and Refactor this service
* This service is being used in both CipherForm and CipherView. Update this service to reflect that
*/

/**
* Service to capture TOTP secret from a client application.
*/
Expand All @@ -11,5 +6,4 @@ export abstract class TotpCaptureService {
* Captures a TOTP secret and returns it as a string. Returns null if no TOTP secret was found.
*/
abstract captureTotpSecret(): Promise<string | null>;
abstract openAutofillNewTab(loginUri: string): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { CommonModule } from "@angular/common";
import { Component, Input } from "@angular/core";

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view";
import {
CardComponent,
FormFieldModule,
IconButtonModule,
SectionComponent,
SectionHeaderComponent,
TypographyModule,
IconButtonModule,
} from "@bitwarden/components";

import { TotpCaptureService } from "../../cipher-form";

@Component({
selector: "app-autofill-options-view",
templateUrl: "autofill-options-view.component.html",
Expand All @@ -32,9 +31,9 @@ import { TotpCaptureService } from "../../cipher-form";
export class AutofillOptionsViewComponent {
@Input() loginUris: LoginUriView[];

constructor(private totpCaptureService: TotpCaptureService) {}
constructor(private platformUtilsService: PlatformUtilsService) {}

async openWebsite(selectedUri: string) {
await this.totpCaptureService.openAutofillNewTab(selectedUri);
openWebsite(selectedUri: string) {
this.platformUtilsService.launchUri(selectedUri);
}
}

0 comments on commit 99ba567

Please sign in to comment.