Skip to content

Commit

Permalink
[PM-2857] Finalizing implementation, writing jest tests, refactoring …
Browse files Browse the repository at this point in the history
…smaller elements
  • Loading branch information
cagonzalezcs committed Jun 28, 2024
1 parent 4bea25e commit c567c6e
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion apps/browser/src/autofill/background/overlay.background.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ describe("OverlayBackground", () => {
describe("removing pageDetails", () => {
it("removes the page details and port key for a specific tab from the pageDetailsForTab object", () => {
const tabId = 1;
portKeyForTabSpy[tabId] = "portKey";
sendMockExtensionMessage(
{ command: "collectPageDetailsResponse", details: createAutofillPageDetailsMock() },
mock<chrome.runtime.MessageSender>({ tab: createChromeTabMock({ id: tabId }), frameId: 1 }),
Expand Down Expand Up @@ -759,7 +760,7 @@ describe("OverlayBackground", () => {
);
});

it("queries all ciphers for the given url, sort them by last used, and format them for usage in the overlay", async () => {
it("queries all cipher types, sorts them by last used, and formats them for usage in the overlay", async () => {
getTabFromCurrentWindowIdSpy.mockResolvedValueOnce(tab);
cipherService.getAllDecryptedForUrl.mockResolvedValue([cipher1, cipher2]);
cipherService.sortCiphersByLastUsedThenName.mockReturnValue(-1);
Expand All @@ -777,6 +778,39 @@ describe("OverlayBackground", () => {
);
});

it("queries only login ciphers when not updating all cipher types", async () => {
overlayBackground["cardAndIdentityCiphers"] = new Set([]);
getTabFromCurrentWindowIdSpy.mockResolvedValueOnce(tab);
cipherService.getAllDecryptedForUrl.mockResolvedValue([cipher1]);
cipherService.sortCiphersByLastUsedThenName.mockReturnValue(-1);

await overlayBackground.updateOverlayCiphers(false);

expect(BrowserApi.getTabFromCurrentWindowId).toHaveBeenCalled();
expect(cipherService.getAllDecryptedForUrl).toHaveBeenCalledWith(url);
expect(overlayBackground["inlineMenuCiphers"]).toStrictEqual(
new Map([["inline-menu-cipher-0", cipher1]]),
);
});

it("queries all cipher types when the card and identity ciphers set is not built when only updating login ciphers", async () => {
getTabFromCurrentWindowIdSpy.mockResolvedValueOnce(tab);
cipherService.getAllDecryptedForUrl.mockResolvedValue([cipher1, cipher2]);
cipherService.sortCiphersByLastUsedThenName.mockReturnValue(-1);

await overlayBackground.updateOverlayCiphers(false);

expect(BrowserApi.getTabFromCurrentWindowId).toHaveBeenCalled();
expect(cipherService.getAllDecryptedForUrl).toHaveBeenCalledWith(url, [CipherType.Card]);
expect(cipherService.sortCiphersByLastUsedThenName).toHaveBeenCalled();
expect(overlayBackground["inlineMenuCiphers"]).toStrictEqual(
new Map([
["inline-menu-cipher-0", cipher2],
["inline-menu-cipher-1", cipher1],
]),
);
});

it("posts an `updateOverlayListCiphers` message to the overlay list port, and send a `updateAutofillInlineMenuListCiphers` message to the tab indicating that the list of ciphers is populated", async () => {
overlayBackground["inlineMenuListPort"] = mock<chrome.runtime.Port>();
overlayBackground["focusedFieldData"] = createFocusedFieldDataMock({ tabId: tab.id });
Expand Down

0 comments on commit c567c6e

Please sign in to comment.