mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 10:27:37 -02:30
Adds basic unit test coverage for the FieldWithPrompt component
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import { bool, func, node, string } from 'prop-types';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Tooltip } from '@patternfly/react-core';
|
import { Tooltip } from '@patternfly/react-core';
|
||||||
@@ -72,13 +72,14 @@ function FieldWithPrompt({
|
|||||||
}
|
}
|
||||||
|
|
||||||
FieldWithPrompt.propTypes = {
|
FieldWithPrompt.propTypes = {
|
||||||
fieldId: PropTypes.string.isRequired,
|
fieldId: string.isRequired,
|
||||||
isRequired: PropTypes.bool,
|
isRequired: bool,
|
||||||
label: PropTypes.string.isRequired,
|
label: string.isRequired,
|
||||||
promptId: PropTypes.string.isRequired,
|
promptId: string.isRequired,
|
||||||
promptValidate: PropTypes.func,
|
promptName: string.isRequired,
|
||||||
tooltip: PropTypes.node,
|
promptValidate: func,
|
||||||
tooltipMaxWidth: PropTypes.string,
|
tooltip: node,
|
||||||
|
tooltipMaxWidth: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
FieldWithPrompt.defaultProps = {
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user