1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-24 21:41:33 +01:00

[PM-5189] Implementing jest tests for AutofillInlineMenuContentService

This commit is contained in:
Cesar Gonzalez 2024-06-11 12:09:48 -05:00
parent 7832784be6
commit 8cea459d44
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
2 changed files with 21 additions and 6 deletions

View File

@ -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,
});
});
});
});

View File

@ -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();
}
}