1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

[PM-11393] Remove the need for TotpCaptureService in Autofill Options View component (#11093)

This commit is contained in:
Shane Melton 2024-09-17 13:15:11 -07:00 committed by GitHub
parent 1a961ee294
commit 99ba56785d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 7 additions and 32 deletions

View File

@ -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";
@ -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,

View File

@ -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");
@ -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");
});
});

View File

@ -20,8 +20,4 @@ export class BrowserTotpCaptureService implements TotpCaptureService {
}
return null;
}
async openAutofillNewTab(loginUri: string) {
await BrowserApi.createNewTab(loginUri);
}
}

View File

@ -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.
*/
@ -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;
}

View File

@ -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",
@ -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);
}
}