mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
[PM-5189] Implementing jest tests for the OverlayBackground
This commit is contained in:
@@ -794,7 +794,7 @@ describe("OverlayBackground", () => {
|
|||||||
command: "openAutofillInlineMenu",
|
command: "openAutofillInlineMenu",
|
||||||
isFocusingFieldElement: false,
|
isFocusingFieldElement: false,
|
||||||
isOpeningFullAutofillInlineMenu: false,
|
isOpeningFullAutofillInlineMenu: false,
|
||||||
authStatus: 2,
|
authStatus: AuthenticationStatus.Unlocked,
|
||||||
},
|
},
|
||||||
{ frameId: 0 },
|
{ frameId: 0 },
|
||||||
);
|
);
|
||||||
@@ -814,7 +814,7 @@ describe("OverlayBackground", () => {
|
|||||||
command: "openAutofillInlineMenu",
|
command: "openAutofillInlineMenu",
|
||||||
isFocusingFieldElement: false,
|
isFocusingFieldElement: false,
|
||||||
isOpeningFullAutofillInlineMenu: false,
|
isOpeningFullAutofillInlineMenu: false,
|
||||||
authStatus: 2,
|
authStatus: AuthenticationStatus.Unlocked,
|
||||||
},
|
},
|
||||||
{ frameId: 10 },
|
{ frameId: 10 },
|
||||||
);
|
);
|
||||||
@@ -1154,6 +1154,84 @@ describe("OverlayBackground", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("checkIsAutofillInlineMenuButtonVisible", () => {
|
||||||
|
it("sends a message to the top frame of the tab to identify if the inline menu button is visible", () => {
|
||||||
|
const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } });
|
||||||
|
|
||||||
|
sendMockExtensionMessage({ command: "checkIsAutofillInlineMenuButtonVisible" }, sender);
|
||||||
|
|
||||||
|
expect(tabsSendMessageSpy).toHaveBeenCalledWith(
|
||||||
|
sender.tab,
|
||||||
|
{ command: "checkIsAutofillInlineMenuButtonVisible" },
|
||||||
|
{ frameId: 0 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("checkIsAutofillInlineMenuListVisible", () => {
|
||||||
|
it("sends a message to the top frame of the tab to identify if the inline menu list is visible", () => {
|
||||||
|
const sender = mock<chrome.runtime.MessageSender>({ tab: { id: 1 } });
|
||||||
|
|
||||||
|
sendMockExtensionMessage({ command: "checkIsAutofillInlineMenuListVisible" }, sender);
|
||||||
|
|
||||||
|
expect(tabsSendMessageSpy).toHaveBeenCalledWith(
|
||||||
|
sender.tab,
|
||||||
|
{ command: "checkIsAutofillInlineMenuListVisible" },
|
||||||
|
{ frameId: 0 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("unlockCompleted", () => {
|
||||||
|
let updateOverlayCiphersSpy: jest.SpyInstance;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
updateOverlayCiphersSpy = jest.spyOn(overlayBackground, "updateOverlayCiphers");
|
||||||
|
await initOverlayElementPorts();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("updates the inline menu button auth status", async () => {
|
||||||
|
sendMockExtensionMessage({ command: "unlockCompleted" });
|
||||||
|
await flushPromises();
|
||||||
|
|
||||||
|
expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({
|
||||||
|
command: "updateInlineMenuButtonAuthStatus",
|
||||||
|
authStatus: AuthenticationStatus.Unlocked,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("updates the overlay ciphers", async () => {
|
||||||
|
const updateOverlayCiphersSpy = jest.spyOn(overlayBackground, "updateOverlayCiphers");
|
||||||
|
sendMockExtensionMessage({ command: "unlockCompleted" });
|
||||||
|
await flushPromises();
|
||||||
|
|
||||||
|
expect(updateOverlayCiphersSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("opens the inline menu if a retry command is present in the message", async () => {
|
||||||
|
updateOverlayCiphersSpy.mockImplementation();
|
||||||
|
getTabFromCurrentWindowIdSpy.mockResolvedValueOnce(createChromeTabMock({ id: 1 }));
|
||||||
|
sendMockExtensionMessage({
|
||||||
|
command: "unlockCompleted",
|
||||||
|
data: {
|
||||||
|
commandToRetry: { message: { command: "openAutofillInlineMenu" } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await flushPromises();
|
||||||
|
|
||||||
|
expect(tabsSendMessageSpy).toHaveBeenCalledWith(
|
||||||
|
expect.any(Object),
|
||||||
|
{
|
||||||
|
command: "openAutofillInlineMenu",
|
||||||
|
isFocusingFieldElement: true,
|
||||||
|
isOpeningFullAutofillInlineMenu: false,
|
||||||
|
authStatus: AuthenticationStatus.Unlocked,
|
||||||
|
},
|
||||||
|
{ frameId: 0 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("extension messages that trigger an update of the inline menu ciphers", () => {
|
describe("extension messages that trigger an update of the inline menu ciphers", () => {
|
||||||
const extensionMessages = [
|
const extensionMessages = [
|
||||||
"addedCipher",
|
"addedCipher",
|
||||||
|
|||||||
@@ -140,8 +140,6 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
this.setupExtensionMessageListeners();
|
this.setupExtensionMessageListeners();
|
||||||
const env = await firstValueFrom(this.environmentService.environment$);
|
const env = await firstValueFrom(this.environmentService.environment$);
|
||||||
this.iconsServerUrl = env.getIconsUrl();
|
this.iconsServerUrl = env.getIconsUrl();
|
||||||
await this.getInlineMenuVisibility();
|
|
||||||
await this.getAuthStatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -836,7 +834,6 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
* @param message - Extension message received from the `unlockCompleted` command
|
* @param message - Extension message received from the `unlockCompleted` command
|
||||||
*/
|
*/
|
||||||
private async unlockCompleted(message: OverlayBackgroundExtensionMessage) {
|
private async unlockCompleted(message: OverlayBackgroundExtensionMessage) {
|
||||||
await this.getAuthStatus();
|
|
||||||
await this.updateInlineMenuButtonAuthStatus();
|
await this.updateInlineMenuButtonAuthStatus();
|
||||||
await this.updateOverlayCiphers();
|
await this.updateOverlayCiphers();
|
||||||
|
|
||||||
@@ -985,7 +982,9 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
*
|
*
|
||||||
* @param sender - The sender of the message
|
* @param sender - The sender of the message
|
||||||
*/
|
*/
|
||||||
private async checkIsAutofillInlineMenuButtonVisible(sender: chrome.runtime.MessageSender) {
|
private async checkIsAutofillInlineMenuButtonVisible(
|
||||||
|
sender: chrome.runtime.MessageSender,
|
||||||
|
): Promise<boolean> {
|
||||||
return await BrowserApi.tabSendMessage(
|
return await BrowserApi.tabSendMessage(
|
||||||
sender.tab,
|
sender.tab,
|
||||||
{ command: "checkIsAutofillInlineMenuButtonVisible" },
|
{ command: "checkIsAutofillInlineMenuButtonVisible" },
|
||||||
@@ -998,7 +997,9 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
*
|
*
|
||||||
* @param sender - The sender of the message
|
* @param sender - The sender of the message
|
||||||
*/
|
*/
|
||||||
private async checkIsAutofillInlineMenuListVisible(sender: chrome.runtime.MessageSender) {
|
private async checkIsAutofillInlineMenuListVisible(
|
||||||
|
sender: chrome.runtime.MessageSender,
|
||||||
|
): Promise<boolean> {
|
||||||
return await BrowserApi.tabSendMessage(
|
return await BrowserApi.tabSendMessage(
|
||||||
sender.tab,
|
sender.tab,
|
||||||
{ command: "checkIsAutofillInlineMenuListVisible" },
|
{ command: "checkIsAutofillInlineMenuListVisible" },
|
||||||
|
|||||||
Reference in New Issue
Block a user