1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-10 19:38:11 +01:00

[PM-5189] Implementing jest tests for the CollectAutofillContentService

This commit is contained in:
Cesar Gonzalez 2024-06-07 12:10:02 -05:00
parent 5bcb9aeb68
commit 938cb74e6e
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF

View File

@ -2592,7 +2592,21 @@ describe("CollectAutofillContentService", () => {
expect(setupAutofillOverlayListenerOnFieldSpy).not.toHaveBeenCalled();
});
it("sets up the overlay listeners on a viewable field", async () => {
it("skips setting up the inline menu listeners if the observed form field is not present in the cache", async () => {
const formFieldElement = document.createElement("input") as ElementWithOpId<FormFieldElement>;
const entries = [
{ target: formFieldElement, isIntersecting: true },
] as unknown as IntersectionObserverEntry[];
isFormFieldViewableSpy.mockReturnValueOnce(true);
collectAutofillContentService["intersectionObserver"] = mockIntersectionObserver;
await collectAutofillContentService["handleFormElementIntersection"](entries);
expect(isFormFieldViewableSpy).not.toHaveBeenCalled();
expect(setupAutofillOverlayListenerOnFieldSpy).not.toHaveBeenCalled();
});
it("sets up the inline menu listeners on a viewable field", async () => {
const formFieldElement = document.createElement("input") as ElementWithOpId<FormFieldElement>;
const autofillField = mock<AutofillField>();
const entries = [
@ -2611,4 +2625,20 @@ describe("CollectAutofillContentService", () => {
);
});
});
describe("destroy", () => {
it("clears the updateAutofillElementsAfterMutationTimeout", () => {
jest.spyOn(window, "clearTimeout");
collectAutofillContentService["updateAutofillElementsAfterMutationTimeout"] = setTimeout(
jest.fn,
100,
);
collectAutofillContentService.destroy();
expect(clearTimeout).toHaveBeenCalledWith(
collectAutofillContentService["updateAutofillElementsAfterMutationTimeout"],
);
});
});
});