mirror of
https://github.com/ansible/awx.git
synced 2026-01-18 05:01:19 -03:30
Adds basic unit test coverage for the FieldWithPrompt component
This commit is contained in:
parent
3a2a61af82
commit
10c6297706
@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { bool, func, node, string } from 'prop-types';
|
||||
import { withI18n } from '@lingui/react';
|
||||
import { t } from '@lingui/macro';
|
||||
import { Tooltip } from '@patternfly/react-core';
|
||||
@ -72,13 +72,14 @@ function FieldWithPrompt({
|
||||
}
|
||||
|
||||
FieldWithPrompt.propTypes = {
|
||||
fieldId: PropTypes.string.isRequired,
|
||||
isRequired: PropTypes.bool,
|
||||
label: PropTypes.string.isRequired,
|
||||
promptId: PropTypes.string.isRequired,
|
||||
promptValidate: PropTypes.func,
|
||||
tooltip: PropTypes.node,
|
||||
tooltipMaxWidth: PropTypes.string,
|
||||
fieldId: string.isRequired,
|
||||
isRequired: bool,
|
||||
label: string.isRequired,
|
||||
promptId: string.isRequired,
|
||||
promptName: string.isRequired,
|
||||
promptValidate: func,
|
||||
tooltip: node,
|
||||
tooltipMaxWidth: string,
|
||||
};
|
||||
|
||||
FieldWithPrompt.defaultProps = {
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
import { Field, Formik } from 'formik';
|
||||
import FieldWithPrompt from './FieldWithPrompt';
|
||||
|
||||
describe('FieldWithPrompt', () => {
|
||||
let wrapper;
|
||||
|
||||
afterEach(() => {
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test('Required asterisk and Tooltip hidden when not required and tooltip not provided', () => {
|
||||
wrapper = mountWithContexts(
|
||||
<Formik
|
||||
initialValues={{
|
||||
ask_limit_on_launch: false,
|
||||
limit: '',
|
||||
}}
|
||||
>
|
||||
{() => (
|
||||
<FieldWithPrompt
|
||||
fieldId="job-template-limit"
|
||||
label="Limit"
|
||||
promptId="job-template-ask-limit-on-launch"
|
||||
promptName="ask_limit_on_launch"
|
||||
>
|
||||
<Field name="limit">
|
||||
{() => <input id="job-template-limit" type="text" />}
|
||||
</Field>
|
||||
</FieldWithPrompt>
|
||||
)}
|
||||
</Formik>
|
||||
);
|
||||
expect(wrapper.find('.pf-c-form__label-required')).toHaveLength(0);
|
||||
expect(wrapper.find('Tooltip')).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('Required asterisk and Tooltip shown when required and tooltip provided', () => {
|
||||
wrapper = mountWithContexts(
|
||||
<Formik
|
||||
initialValues={{
|
||||
ask_limit_on_launch: false,
|
||||
limit: '',
|
||||
}}
|
||||
>
|
||||
{() => (
|
||||
<FieldWithPrompt
|
||||
fieldId="job-template-limit"
|
||||
label="Limit"
|
||||
promptId="job-template-ask-limit-on-launch"
|
||||
promptName="ask_limit_on_launch"
|
||||
tooltip="Help text"
|
||||
isRequired
|
||||
>
|
||||
<Field name="limit">
|
||||
{() => <input id="job-template-limit" type="text" />}
|
||||
</Field>
|
||||
</FieldWithPrompt>
|
||||
)}
|
||||
</Formik>
|
||||
);
|
||||
expect(wrapper.find('.pf-c-form__label-required')).toHaveLength(1);
|
||||
expect(wrapper.find('Tooltip')).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user