Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add button enable/disable logic when answering enumerator questions #7321

Merged
merged 2 commits into from
Apr 30, 2024
Merged
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
53 changes: 53 additions & 0 deletions browser-test/src/end_to_end_enumerators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,59 @@ test.describe('End to end enumerator test', {tag: ['@uses-fixtures']}, () => {
await logout(page)
})

test('Enumerator add button is enabled/disabled correctly', async ({
page,
applicantQuestions,
}) => {
await test.step('Set up application', async () => {
await applicantQuestions.applyProgram(programName)

await applicantQuestions.answerNameQuestion('Porky', 'Pig')
await applicantQuestions.clickNext()
})

await test.step('Add button is enabled with a non-blank entity', async () => {
await applicantQuestions.addEnumeratorAnswer('Bugs')

await expect(
page.locator('#enumerator-field-add-button'),
).not.toHaveAttribute('disabled')
})

await test.step('Add button is disabled if an entity is blank', async () => {
await applicantQuestions.addEnumeratorAnswer('')

await expect(
page.locator('#enumerator-field-add-button'),
).toHaveAttribute('disabled')
})

await test.step('Add button is re-enabled when the blank item is removed', async () => {
await applicantQuestions.deleteEnumeratorEntityByIndex(2)

await expect(
page.locator('#enumerator-field-add-button'),
).not.toHaveAttribute('disabled')
})

await test.step('Add button is still enabled after navigating away and back', async () => {
await applicantQuestions.clickNext()
await applicantQuestions.clickPrevious()

await expect(
page.locator('#enumerator-field-add-button'),
).not.toHaveAttribute('disabled')
})

await test.step('Add button is disabled when an existing item is blanked', async () => {
await applicantQuestions.editEnumeratorAnswer('Bugs', '')

await expect(
page.locator('#enumerator-field-add-button'),
).toHaveAttribute('disabled')
})
})

test('Applicant can navigate to previous blocks', async ({
page,
applicantQuestions,
Expand Down
10 changes: 10 additions & 0 deletions browser-test/src/support/applicant_questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ export class ApplicantQuestions {
)
}

async editEnumeratorAnswer(
existingEntityName: string,
newEntityName: string,
) {
await this.page.fill(
`#enumerator-fields .cf-enumerator-field input[value="${existingEntityName}"]`,
newEntityName,
)
}

async checkEnumeratorAnswerValue(entityName: string, index: number) {
await this.page.waitForSelector(
`#enumerator-fields .cf-enumerator-field:nth-of-type(${index}) input`,
Expand Down
1 change: 1 addition & 0 deletions server/app/assets/javascripts/enumerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function removeExistingEnumeratorField(event: Event) {
enumeratorFieldDiv.querySelector('input'),
)
enumeratorInput.classList.add('hidden')
enumeratorInput.removeAttribute('data-entity-input')

// Create a copy of the hidden deleted entity template. Set the value to this
// button's ID, and set disabled to false so the data is submitted with the form.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ private static DivTag enumeratorField(
localizedEntityType)
+ indexString)
.addReferenceClass(ReferenceClasses.ENTITY_NAME_INPUT);
if (!isDisabled) {
entityNameInputField.setAttribute("data-entity-input");
}
if (elementId.isPresent()) {
entityNameInputField.setId(elementId.get());
}
Expand Down