1
0
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:
Cesar Gonzalez
2024-06-05 13:57:02 -05:00
parent df30a205b0
commit 2efbc5ce51

View File

@@ -1585,5 +1585,33 @@ describe("OverlayBackground", () => {
expect(copyToClipboardSpy).toHaveBeenCalledWith("totp-code"); expect(copyToClipboardSpy).toHaveBeenCalledWith("totp-code");
}); });
}); });
describe("addNewVaultItem message handler", () => {
it("skips sending the `addNewVaultItemFromOverlay` message if the sender tab does not contain the focused field", async () => {
const focusedFieldData = createFocusedFieldDataMock({ tabId: 2 });
sendMockExtensionMessage({ command: "updateFocusedFieldData", focusedFieldData });
await flushPromises();
sendPortMessage(listMessageConnectorSpy, { command: "addNewVaultItem", portKey });
await flushPromises();
expect(tabsSendMessageSpy).not.toHaveBeenCalled();
});
it("sends a message to the tab to add a new vault item", async () => {
const focusedFieldData = createFocusedFieldDataMock();
sendMockExtensionMessage({ command: "updateFocusedFieldData", focusedFieldData }, sender);
await flushPromises();
sendPortMessage(listMessageConnectorSpy, { command: "addNewVaultItem", portKey });
await flushPromises();
expect(tabsSendMessageSpy).toHaveBeenCalledWith(
sender.tab,
{ command: "addNewVaultItemFromOverlay" },
{ frameId: sender.frameId },
);
});
});
}); });
}); });