mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-23 07:38:07 -05:00
Add simple unittests for a couple of Formik components.
This commit is contained in:
parent
6a527be0bf
commit
8de11218cc
2 changed files with 88 additions and 0 deletions
28
test/unit/components/formik-input.test.jsx
Normal file
28
test/unit/components/formik-input.test.jsx
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import React from 'react';
|
||||||
|
import {mountWithIntl} from '../../helpers/intl-helpers.jsx';
|
||||||
|
import FormikInput from '../../../src/components/formik-forms/formik-input.jsx';
|
||||||
|
import {Formik} from 'formik';
|
||||||
|
|
||||||
|
describe('FormikInput', () => {
|
||||||
|
test('No validation message without an error', () => {
|
||||||
|
const component = mountWithIntl(
|
||||||
|
<Formik>
|
||||||
|
<FormikInput
|
||||||
|
error=""
|
||||||
|
/>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
expect(component.find('ValidationMessage').exists()).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Validation message shown when error given', () => {
|
||||||
|
const component = mountWithIntl(
|
||||||
|
<Formik>
|
||||||
|
<FormikInput
|
||||||
|
error="There was an error"
|
||||||
|
/>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
expect(component.find('ValidationMessage').exists()).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
60
test/unit/components/formik-select.test.jsx
Normal file
60
test/unit/components/formik-select.test.jsx
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
import React from 'react';
|
||||||
|
import {mountWithIntl} from '../../helpers/intl-helpers.jsx';
|
||||||
|
import FormikSelect from '../../../src/components/formik-forms/formik-select.jsx';
|
||||||
|
import {Formik} from 'formik';
|
||||||
|
import {Field} from 'formik';
|
||||||
|
|
||||||
|
describe('FormikSelect', () => {
|
||||||
|
test('No validation message without an error', () => {
|
||||||
|
const component = mountWithIntl(
|
||||||
|
<Formik>
|
||||||
|
<FormikSelect
|
||||||
|
error=""
|
||||||
|
options={[]}
|
||||||
|
/>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(component.find('ValidationMessage').exists()).toEqual(false);
|
||||||
|
expect(component.find(Field).exists()).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Validation message shown when error present', () => {
|
||||||
|
const component = mountWithIntl(
|
||||||
|
<Formik>
|
||||||
|
<FormikSelect
|
||||||
|
error="uh oh. error"
|
||||||
|
options={[]}
|
||||||
|
/>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
expect(component.find('ValidationMessage').exists()).toEqual(true);
|
||||||
|
expect(component.find(Field).exists()).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('list of options passed to formik', () => {
|
||||||
|
const optionList = [
|
||||||
|
{
|
||||||
|
disabled: false,
|
||||||
|
label: 'option1',
|
||||||
|
value: 'value1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
disabled: false,
|
||||||
|
label: 'option2',
|
||||||
|
value: 'value2'
|
||||||
|
}
|
||||||
|
|
||||||
|
];
|
||||||
|
const component = mountWithIntl(
|
||||||
|
<Formik>
|
||||||
|
<FormikSelect
|
||||||
|
error=""
|
||||||
|
options={optionList}
|
||||||
|
/>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
expect(component.find(Field).exists()).toEqual(true);
|
||||||
|
expect(component.find(Field).prop('children').length).toEqual(2);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue