From 8de11218cc331663433818f0196924ae12fbb50a Mon Sep 17 00:00:00 2001 From: picklesrus Date: Thu, 15 Aug 2019 13:53:16 -0400 Subject: [PATCH] Add simple unittests for a couple of Formik components. --- test/unit/components/formik-input.test.jsx | 28 ++++++++++ test/unit/components/formik-select.test.jsx | 60 +++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 test/unit/components/formik-input.test.jsx create mode 100644 test/unit/components/formik-select.test.jsx diff --git a/test/unit/components/formik-input.test.jsx b/test/unit/components/formik-input.test.jsx new file mode 100644 index 000000000..0a59f428c --- /dev/null +++ b/test/unit/components/formik-input.test.jsx @@ -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( + + + + ); + expect(component.find('ValidationMessage').exists()).toEqual(false); + }); + + test('Validation message shown when error given', () => { + const component = mountWithIntl( + + + + ); + expect(component.find('ValidationMessage').exists()).toEqual(true); + }); +}); diff --git a/test/unit/components/formik-select.test.jsx b/test/unit/components/formik-select.test.jsx new file mode 100644 index 000000000..46accb37e --- /dev/null +++ b/test/unit/components/formik-select.test.jsx @@ -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( + + + + ); + + expect(component.find('ValidationMessage').exists()).toEqual(false); + expect(component.find(Field).exists()).toEqual(true); + }); + + test('Validation message shown when error present', () => { + const component = mountWithIntl( + + + + ); + 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( + + + + ); + expect(component.find(Field).exists()).toEqual(true); + expect(component.find(Field).prop('children').length).toEqual(2); + }); +});