mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 14:53:33 +00:00
[PM-5189] Fixing jest tests
This commit is contained in:
@@ -282,7 +282,7 @@ describe("OverlayBackground", () => {
|
|||||||
it("will attempt to build the sub frame offsets by posting window messages if a set of offsets is not returned", async () => {
|
it("will attempt to build the sub frame offsets by posting window messages if a set of offsets is not returned", async () => {
|
||||||
const tab = createChromeTabMock({ id: tabId });
|
const tab = createChromeTabMock({ id: tabId });
|
||||||
const frameId = 1;
|
const frameId = 1;
|
||||||
tabsSendMessageSpy.mockResolvedValueOnce(null);
|
tabsSendMessageSpy.mockResolvedValue(null);
|
||||||
sendMockExtensionMessage(
|
sendMockExtensionMessage(
|
||||||
{ command: "collectPageDetailsResponse", details: createAutofillPageDetailsMock() },
|
{ command: "collectPageDetailsResponse", details: createAutofillPageDetailsMock() },
|
||||||
mock<chrome.runtime.MessageSender>({ tab, frameId }),
|
mock<chrome.runtime.MessageSender>({ tab, frameId }),
|
||||||
@@ -384,12 +384,12 @@ describe("OverlayBackground", () => {
|
|||||||
it("rebuilds the sub frame offsets for a given tab", async () => {
|
it("rebuilds the sub frame offsets for a given tab", async () => {
|
||||||
const sender = mock<chrome.runtime.MessageSender>({ tab, frameId: middleFrameId });
|
const sender = mock<chrome.runtime.MessageSender>({ tab, frameId: middleFrameId });
|
||||||
|
|
||||||
sendMockExtensionMessage({ command: "repositionInlineMenuForSubFrame" }, sender);
|
sendMockExtensionMessage({ command: "repositionAutofillInlineMenuForSubFrame" }, sender);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
|
||||||
expect(getFrameDetailsSpy).toHaveBeenCalledWith({ tabId, frameId: topFrameId });
|
expect(getFrameDetailsSpy).toHaveBeenCalledWith({ tabId, frameId: topFrameId });
|
||||||
expect(getFrameDetailsSpy).toHaveBeenCalledWith({ tabId, frameId: bottomFrameId });
|
expect(getFrameDetailsSpy).toHaveBeenCalledWith({ tabId, frameId: bottomFrameId });
|
||||||
expect(getFrameDetailsSpy).not.toHaveBeenCalledWith({ tabId, frameId: middleFrameId });
|
expect(getFrameDetailsSpy).toHaveBeenCalledWith({ tabId, frameId: middleFrameId });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("triggers an update of the inline menu position after rebuilding sub frames", async () => {
|
it("triggers an update of the inline menu position after rebuilding sub frames", async () => {
|
||||||
@@ -399,7 +399,10 @@ describe("OverlayBackground", () => {
|
|||||||
jest.spyOn(overlayBackground as any, "updateInlineMenuPositionAfterSubFrameRebuild");
|
jest.spyOn(overlayBackground as any, "updateInlineMenuPositionAfterSubFrameRebuild");
|
||||||
|
|
||||||
sendMockExtensionMessage(
|
sendMockExtensionMessage(
|
||||||
{ command: "repositionInlineMenuForSubFrame", triggerInlineMenuPositionUpdate: true },
|
{
|
||||||
|
command: "repositionAutofillInlineMenuForSubFrame",
|
||||||
|
triggerInlineMenuPositionUpdate: true,
|
||||||
|
},
|
||||||
sender,
|
sender,
|
||||||
);
|
);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
@@ -458,7 +461,10 @@ describe("OverlayBackground", () => {
|
|||||||
|
|
||||||
it("updates the position of the inline menu elements", async () => {
|
it("updates the position of the inline menu elements", async () => {
|
||||||
sendMockExtensionMessage(
|
sendMockExtensionMessage(
|
||||||
{ command: "repositionInlineMenuForSubFrame", triggerInlineMenuPositionUpdate: true },
|
{
|
||||||
|
command: "repositionAutofillInlineMenuForSubFrame",
|
||||||
|
triggerInlineMenuPositionUpdate: true,
|
||||||
|
},
|
||||||
sender,
|
sender,
|
||||||
);
|
);
|
||||||
await flushInlineMenuUpdatePromises();
|
await flushInlineMenuUpdatePromises();
|
||||||
@@ -491,7 +497,10 @@ describe("OverlayBackground", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
sendMockExtensionMessage(
|
sendMockExtensionMessage(
|
||||||
{ command: "repositionInlineMenuForSubFrame", triggerInlineMenuPositionUpdate: true },
|
{
|
||||||
|
command: "repositionAutofillInlineMenuForSubFrame",
|
||||||
|
triggerInlineMenuPositionUpdate: true,
|
||||||
|
},
|
||||||
sender,
|
sender,
|
||||||
);
|
);
|
||||||
await flushInlineMenuUpdatePromises();
|
await flushInlineMenuUpdatePromises();
|
||||||
@@ -1154,15 +1163,13 @@ describe("OverlayBackground", () => {
|
|||||||
overlayElement: AutofillOverlayElement.List,
|
overlayElement: AutofillOverlayElement.List,
|
||||||
});
|
});
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
jest.advanceTimersByTime(50);
|
jest.advanceTimersByTime(150);
|
||||||
|
|
||||||
expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({
|
expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({
|
||||||
command: "updateAutofillInlineMenuPosition",
|
command: "fadeInAutofillInlineMenuIframe",
|
||||||
styles: { opacity: "1" },
|
|
||||||
});
|
});
|
||||||
expect(listPortSpy.postMessage).toHaveBeenCalledWith({
|
expect(listPortSpy.postMessage).toHaveBeenCalledWith({
|
||||||
command: "updateAutofillInlineMenuPosition",
|
command: "fadeInAutofillInlineMenuIframe",
|
||||||
styles: { opacity: "1" },
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1198,14 +1205,14 @@ describe("OverlayBackground", () => {
|
|||||||
command: "toggleAutofillInlineMenuHidden",
|
command: "toggleAutofillInlineMenuHidden",
|
||||||
styles: {
|
styles: {
|
||||||
display: "none",
|
display: "none",
|
||||||
opacity: 1,
|
opacity: "1",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(listPortSpy.postMessage).toHaveBeenCalledWith({
|
expect(listPortSpy.postMessage).toHaveBeenCalledWith({
|
||||||
command: "toggleAutofillInlineMenuHidden",
|
command: "toggleAutofillInlineMenuHidden",
|
||||||
styles: {
|
styles: {
|
||||||
display: "none",
|
display: "none",
|
||||||
opacity: 1,
|
opacity: "1",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1441,7 +1448,7 @@ describe("OverlayBackground", () => {
|
|||||||
sendResponse,
|
sendResponse,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(returnValue).toBe(undefined);
|
expect(returnValue).toBe(null);
|
||||||
expect(sendResponse).not.toHaveBeenCalled();
|
expect(sendResponse).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -106,15 +106,15 @@ describe("AutofillInit", () => {
|
|||||||
sender = mock<chrome.runtime.MessageSender>();
|
sender = mock<chrome.runtime.MessageSender>();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns a undefined value if a extension message handler is not found with the given message command", () => {
|
it("returns a null value if a extension message handler is not found with the given message command", () => {
|
||||||
message.command = "unknownCommand";
|
message.command = "unknownCommand";
|
||||||
|
|
||||||
const response = autofillInit["handleExtensionMessage"](message, sender, sendResponse);
|
const response = autofillInit["handleExtensionMessage"](message, sender, sendResponse);
|
||||||
|
|
||||||
expect(response).toBe(undefined);
|
expect(response).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns a undefined value if the message handler does not return a response", async () => {
|
it("returns a null value if the message handler does not return a response", async () => {
|
||||||
const response1 = await autofillInit["handleExtensionMessage"](message, sender, sendResponse);
|
const response1 = await autofillInit["handleExtensionMessage"](message, sender, sendResponse);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ describe("AutofillInit", () => {
|
|||||||
const response2 = autofillInit["handleExtensionMessage"](message, sender, sendResponse);
|
const response2 = autofillInit["handleExtensionMessage"](message, sender, sendResponse);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
|
||||||
expect(response2).toBe(undefined);
|
expect(response2).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns a true value and calls sendResponse if the message handler returns a response", async () => {
|
it("returns a true value and calls sendResponse if the message handler returns a response", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user