From f1ca272394e5c8efa34a9acad6cb83269756129c Mon Sep 17 00:00:00 2001 From: nixocio Date: Thu, 17 Jun 2021 08:42:21 -0400 Subject: [PATCH] Remove test button from logging settings screen Remove test button from logging settings screen Closes: https://github.com/ansible/awx/issues/9409 --- .../Logging/LoggingEdit/LoggingEdit.jsx | 67 +------------------ .../Logging/LoggingEdit/LoggingEdit.test.jsx | 16 ----- .../Setting/shared/LoggingTestAlert.jsx | 58 ---------------- .../Setting/shared/LoggingTestAlert.test.jsx | 61 ----------------- .../src/screens/Setting/shared/index.js | 1 - 5 files changed, 3 insertions(+), 200 deletions(-) delete mode 100644 awx/ui_next/src/screens/Setting/shared/LoggingTestAlert.jsx delete mode 100644 awx/ui_next/src/screens/Setting/shared/LoggingTestAlert.test.jsx diff --git a/awx/ui_next/src/screens/Setting/Logging/LoggingEdit/LoggingEdit.jsx b/awx/ui_next/src/screens/Setting/Logging/LoggingEdit/LoggingEdit.jsx index fd403b67f8..b1b8d8e8bc 100644 --- a/awx/ui_next/src/screens/Setting/Logging/LoggingEdit/LoggingEdit.jsx +++ b/awx/ui_next/src/screens/Setting/Logging/LoggingEdit/LoggingEdit.jsx @@ -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} - > - -
- -
-
- + /> {isModalOpen && ( )} - {(testSuccess || testError) && ( - - )} ); }} diff --git a/awx/ui_next/src/screens/Setting/Logging/LoggingEdit/LoggingEdit.test.jsx b/awx/ui_next/src/screens/Setting/Logging/LoggingEdit/LoggingEdit.test.jsx index 19364a6166..efb16796c8 100644 --- a/awx/ui_next/src/screens/Setting/Logging/LoggingEdit/LoggingEdit.test.jsx +++ b/awx/ui_next/src/screens/Setting/Logging/LoggingEdit/LoggingEdit.test.jsx @@ -188,22 +188,6 @@ describe('', () => { ).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); diff --git a/awx/ui_next/src/screens/Setting/shared/LoggingTestAlert.jsx b/awx/ui_next/src/screens/Setting/shared/LoggingTestAlert.jsx deleted file mode 100644 index a9e91673fa..0000000000 --- a/awx/ui_next/src/screens/Setting/shared/LoggingTestAlert.jsx +++ /dev/null @@ -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 ( - - {testMessage && ( - } - ouiaId="logging-test-alert" - title={successResponse ? t`Success` : t`Error`} - variant={successResponse ? 'success' : 'danger'} - > - {testMessage} -

{errorData}

-
- )} -
- ); -} - -LoggingTestAlert.propTypes = { - successResponse: shape({}), - errorResponse: shape({}), - onClose: func, -}; - -LoggingTestAlert.defaultProps = { - successResponse: null, - errorResponse: null, - onClose: () => {}, -}; - -export default LoggingTestAlert; diff --git a/awx/ui_next/src/screens/Setting/shared/LoggingTestAlert.test.jsx b/awx/ui_next/src/screens/Setting/shared/LoggingTestAlert.test.jsx deleted file mode 100644 index 105cfe7382..0000000000 --- a/awx/ui_next/src/screens/Setting/shared/LoggingTestAlert.test.jsx +++ /dev/null @@ -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( - {}} - /> - ); - expect(wrapper.find('b#test-message').text()).toBe( - 'Log aggregator test sent successfully.' - ); - }); - - test('renders expected content when test is unsuccessful', () => { - wrapper = mountWithContexts( - {}} - /> - ); - 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( - - ); - wrapper.find('AlertActionCloseButton').invoke('onClose')(); - expect(onClose).toHaveBeenCalledTimes(1); - }); -}); diff --git a/awx/ui_next/src/screens/Setting/shared/index.js b/awx/ui_next/src/screens/Setting/shared/index.js index cd9a2ab833..24179bbd37 100644 --- a/awx/ui_next/src/screens/Setting/shared/index.js +++ b/awx/ui_next/src/screens/Setting/shared/index.js @@ -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';