Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
28 changes: 21 additions & 7 deletions frontend/tests/e2e/utils/common/file-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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 },
Expand Down
Loading