Skip to content

Commit

Permalink
[PM-8833] Implementing jest tests for OverlayBackground
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesar Gonzalez committed Oct 1, 2024
1 parent 526966a commit c784cd9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 31 additions & 6 deletions apps/browser/src/autofill/background/overlay.background.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ describe("OverlayBackground", () => {
domainSettingsService.showFavicons$ = showFaviconsMock$;
domainSettingsService.neverDomains$ = neverDomainsMock$;
logService = mock<LogService>();
cipherService = mock<CipherService>();
cipherService = mock<CipherService>({
getAllDecryptedForUrl: jest.fn().mockResolvedValue([]),
});
autofillService = mock<AutofillService>();
activeAccountStatusMock$ = new BehaviorSubject(AuthenticationStatus.Unlocked);
authService = mock<AuthService>();
Expand Down Expand Up @@ -2028,11 +2030,36 @@ describe("OverlayBackground", () => {
});
getTabFromCurrentWindowIdSpy.mockResolvedValue(sender.tab);
tabsSendMessageSpy.mockImplementation();
sendMockExtensionMessage(
{ command: "updateFocusedFieldData", focusedFieldData: createFocusedFieldDataMock() },
sender,
);
});

it.todo(
"updates the inline menu position of both button and list elements if the inline menu is being forced open",
);
it("updates the inline menu position of both button and list elements if the inline menu is being forced open", async () => {
sendMockExtensionMessage(
{ command: "openAutofillInlineMenu", isOpeningFullInlineMenu: true },
sender,
);
await flushPromises();

expect(tabsSendMessageSpy).toHaveBeenCalledWith(
sender.tab,
{
command: "appendAutofillInlineMenuToDom",
overlayElement: AutofillOverlayElement.Button,
},
{ frameId: 0 },
);
expect(tabsSendMessageSpy).toHaveBeenCalledWith(
sender.tab,
{
command: "appendAutofillInlineMenuToDom",
overlayElement: AutofillOverlayElement.List,
},
{ frameId: 0 },
);
});

describe("when the focused field does not have a value", () => {
beforeEach(() => {
Expand Down Expand Up @@ -2412,7 +2439,6 @@ describe("OverlayBackground", () => {

it("focuses the most recently focused field if a retry command is present in the message", async () => {
activeAccountStatusMock$.next(AuthenticationStatus.Unlocked);
cipherService.getAllDecryptedForUrl.mockResolvedValue([]);
getTabFromCurrentWindowIdSpy.mockResolvedValueOnce(createChromeTabMock({ id: 1 }));
sendMockExtensionMessage({
command: "unlockCompleted",
Expand Down Expand Up @@ -2499,7 +2525,6 @@ describe("OverlayBackground", () => {
await initOverlayElementPorts();
buttonMessageConnectorSpy.sender = sender;
openUnlockPopoutSpy.mockImplementation();
cipherService.getAllDecryptedForUrl.mockResolvedValue([]);
});

describe("autofillInlineMenuButtonClicked message handler", () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/browser/src/autofill/background/overlay.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
{ frameId: 0 },
);

const subFrameOffsetsForTab = this.subFrameOffsetsForTab[this.focusedFieldData.tabId];
const subFrameOffsetsForTab = this.subFrameOffsetsForTab[this.focusedFieldData?.tabId];
let subFrameOffsets: SubFrameOffsetData;
if (subFrameOffsetsForTab) {
subFrameOffsets = subFrameOffsetsForTab.get(this.focusedFieldData.frameId);
Expand Down

0 comments on commit c784cd9

Please sign in to comment.