Skip to content

Commit

Permalink
✅ [open-formulieren/open-forms#3647] Test not setting invalid time to…
Browse files Browse the repository at this point in the history
… string 'invalid date'
  • Loading branch information
SilviaAmAm committed Dec 7, 2023
1 parent b405923 commit 1cc0fff
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/formio/components/TimeField.spec.js
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);
});
});

0 comments on commit 1cc0fff

Please sign in to comment.