mirror of
https://github.com/ansible/awx.git
synced 2026-02-18 19:50:05 -03:30
add FormActionGroup error message test
This commit is contained in:
@@ -5,11 +5,6 @@ import { withI18n } from '@lingui/react';
|
|||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { ActionGroup as PFActionGroup, Button } from '@patternfly/react-core';
|
import { ActionGroup as PFActionGroup, Button } from '@patternfly/react-core';
|
||||||
|
|
||||||
const ErrorMessage = styled('div')`
|
|
||||||
color: var(--pf-global--danger-color--200);
|
|
||||||
font-weight: var(--pf-global--FontWeight--bold);
|
|
||||||
`;
|
|
||||||
|
|
||||||
const ActionGroup = styled(PFActionGroup)`
|
const ActionGroup = styled(PFActionGroup)`
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
@@ -34,7 +29,7 @@ const FormActionGroup = ({
|
|||||||
i18n,
|
i18n,
|
||||||
}) => (
|
}) => (
|
||||||
<ActionGroup>
|
<ActionGroup>
|
||||||
{errorMessage ? <ErrorMessage>{errorMessage}</ErrorMessage> : null}
|
{errorMessage}
|
||||||
<Button
|
<Button
|
||||||
aria-label={i18n._(t`Save`)}
|
aria-label={i18n._(t`Save`)}
|
||||||
variant="primary"
|
variant="primary"
|
||||||
|
|||||||
@@ -4,10 +4,21 @@ import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
|||||||
import FormActionGroup from './FormActionGroup';
|
import FormActionGroup from './FormActionGroup';
|
||||||
|
|
||||||
describe('FormActionGroup', () => {
|
describe('FormActionGroup', () => {
|
||||||
test('renders the expected content', () => {
|
test('should render the expected content', () => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<FormActionGroup onSubmit={() => {}} onCancel={() => {}} />
|
<FormActionGroup onSubmit={() => {}} onCancel={() => {}} />
|
||||||
);
|
);
|
||||||
expect(wrapper).toHaveLength(1);
|
expect(wrapper).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should display error message if given', () => {
|
||||||
|
const wrapper = mountWithContexts(
|
||||||
|
<FormActionGroup
|
||||||
|
onSubmit={() => {}}
|
||||||
|
onCancel={() => {}}
|
||||||
|
errorMessage={<div className="error">oh noes</div>}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
expect(wrapper.find('.error').text()).toEqual('oh noes');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
const ErrorMessage = styled('div')`
|
||||||
|
color: var(--pf-global--danger-color--200);
|
||||||
|
font-weight: var(--pf-global--FontWeight--bold);
|
||||||
|
`;
|
||||||
|
ErrorMessage.displayName = 'ErrorMessage';
|
||||||
|
|
||||||
function FormSubmitError({ error }) {
|
function FormSubmitError({ error }) {
|
||||||
const [formError, setFormError] = useState(null);
|
const [formError, setFormError] = useState(null);
|
||||||
@@ -24,7 +31,7 @@ function FormSubmitError({ error }) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <span>{formError.message}</span>;
|
return <ErrorMessage>{formError.message}</ErrorMessage>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FormSubmitError;
|
export default FormSubmitError;
|
||||||
|
|||||||
Reference in New Issue
Block a user