1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

[PM-5189] Refactoring implementation

This commit is contained in:
Cesar Gonzalez
2024-04-16 15:45:45 -05:00
parent 43ba6256dc
commit c15439512b
7 changed files with 21 additions and 21 deletions

View File

@@ -96,7 +96,7 @@ type OverlayBackgroundExtensionMessageHandlers = {
closeAutofillOverlayMenu: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
autofillOverlayElementClosed: ({ message }: BackgroundMessageParam) => void;
autofillOverlayAddNewVaultItem: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
getAutofillOverlayVisibility: () => void;
getInlineMenuVisibilitySetting: () => void;
checkAutofillOverlayMenuFocused: () => void;
focusAutofillOverlayList: () => void;
updateAutofillOverlayMenuPosition: ({

View File

@@ -133,7 +133,7 @@ describe("OverlayBackground", () => {
);
jest
.spyOn(overlayBackground as any, "getOverlayVisibility")
.spyOn(overlayBackground as any, "getInlineMenuVisibility")
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
themeStateService.selectedTheme$ = of(ThemeType.Light);
@@ -161,13 +161,13 @@ describe("OverlayBackground", () => {
describe("init", () => {
it("sets up the extension message listeners, get the overlay's visibility settings, and get the user's auth status", async () => {
overlayBackground["setupExtensionMessageListeners"] = jest.fn();
overlayBackground["getOverlayVisibility"] = jest.fn();
overlayBackground["getInlineMenuVisibility"] = jest.fn();
overlayBackground["getAuthStatus"] = jest.fn();
await overlayBackground.init();
expect(overlayBackground["setupExtensionMessageListeners"]).toHaveBeenCalled();
expect(overlayBackground["getOverlayVisibility"]).toHaveBeenCalled();
expect(overlayBackground["getInlineMenuVisibility"]).toHaveBeenCalled();
expect(overlayBackground["getAuthStatus"]).toHaveBeenCalled();
});
});
@@ -638,18 +638,18 @@ describe("OverlayBackground", () => {
});
});
describe("getAutofillOverlayVisibility message handler", () => {
describe("getInlineMenuVisibilitySetting message handler", () => {
beforeEach(() => {
jest
.spyOn(overlayBackground as any, "getOverlayVisibility")
.spyOn(overlayBackground as any, "getInlineMenuVisibility")
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
});
it("will set the overlayVisibility property", async () => {
sendMockExtensionMessage({ command: "getAutofillOverlayVisibility" });
sendMockExtensionMessage({ command: "getInlineMenuVisibilitySetting" });
await flushPromises();
expect(await overlayBackground["getOverlayVisibility"]()).toBe(
expect(await overlayBackground["getInlineMenuVisibility"]()).toBe(
AutofillOverlayVisibility.OnFieldFocus,
);
});
@@ -658,7 +658,7 @@ describe("OverlayBackground", () => {
const sendMessageSpy = jest.fn();
sendMockExtensionMessage(
{ command: "getAutofillOverlayVisibility" },
{ command: "getInlineMenuVisibilitySetting" },
undefined,
sendMessageSpy,
);

View File

@@ -68,7 +68,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
closeAutofillOverlayMenu: ({ message, sender }) => this.closeOverlayMenu(sender, message),
autofillOverlayElementClosed: ({ message }) => this.overlayElementClosed(message),
autofillOverlayAddNewVaultItem: ({ message, sender }) => this.addNewVaultItem(message, sender),
getAutofillOverlayVisibility: () => this.getOverlayVisibility(),
getInlineMenuVisibilitySetting: () => this.getInlineMenuVisibility(),
checkAutofillOverlayMenuFocused: () => this.checkOverlayMenuFocused(),
focusAutofillOverlayList: () => this.focusOverlayList(),
updateAutofillOverlayMenuPosition: ({ message, sender }) =>
@@ -135,7 +135,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
this.setupExtensionMessageListeners();
const env = await firstValueFrom(this.environmentService.environment$);
this.iconsServerUrl = env.getIconsUrl();
await this.getOverlayVisibility();
await this.getInlineMenuVisibility();
await this.getAuthStatus();
}
@@ -641,7 +641,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
/**
* Gets the overlay's visibility setting from the settings service.
*/
private async getOverlayVisibility(): Promise<InlineMenuVisibilitySetting> {
private async getInlineMenuVisibility(): Promise<InlineMenuVisibilitySetting> {
return await firstValueFrom(this.autofillSettingsService.inlineMenuVisibility$);
}

View File

@@ -230,7 +230,7 @@ describe("AutofillOverlayContentService", () => {
autofillFieldData,
);
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("getAutofillOverlayVisibility");
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("getInlineMenuVisibilitySetting");
expect(autofillOverlayContentService["autofillOverlayVisibility"]).toEqual(
AutofillOverlayVisibility.OnFieldFocus,
);

View File

@@ -93,7 +93,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
}
if (!this.autofillOverlayVisibility) {
await this.getAutofillOverlayVisibility();
await this.getInlineMenuVisibilitySetting();
}
this.setupFormFieldElementEventListeners(formFieldElement);
@@ -722,8 +722,8 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
* If the setting is not found, a default value of OnFieldFocus will be used
* @private
*/
private async getAutofillOverlayVisibility() {
const overlayVisibility = await this.sendExtensionMessage("getAutofillOverlayVisibility");
private async getInlineMenuVisibilitySetting() {
const overlayVisibility = await this.sendExtensionMessage("getInlineMenuVisibilitySetting");
this.autofillOverlayVisibility = overlayVisibility || AutofillOverlayVisibility.OnFieldFocus;
}

View File

@@ -108,7 +108,7 @@ describe("AutofillService", () => {
.spyOn(BrowserApi, "getAllFrames")
.mockResolvedValue([mock<chrome.webNavigation.GetAllFrameResultDetails>({ frameId: 0 })]);
jest
.spyOn(autofillService, "getOverlayVisibility")
.spyOn(autofillService, "getInlineMenuVisibility")
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
jest.spyOn(autofillService, "getAutofillOnPageLoad").mockResolvedValue(true);
});
@@ -186,7 +186,7 @@ describe("AutofillService", () => {
sender = { tab: tabMock, frameId: 1 };
jest.spyOn(BrowserApi, "executeScriptInTab").mockImplementation();
jest
.spyOn(autofillService, "getOverlayVisibility")
.spyOn(autofillService, "getInlineMenuVisibility")
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
jest.spyOn(autofillService, "getAutofillOnPageLoad").mockResolvedValue(true);
});
@@ -232,7 +232,7 @@ describe("AutofillService", () => {
it("will inject the bootstrap-autofill script if the user does not have the autofill overlay enabled", async () => {
jest
.spyOn(autofillService, "getOverlayVisibility")
.spyOn(autofillService, "getInlineMenuVisibility")
.mockResolvedValue(AutofillOverlayVisibility.Off);
await autofillService.injectAutofillScripts(sender.tab, sender.frameId);

View File

@@ -99,7 +99,7 @@ export default class AutofillService implements AutofillServiceInterface {
frameId = 0,
triggeringOnPageLoad = true,
): Promise<void> {
const mainAutofillScript = (await this.getOverlayVisibility())
const mainAutofillScript = (await this.getInlineMenuVisibility())
? "bootstrap-autofill-overlay.js"
: "bootstrap-autofill.js";
@@ -199,7 +199,7 @@ export default class AutofillService implements AutofillServiceInterface {
/**
* Gets the overlay's visibility setting from the autofill settings service.
*/
async getOverlayVisibility(): Promise<InlineMenuVisibilitySetting> {
async getInlineMenuVisibility(): Promise<InlineMenuVisibilitySetting> {
return await firstValueFrom(this.autofillSettingsService.inlineMenuVisibility$);
}