Remove test button from logging settings screen

Remove test button from logging settings screen

Closes: https://github.com/ansible/awx/issues/9409
This commit is contained in:
nixocio 2021-06-17 08:42:21 -04:00 committed by Shane McDonald
parent 8697387d13
commit f1ca272394
No known key found for this signature in database
GPG Key ID: 6F374AF6E9EB9374
5 changed files with 3 additions and 200 deletions

View File

@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
import { t } from '@lingui/macro';
import { Formik } from 'formik';
import { Button, Form, Tooltip } from '@patternfly/react-core';
import { Form } from '@patternfly/react-core';
import { CardBody } from '../../../../components/Card';
import ContentError from '../../../../components/ContentError';
import ContentLoading from '../../../../components/ContentLoading';
@ -18,10 +18,9 @@ import {
ObjectField,
RevertAllAlert,
RevertFormActionGroup,
LoggingTestAlert,
} from '../../shared';
import useModal from '../../../../util/useModal';
import useRequest, { useDismissableError } from '../../../../util/useRequest';
import useRequest from '../../../../util/useRequest';
import { formatJson } from '../../shared/settingUtils';
import { SettingsAPI } from '../../../../api';
@ -90,33 +89,6 @@ function LoggingEdit() {
history.push('/settings/logging/details');
};
const {
error: testLoggingError,
request: testLogging,
result: testSuccess,
setValue: setTestLogging,
} = useRequest(
useCallback(async () => {
const result = await SettingsAPI.createTest('logging', {});
return result;
}, []),
null
);
const {
error: testError,
dismissError: dismissTestError,
} = useDismissableError(testLoggingError);
const handleTest = async () => {
await testLogging();
};
const handleCloseAlert = () => {
setTestLogging(null);
dismissTestError();
};
const handleCancel = () => {
history.push('/settings/logging/details');
};
@ -231,33 +203,7 @@ function LoggingEdit() {
onCancel={handleCancel}
onSubmit={formik.handleSubmit}
onRevert={toggleModal}
>
<Tooltip
content={
formik.dirty || !formik.values.LOG_AGGREGATOR_ENABLED
? t`Save and enable log aggregation before testing the log aggregator.`
: t`Send a test log message to the configured log aggregator.`
}
>
<div>
<Button
aria-label={t`Test logging`}
ouiaId="test-logging-button"
variant="secondary"
type="button"
onClick={handleTest}
isDisabled={
formik.dirty ||
!formik.values.LOG_AGGREGATOR_ENABLED ||
testSuccess ||
testError
}
>
{t`Test`}
</Button>
</div>
</Tooltip>
</RevertFormActionGroup>
/>
</FormColumnLayout>
{isModalOpen && (
<RevertAllAlert
@ -265,13 +211,6 @@ function LoggingEdit() {
onRevertAll={handleRevertAll}
/>
)}
{(testSuccess || testError) && (
<LoggingTestAlert
successResponse={testSuccess}
errorResponse={testError}
onClose={handleCloseAlert}
/>
)}
</Form>
);
}}

View File

@ -188,22 +188,6 @@ describe('<LoggingEdit />', () => {
).toHaveLength(1);
});
test('should display successful toast when test button is clicked', async () => {
SettingsAPI.createTest.mockResolvedValue({});
expect(SettingsAPI.createTest).toHaveBeenCalledTimes(0);
expect(wrapper.find('LoggingTestAlert')).toHaveLength(0);
await act(async () => {
wrapper.find('button[aria-label="Test logging"]').invoke('onClick')();
});
wrapper.update();
await waitForElement(wrapper, 'LoggingTestAlert');
expect(SettingsAPI.createTest).toHaveBeenCalledTimes(1);
await act(async () => {
wrapper.find('AlertActionCloseButton button').invoke('onClick')();
});
await waitForElement(wrapper, 'LoggingTestAlert', el => el.length === 0);
});
test('should successfully send default values to api on form revert all', async () => {
expect(SettingsAPI.revertCategory).toHaveBeenCalledTimes(0);
expect(wrapper.find('RevertAllAlert')).toHaveLength(0);

View File

@ -1,58 +0,0 @@
import React from 'react';
import { t } from '@lingui/macro';
import { func, shape } from 'prop-types';
import {
Alert,
AlertActionCloseButton,
AlertGroup,
} from '@patternfly/react-core';
function LoggingTestAlert({ successResponse, errorResponse, onClose }) {
let testMessage = null;
if (successResponse) {
testMessage = t`Log aggregator test sent successfully.`;
}
let errorData = null;
if (errorResponse) {
testMessage = t`There was an error testing the log aggregator.`;
if (
errorResponse?.response?.statusText &&
errorResponse?.response?.status
) {
testMessage = t`${errorResponse.response.statusText}: ${errorResponse.response.status}`;
errorData = t`${errorResponse.response?.data?.error}`;
}
}
return (
<AlertGroup isToast>
{testMessage && (
<Alert
actionClose={<AlertActionCloseButton onClose={onClose} />}
ouiaId="logging-test-alert"
title={successResponse ? t`Success` : t`Error`}
variant={successResponse ? 'success' : 'danger'}
>
<b id="test-message">{testMessage}</b>
<p id="test-error">{errorData}</p>
</Alert>
)}
</AlertGroup>
);
}
LoggingTestAlert.propTypes = {
successResponse: shape({}),
errorResponse: shape({}),
onClose: func,
};
LoggingTestAlert.defaultProps = {
successResponse: null,
errorResponse: null,
onClose: () => {},
};
export default LoggingTestAlert;

View File

@ -1,61 +0,0 @@
import React from 'react';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import LoggingTestAlert from './LoggingTestAlert';
describe('LoggingTestAlert', () => {
let wrapper;
afterEach(() => {
wrapper.unmount();
jest.clearAllMocks();
});
test('renders expected content when test is successful', () => {
wrapper = mountWithContexts(
<LoggingTestAlert
successResponse={{}}
errorResponse={null}
onClose={() => {}}
/>
);
expect(wrapper.find('b#test-message').text()).toBe(
'Log aggregator test sent successfully.'
);
});
test('renders expected content when test is unsuccessful', () => {
wrapper = mountWithContexts(
<LoggingTestAlert
successResponse={null}
errorResponse={{
response: {
data: {
error: 'Name or service not known',
},
status: 400,
statusText: 'Bad Response',
},
}}
onClose={() => {}}
/>
);
expect(wrapper.find('b#test-message').text()).toBe('Bad Response: 400');
expect(wrapper.find('p#test-error').text()).toBe(
'Name or service not known'
);
});
test('close button should call "onClose"', () => {
const onClose = jest.fn();
expect(onClose).toHaveBeenCalledTimes(0);
wrapper = mountWithContexts(
<LoggingTestAlert
successResponse={{}}
errorResponse={null}
onClose={onClose}
/>
);
wrapper.find('AlertActionCloseButton').invoke('onClose')();
expect(onClose).toHaveBeenCalledTimes(1);
});
});

View File

@ -1,4 +1,3 @@
export { default as LoggingTestAlert } from './LoggingTestAlert';
export { default as SettingDetail } from './SettingDetail';
export { default as RevertAllAlert } from './RevertAllAlert';
export { default as RevertFormActionGroup } from './RevertFormActionGroup';