diff --git a/frontend/tests/e2e/apply/fixtures/attachment-field-definitions.ts b/frontend/tests/e2e/apply/fixtures/attachment-field-definitions.ts index 6401678ca5..f5e67d6050 100644 --- a/frontend/tests/e2e/apply/fixtures/attachment-field-definitions.ts +++ b/frontend/tests/e2e/apply/fixtures/attachment-field-definitions.ts @@ -1,9 +1,18 @@ import { FormFillFieldDefinitions } from "tests/e2e/utils/common/types"; import { FORM_DEFAULTS } from "tests/e2e/utils/forms/form-defaults"; +/** + * For application attachments, the attachment field name is assoicated to + * to a visible and hidden input. The visible input for virus scanning + * is rendered, but the value of the form field lives on the hidden input. + * + * For example, if a form field has an attachment property "att1", there + * will be a hidden input with `name` and `id` property of "att1" and a + * visible file input of "att1-visible" + */ export const fieldDefinitionsAttachment: FormFillFieldDefinitions = { att1: { - selector: 'input[name="att1"][type="file"]', + selector: 'input[name="att1-visible"][type="file"]', type: "file", field: "Attachment 1", }, diff --git a/frontend/tests/e2e/apply/submission/specs/submission-printview-attachment.spec.ts b/frontend/tests/e2e/apply/submission/specs/submission-printview-attachment.spec.ts index 1e0dfa7d2a..03d0610d08 100644 --- a/frontend/tests/e2e/apply/submission/specs/submission-printview-attachment.spec.ts +++ b/frontend/tests/e2e/apply/submission/specs/submission-printview-attachment.spec.ts @@ -61,7 +61,7 @@ test.beforeEach(({ page: _ }, testInfo) => { }); for (const { testName, orgLabel } of applicantScenarios) { - test.skip( + test( testName, { tag: [SMOKE, GRANTEE, APPLY, APPLY_FORMS, CORE_REGRESSION] }, async ( diff --git a/frontend/tests/e2e/utils/common/file-handler.ts b/frontend/tests/e2e/utils/common/file-handler.ts index 0b9ed3d271..1d26418aba 100644 --- a/frontend/tests/e2e/utils/common/file-handler.ts +++ b/frontend/tests/e2e/utils/common/file-handler.ts @@ -32,10 +32,17 @@ export const fileHandler: FieldHandler = async ( await locator.scrollIntoViewIfNeeded(); const inputName = await locator.getAttribute("name"); const inputId = await locator.getAttribute("id"); - const hiddenInputSelector = inputName - ? `input[type="hidden"][name="${inputName}"]` - : inputId - ? `input[type="hidden"][name="${inputId}"], input[type="hidden"]#${inputId}` + + // Certain virus-scanning upload implementations such as apply forms, name the visible file + // input `${fieldId}-visible` while the actual form value lives in a hidden input + // named `${fieldId}` so strip the suffix so both widget variants resolve. + const toHiddenInputName = (value: string) => value.replace(/-visible$/, ""); + const hiddenInputName = inputName ? toHiddenInputName(inputName) : null; + const hiddenInputId = inputId ? toHiddenInputName(inputId) : null; + const hiddenInputSelector = hiddenInputName + ? `input[type="hidden"][name="${hiddenInputName}"]` + : hiddenInputId + ? `input[type="hidden"][name="${hiddenInputId}"], input[type="hidden"]#${hiddenInputId}` : null; await locator.setInputFiles(data); const fileName = data.split(/[/\\]/).pop() ?? data; @@ -45,8 +52,13 @@ export const fileHandler: FieldHandler = async ( .locator( "xpath=ancestor::*[contains(concat(' ', normalize-space(@class), ' '), ' usa-form-group ') or contains(concat(' ', normalize-space(@class), ' '), ' simpler-formgroup ')][1]", ) - .locator("span") + // SimplerFileInput (virus scanning) component renders it in a div FileInputExistingFiles + // and non-virus scanning file uploads render it in a span. + // Filter to visible elements - the USWDS file input keeps a hidden + // preview node containing the file name after upload. + .locator("span, div") .filter({ hasText: fileName }) + .filter({ visible: true }) .first() .waitFor({ state: "visible", timeout: 30000 }); } else { @@ -73,8 +85,10 @@ export const fileHandler: FieldHandler = async ( if (!fieldContainer) { return false; } - return Array.from(fieldContainer.querySelectorAll("span")).some( - (span) => span.textContent?.trim() === uploadedFileName, + return Array.from(fieldContainer.querySelectorAll("span, div")).some( + (element) => + element.textContent?.trim() === uploadedFileName && + element.checkVisibility(), ); }, { selector: hiddenInputSelector, uploadedFileName: fileName },