-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #717 from open-formulieren/feature/4716-accessibil…
…ity-improvements-form-fields Accessibility improvements - form fields
- Loading branch information
Showing
44 changed files
with
1,885 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import {screen} from '@testing-library/dom'; | ||
import userEvent from '@testing-library/user-event'; | ||
import _ from 'lodash'; | ||
import {Formio} from 'react-formio'; | ||
|
||
import OpenFormsModule from 'formio/module'; | ||
|
||
// Use our custom components | ||
Formio.use(OpenFormsModule); | ||
|
||
const selectboxesForm = { | ||
type: 'form', | ||
components: [ | ||
{ | ||
key: 'checkbox', | ||
type: 'checkbox', | ||
label: 'Checkbox', | ||
validate: { | ||
required: true, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const renderForm = async () => { | ||
let formJSON = _.cloneDeep(selectboxesForm); | ||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
const form = await Formio.createForm(container, formJSON); | ||
return {form, container}; | ||
}; | ||
|
||
describe('The checkbox component', () => { | ||
afterEach(() => { | ||
document.body.innerHTML = ''; | ||
}); | ||
|
||
test('Checkbox component required and checked', async () => { | ||
const user = userEvent.setup({delay: 50}); | ||
const {form} = await renderForm(); | ||
|
||
const checkbox = screen.getByLabelText('Checkbox'); | ||
|
||
expect(checkbox).toBeVisible(); | ||
|
||
await user.click(checkbox); | ||
|
||
expect(form.isValid()).toBeTruthy(); | ||
}); | ||
|
||
test('Checkbox component required without being checked', async () => { | ||
const user = userEvent.setup({delay: 50}); | ||
const {form} = await renderForm(); | ||
|
||
const checkbox = screen.getByLabelText('Checkbox'); | ||
|
||
// Check and uncheck the checkbox to trigger the validation | ||
await user.click(checkbox); | ||
await user.click(checkbox); | ||
|
||
// All selectboxes are marked as invalid and have aria-describedby and aria-invalid | ||
expect(checkbox).toHaveClass('is-invalid'); | ||
expect(checkbox).toHaveAttribute('aria-describedby'); | ||
expect(checkbox).toHaveAttribute('aria-invalid', 'true'); | ||
expect(form.isValid()).toBeFalsy(); | ||
|
||
await user.click(checkbox); | ||
|
||
// All checkboxes are again marked as valid and without aria-describedby and aria-invalid | ||
expect(checkbox).not.toHaveClass('is-invalid'); | ||
expect(checkbox).not.toHaveAttribute('aria-describedby'); | ||
expect(checkbox).not.toHaveAttribute('aria-invalid'); | ||
expect(form.isValid()).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import {screen} from '@testing-library/dom'; | ||
import userEvent from '@testing-library/user-event'; | ||
import _ from 'lodash'; | ||
import {Formio} from 'react-formio'; | ||
|
||
import OpenFormsModule from 'formio/module'; | ||
|
||
// Use our custom components | ||
Formio.use(OpenFormsModule); | ||
|
||
const currencyForm = { | ||
type: 'form', | ||
components: [ | ||
{ | ||
key: 'currency', | ||
type: 'currency', | ||
label: 'Currency', | ||
validate: { | ||
required: true, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const renderForm = async () => { | ||
let formJSON = _.cloneDeep(currencyForm); | ||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
const form = await Formio.createForm(container, formJSON); | ||
return {form, container}; | ||
}; | ||
|
||
describe('The currency component', () => { | ||
afterEach(() => { | ||
document.body.innerHTML = ''; | ||
}); | ||
|
||
test('Single currency component with valid input', async () => { | ||
const user = userEvent.setup({delay: 50}); | ||
const {form} = await renderForm(); | ||
|
||
const input = screen.getByLabelText('Currency'); | ||
|
||
expect(input).toBeVisible(); | ||
|
||
await user.type(input, '6'); | ||
|
||
expect(form.isValid()).toBeTruthy(); | ||
}); | ||
|
||
test('Single currency component with invalid input', async () => { | ||
const user = userEvent.setup({delay: 50}); | ||
const {form} = await renderForm(); | ||
|
||
const input = screen.getByLabelText('Currency'); | ||
|
||
// Trigger validation | ||
await user.type(input, '6'); | ||
await user.clear(input); | ||
await user.tab({shift: true}); | ||
|
||
// Input is invalid and should have aria-describedby and aria-invalid | ||
expect(input).toHaveClass('is-invalid'); | ||
expect(input).toHaveAttribute('aria-describedby'); | ||
expect(input).toHaveAttribute('aria-invalid', 'true'); | ||
expect(form.isValid()).toBeFalsy(); | ||
|
||
await user.type(input, '6'); | ||
await user.tab({shift: true}); | ||
|
||
// Input is again valid and without aria-describedby and aria-invalid | ||
expect(input).not.toHaveClass('is-invalid'); | ||
expect(input).not.toHaveAttribute('aria-describedby'); | ||
expect(input).not.toHaveAttribute('aria-invalid'); | ||
expect(form.isValid()).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.