[PM-8027] Cleaning up implementation details
This commit is contained in:
parent
f3d41f91aa
commit
ff96fc1773
|
@ -98,7 +98,6 @@ class AutofillInit implements AutofillInitInterface {
|
|||
): Promise<AutofillPageDetails | void> {
|
||||
const pageDetails: AutofillPageDetails =
|
||||
await this.collectAutofillContentService.getPageDetails();
|
||||
|
||||
if (sendDetailsInResponse) {
|
||||
return pageDetails;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@ type UpdateAutofillDataAttributeParams = {
|
|||
};
|
||||
|
||||
interface CollectAutofillContentService {
|
||||
autofillFormElements: AutofillFormElements;
|
||||
autofillFieldElements: AutofillFieldElements;
|
||||
getPageDetails(): Promise<AutofillPageDetails>;
|
||||
getAutofillFieldElementByOpid(opid: string): HTMLElement | null;
|
||||
deepQueryElements<T>(
|
||||
|
|
|
@ -72,17 +72,14 @@ describe("CollectAutofillContentService", () => {
|
|||
it("returns an object with empty forms and fields if no fields were found on a previous iteration", async () => {
|
||||
collectAutofillContentService["domRecentlyMutated"] = false;
|
||||
collectAutofillContentService["noFieldsFound"] = true;
|
||||
jest.spyOn(collectAutofillContentService as any, "buildFormattedPageDetails");
|
||||
jest.spyOn(collectAutofillContentService as any, "getFormattedPageDetails");
|
||||
jest.spyOn(collectAutofillContentService as any, "queryAutofillFormAndFieldElements");
|
||||
jest.spyOn(collectAutofillContentService as any, "buildAutofillFormsData");
|
||||
jest.spyOn(collectAutofillContentService as any, "buildAutofillFieldsData");
|
||||
|
||||
await collectAutofillContentService.getPageDetails();
|
||||
|
||||
expect(collectAutofillContentService["buildFormattedPageDetails"]).toHaveBeenCalledWith(
|
||||
{},
|
||||
[],
|
||||
);
|
||||
expect(collectAutofillContentService["getFormattedPageDetails"]).toHaveBeenCalledWith({}, []);
|
||||
expect(
|
||||
collectAutofillContentService["queryAutofillFormAndFieldElements"],
|
||||
).not.toHaveBeenCalled();
|
||||
|
@ -159,7 +156,7 @@ describe("CollectAutofillContentService", () => {
|
|||
collectAutofillContentService["autofillFieldElements"] = new Map([
|
||||
[fieldElement, autofillField],
|
||||
]);
|
||||
jest.spyOn(collectAutofillContentService as any, "buildFormattedPageDetails");
|
||||
jest.spyOn(collectAutofillContentService as any, "getFormattedPageDetails");
|
||||
jest.spyOn(collectAutofillContentService as any, "getFormattedAutofillFormsData");
|
||||
jest.spyOn(collectAutofillContentService as any, "getFormattedAutofillFieldsData");
|
||||
jest.spyOn(collectAutofillContentService as any, "queryAutofillFormAndFieldElements");
|
||||
|
@ -168,7 +165,7 @@ describe("CollectAutofillContentService", () => {
|
|||
|
||||
await collectAutofillContentService.getPageDetails();
|
||||
|
||||
expect(collectAutofillContentService["buildFormattedPageDetails"]).toHaveBeenCalled();
|
||||
expect(collectAutofillContentService["getFormattedPageDetails"]).toHaveBeenCalled();
|
||||
expect(collectAutofillContentService["getFormattedAutofillFormsData"]).toHaveBeenCalled();
|
||||
expect(collectAutofillContentService["getFormattedAutofillFieldsData"]).toHaveBeenCalled();
|
||||
expect(
|
||||
|
|
|
@ -37,15 +37,14 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
|||
private readonly autofillOverlayContentService: AutofillOverlayContentService;
|
||||
private noFieldsFound = false;
|
||||
private domRecentlyMutated = true;
|
||||
autofillFormElements: AutofillFormElements = new Map();
|
||||
autofillFieldElements: AutofillFieldElements = new Map();
|
||||
private autofillFormElements: AutofillFormElements = new Map();
|
||||
private autofillFieldElements: AutofillFieldElements = new Map();
|
||||
private currentLocationHref = "";
|
||||
private intersectionObserver: IntersectionObserver;
|
||||
private elementInitializingIntersectionObserver: Set<Element> = new Set();
|
||||
private mutationObserver: MutationObserver;
|
||||
private updateAutofillElementsAfterMutationTimeout: number | NodeJS.Timeout;
|
||||
private mutationsQueue: MutationRecord[][] = [];
|
||||
private cachedAutofillPageDetails: AutofillPageDetails;
|
||||
private readonly updateAfterMutationTimeoutDelay = 1000;
|
||||
private readonly formFieldQueryString;
|
||||
private readonly nonInputFormFieldTags = new Set(["textarea", "select"]);
|
||||
|
@ -95,13 +94,13 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
|||
}
|
||||
|
||||
if (!this.domRecentlyMutated && this.noFieldsFound) {
|
||||
return this.buildFormattedPageDetails({}, []);
|
||||
return this.getFormattedPageDetails({}, []);
|
||||
}
|
||||
|
||||
if (!this.domRecentlyMutated && this.autofillFieldElements.size) {
|
||||
this.updateCachedAutofillFieldVisibility();
|
||||
|
||||
return this.buildFormattedPageDetails(
|
||||
return this.getFormattedPageDetails(
|
||||
this.getFormattedAutofillFormsData(),
|
||||
this.getFormattedAutofillFieldsData(),
|
||||
);
|
||||
|
@ -120,7 +119,7 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
|||
}
|
||||
|
||||
this.domRecentlyMutated = false;
|
||||
const pageDetails = this.buildFormattedPageDetails(autofillFormsData, autofillFieldsData);
|
||||
const pageDetails = this.getFormattedPageDetails(autofillFormsData, autofillFieldsData);
|
||||
this.setupInlineMenuListeners(pageDetails);
|
||||
|
||||
return pageDetails;
|
||||
|
@ -274,11 +273,11 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
|||
* @param autofillFormsData - The data for all the forms found in the page
|
||||
* @param autofillFieldsData - The data for all the fields found in the page
|
||||
*/
|
||||
private buildFormattedPageDetails(
|
||||
private getFormattedPageDetails(
|
||||
autofillFormsData: Record<string, AutofillForm>,
|
||||
autofillFieldsData: AutofillField[],
|
||||
): AutofillPageDetails {
|
||||
this.cachedAutofillPageDetails = {
|
||||
return {
|
||||
title: document.title,
|
||||
url: (document.defaultView || globalThis).location.href,
|
||||
documentUrl: document.location.href,
|
||||
|
@ -286,8 +285,6 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
|||
fields: autofillFieldsData,
|
||||
collectedTimestamp: Date.now(),
|
||||
};
|
||||
|
||||
return this.cachedAutofillPageDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1448,7 +1445,10 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
|
|||
void this.autofillOverlayContentService?.setupAutofillOverlayListenerOnField(
|
||||
formFieldElement,
|
||||
cachedAutofillFieldElement,
|
||||
this.cachedAutofillPageDetails,
|
||||
this.getFormattedPageDetails(
|
||||
this.getFormattedAutofillFormsData(),
|
||||
this.getFormattedAutofillFieldsData(),
|
||||
),
|
||||
);
|
||||
|
||||
this.intersectionObserver?.unobserve(entry.target);
|
||||
|
|
Loading…
Reference in New Issue