mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
[PM-5189] Implementing jest tests for AutofillInlineMenuContentService
This commit is contained in:
@@ -82,9 +82,9 @@ describe("AutofillInlineMenuContentService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("closes both inline menu elements and removes the body element mutation observer", async () => {
|
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,
|
autofillInlineMenuContentService as any,
|
||||||
"removeBodyElementObserver",
|
"unobserveBodyElement",
|
||||||
);
|
);
|
||||||
sendMockExtensionMessage({
|
sendMockExtensionMessage({
|
||||||
command: "appendAutofillInlineMenuToDom",
|
command: "appendAutofillInlineMenuToDom",
|
||||||
@@ -99,7 +99,7 @@ describe("AutofillInlineMenuContentService", () => {
|
|||||||
command: "closeAutofillInlineMenu",
|
command: "closeAutofillInlineMenu",
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(removeBodyElementObserverSpy).toHaveBeenCalled();
|
expect(unobserveBodyElementSpy).toHaveBeenCalled();
|
||||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("autofillOverlayElementClosed", {
|
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("autofillOverlayElementClosed", {
|
||||||
overlayElement: AutofillOverlayElement.Button,
|
overlayElement: AutofillOverlayElement.Button,
|
||||||
});
|
});
|
||||||
@@ -425,4 +425,20 @@ describe("AutofillInlineMenuContentService", () => {
|
|||||||
expect(closeInlineMenuSpy).toHaveBeenCalled();
|
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,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export class AutofillInlineMenuContentService implements AutofillInlineMenuConte
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.removeBodyElementObserver();
|
this.unobserveBodyElement();
|
||||||
this.closeInlineMenuButton();
|
this.closeInlineMenuButton();
|
||||||
this.closeInlineMenuList();
|
this.closeInlineMenuList();
|
||||||
};
|
};
|
||||||
@@ -304,7 +304,7 @@ export class AutofillInlineMenuContentService implements AutofillInlineMenuConte
|
|||||||
/**
|
/**
|
||||||
* Disconnects the mutation observer for the body element.
|
* Disconnects the mutation observer for the body element.
|
||||||
*/
|
*/
|
||||||
private removeBodyElementObserver() {
|
private unobserveBodyElement() {
|
||||||
this.bodyElementMutationObserver?.disconnect();
|
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.
|
* Disconnects the mutation observers and removes the inline menu elements from the DOM.
|
||||||
*/
|
*/
|
||||||
destroy() {
|
destroy() {
|
||||||
this.documentElementMutationObserver?.disconnect();
|
|
||||||
this.closeInlineMenu();
|
this.closeInlineMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user