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:
parent
5bcb9aeb68
commit
938cb74e6e
@ -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"],
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user