2019-08-15 13:53:16 -04:00
|
|
|
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', () => {
|
2019-08-20 14:25:44 -04:00
|
|
|
test('No validation message without an error or a tooltip', () => {
|
2019-08-15 13:53:16 -04:00
|
|
|
const component = mountWithIntl(
|
|
|
|
<Formik>
|
|
|
|
<FormikInput
|
|
|
|
error=""
|
2019-08-20 14:25:44 -04:00
|
|
|
tooltip=""
|
2019-08-15 13:53:16 -04:00
|
|
|
/>
|
|
|
|
</Formik>
|
|
|
|
);
|
|
|
|
expect(component.find('ValidationMessage').exists()).toEqual(false);
|
2019-08-20 14:25:44 -04:00
|
|
|
expect(component.find('div.validation-error').exists()).toEqual(false);
|
|
|
|
expect(component.find('div.validation-info').exists()).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('No validation message with blank error or tooltip', () => {
|
|
|
|
const component = mountWithIntl(
|
|
|
|
<Formik>
|
|
|
|
<FormikInput />
|
|
|
|
</Formik>
|
|
|
|
);
|
|
|
|
expect(component.find('ValidationMessage').exists()).toEqual(false);
|
|
|
|
expect(component.find('div.validation-error').exists()).toEqual(false);
|
|
|
|
expect(component.find('div.validation-info').exists()).toEqual(false);
|
2019-08-15 13:53:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
2019-08-20 14:25:44 -04:00
|
|
|
expect(component.find('div.validation-error').exists()).toEqual(true);
|
|
|
|
expect(component.find('div.validation-info').exists()).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Tooltip shown when tooltip given', () => {
|
|
|
|
const component = mountWithIntl(
|
|
|
|
<Formik>
|
|
|
|
<FormikInput
|
|
|
|
toolTip="Have fun out there!"
|
|
|
|
/>
|
|
|
|
</Formik>
|
|
|
|
);
|
|
|
|
expect(component.find('ValidationMessage').exists()).toEqual(true);
|
|
|
|
expect(component.find('div.validation-error').exists()).toEqual(false);
|
|
|
|
expect(component.find('div.validation-info').exists()).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('If both error and tooltip messages, error takes precedence', () => {
|
|
|
|
const component = mountWithIntl(
|
|
|
|
<Formik>
|
|
|
|
<FormikInput
|
|
|
|
error="There was an error"
|
|
|
|
toolTip="Have fun out there!"
|
|
|
|
/>
|
|
|
|
</Formik>
|
|
|
|
);
|
|
|
|
expect(component.find('ValidationMessage').exists()).toEqual(true);
|
|
|
|
expect(component.find('div.validation-error').exists()).toEqual(true);
|
|
|
|
expect(component.find('div.validation-info').exists()).toEqual(false);
|
2019-08-15 13:53:16 -04:00
|
|
|
});
|
|
|
|
});
|