-
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 #609 from open-formulieren/fix/3647-invalid-time-c…
…rashes-form [#3647] Prevent invalid time from crashing form
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {screen, waitFor} 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 phoneForm = { | ||
type: 'form', | ||
components: [ | ||
{ | ||
key: 'time', | ||
type: 'time', | ||
input: true, | ||
label: 'Time', | ||
inputType: 'text', | ||
}, | ||
], | ||
}; | ||
|
||
const renderForm = async () => { | ||
let formJSON = _.cloneDeep(phoneForm); | ||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
const form = await Formio.createForm(container, formJSON); | ||
return {form, container}; | ||
}; | ||
|
||
describe('The time component', () => { | ||
afterEach(() => { | ||
document.body.innerHTML = ''; | ||
}); | ||
|
||
test('Time component with invalid time', async () => { | ||
const user = userEvent.setup({delay: 50}); | ||
const {form} = await renderForm(); | ||
|
||
const input = screen.getByLabelText('Time'); | ||
expect(input).toBeVisible(); | ||
await user.type(input, '25:00'); | ||
expect(input).toHaveDisplayValue('25:00'); | ||
|
||
expect(form.isValid()).toBe(false); | ||
}); | ||
}); |