From 20564f2f546e367be45528778d1b63a08eb44d05 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Sat, 30 Sep 2023 13:25:01 -0500 Subject: [PATCH] [PM-3704] Autofill Command Should Not Attempt to Fill If Fields Are Not Found in Page Details (#6318) * [PM-3704] Autofil Command Should Not Attempt to Fill If Fields Are Not Found in Page Details * [PM-2319] Adding jest test to ensure workflow is captured in future refactors --- .../src/autofill/services/autofill.service.spec.ts | 12 ++++++++++++ .../src/autofill/services/autofill.service.ts | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/apps/browser/src/autofill/services/autofill.service.spec.ts b/apps/browser/src/autofill/services/autofill.service.spec.ts index e6a629cfc9..f8f12fa7dd 100644 --- a/apps/browser/src/autofill/services/autofill.service.spec.ts +++ b/apps/browser/src/autofill/services/autofill.service.spec.ts @@ -780,6 +780,18 @@ describe("AutofillService", () => { ]; }); + it("returns a null vault without doing autofill if the page details does not contain fields ", async () => { + pageDetails[0].details.fields = []; + jest.spyOn(autofillService as any, "getActiveTab"); + jest.spyOn(autofillService, "doAutoFill"); + + const result = await autofillService.doAutoFillActiveTab(pageDetails, false); + + expect(autofillService["getActiveTab"]).not.toHaveBeenCalled(); + expect(autofillService.doAutoFill).not.toHaveBeenCalled(); + expect(result).toBeNull(); + }); + it("returns a null value without doing autofill if the active tab cannot be found", async () => { jest.spyOn(autofillService as any, "getActiveTab").mockResolvedValueOnce(undefined); jest.spyOn(autofillService, "doAutoFill"); diff --git a/apps/browser/src/autofill/services/autofill.service.ts b/apps/browser/src/autofill/services/autofill.service.ts index 6a61a781c0..ee233c4252 100644 --- a/apps/browser/src/autofill/services/autofill.service.ts +++ b/apps/browser/src/autofill/services/autofill.service.ts @@ -314,6 +314,10 @@ export default class AutofillService implements AutofillServiceInterface { fromCommand: boolean, cipherType?: CipherType ): Promise { + if (!pageDetails[0]?.details?.fields?.length) { + return null; + } + const tab = await this.getActiveTab(); if (!tab || !tab.url) {