From 8cea459d445f163692fe759de17fe4e2a5ad568b Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Tue, 11 Jun 2024 12:09:48 -0500 Subject: [PATCH] [PM-5189] Implementing jest tests for AutofillInlineMenuContentService --- ...tofill-inline-menu-content.service.spec.ts | 22 ++++++++++++++++--- .../autofill-inline-menu-content.service.ts | 5 ++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.spec.ts b/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.spec.ts index 174c94f0d4..147ffc612a 100644 --- a/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.spec.ts +++ b/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.spec.ts @@ -82,9 +82,9 @@ describe("AutofillInlineMenuContentService", () => { }); it("closes both inline menu elements and removes the body element mutation observer", async () => { - const removeBodyElementObserverSpy = jest.spyOn( + const unobserveBodyElementSpy = jest.spyOn( autofillInlineMenuContentService as any, - "removeBodyElementObserver", + "unobserveBodyElement", ); sendMockExtensionMessage({ command: "appendAutofillInlineMenuToDom", @@ -99,7 +99,7 @@ describe("AutofillInlineMenuContentService", () => { command: "closeAutofillInlineMenu", }); - expect(removeBodyElementObserverSpy).toHaveBeenCalled(); + expect(unobserveBodyElementSpy).toHaveBeenCalled(); expect(sendExtensionMessageSpy).toHaveBeenCalledWith("autofillOverlayElementClosed", { overlayElement: AutofillOverlayElement.Button, }); @@ -425,4 +425,20 @@ describe("AutofillInlineMenuContentService", () => { expect(closeInlineMenuSpy).toHaveBeenCalled(); }); }); + + describe("destroy", () => { + it("closes the inline menu", () => { + autofillInlineMenuContentService["buttonElement"] = document.createElement("div"); + autofillInlineMenuContentService["listElement"] = document.createElement("div"); + + autofillInlineMenuContentService.destroy(); + + expect(sendExtensionMessageSpy).toHaveBeenCalledWith("autofillOverlayElementClosed", { + overlayElement: AutofillOverlayElement.Button, + }); + expect(sendExtensionMessageSpy).toHaveBeenCalledWith("autofillOverlayElementClosed", { + overlayElement: AutofillOverlayElement.List, + }); + }); + }); }); diff --git a/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.ts b/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.ts index 7ff934306b..2469bd54df 100644 --- a/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.ts +++ b/apps/browser/src/autofill/overlay/inline-menu/content/autofill-inline-menu-content.service.ts @@ -103,7 +103,7 @@ export class AutofillInlineMenuContentService implements AutofillInlineMenuConte return; } - this.removeBodyElementObserver(); + this.unobserveBodyElement(); this.closeInlineMenuButton(); this.closeInlineMenuList(); }; @@ -304,7 +304,7 @@ export class AutofillInlineMenuContentService implements AutofillInlineMenuConte /** * Disconnects the mutation observer for the body element. */ - private removeBodyElementObserver() { + private unobserveBodyElement() { this.bodyElementMutationObserver?.disconnect(); } @@ -427,7 +427,6 @@ export class AutofillInlineMenuContentService implements AutofillInlineMenuConte * Disconnects the mutation observers and removes the inline menu elements from the DOM. */ destroy() { - this.documentElementMutationObserver?.disconnect(); this.closeInlineMenu(); } }