From 32a56311e61cc30ef05b3a0f72f9d9f62608f382 Mon Sep 17 00:00:00 2001 From: Zita Nemeckova Date: Tue, 28 Feb 2023 11:51:34 +0100 Subject: [PATCH] Fix linting issues --- awx/ui/src/screens/HostMetrics/HostMetrics.js | 17 +++-- .../screens/HostMetrics/HostMetrics.test.js | 68 +++++++++++++++++++ .../HostMetrics/HostMetricsDeleteButton.js | 12 +--- 3 files changed, 79 insertions(+), 18 deletions(-) create mode 100644 awx/ui/src/screens/HostMetrics/HostMetrics.test.js diff --git a/awx/ui/src/screens/HostMetrics/HostMetrics.js b/awx/ui/src/screens/HostMetrics/HostMetrics.js index ce43a04000..c85bbc6a33 100644 --- a/awx/ui/src/screens/HostMetrics/HostMetrics.js +++ b/awx/ui/src/screens/HostMetrics/HostMetrics.js @@ -11,23 +11,22 @@ import DataListToolbar from 'components/DataListToolbar'; import { getQSConfig, parseQueryString } from 'util/qs'; import {Card, PageSection} from "@patternfly/react-core"; import { useLocation } from 'react-router-dom'; +import useSelected from 'hooks/useSelected'; import HostMetricsListItem from "./HostMetricsListItem"; import HostMetricsDeleteButton from "./HostMetricsDeleteButton"; -import useSelected from 'hooks/useSelected'; +const QS_CONFIG = getQSConfig('host_metrics', { + page: 1, + page_size: 20, + order_by: 'hostname', +}); function HostMetrics() { - const location = useLocation(); const [breadcrumbConfig] = useState({ '/host_metrics': t`Host Metrics`, }); - const QS_CONFIG = getQSConfig('host_metrics', { - page: 1, - page_size: 20, - order_by: 'hostname', - }); const { result: { count, results }, isLoading, @@ -41,7 +40,7 @@ function HostMetrics() { count: list.data.count, results: list.data.results }; - }, [location.search]), + }, [location]), { results: [], count: 0 } ); @@ -81,7 +80,7 @@ function HostMetrics() { renderToolbar={(props) => el.find('ContentLoading').length === 0 + ); +} + +describe('', () => { + beforeEach(() => { + HostMetricsAPI.read.mockResolvedValue({ + data: { + count: mockHostMetrics.length, + results: mockHostMetrics, + }, + }); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + test('initially renders successfully', async () => { + await act(async () => { + mountWithContexts( + + ); + }); + }); + + test('HostMetrics are retrieved from the api and the components finishes loading', async () => { + let wrapper; + await act(async () => { + wrapper = mountWithContexts(); + }); + await waitForLoaded(wrapper); + + expect(HostMetricsAPI.read).toHaveBeenCalled(); + expect(wrapper.find('HostMetricsListItem')).toHaveLength(1); + }); +}); diff --git a/awx/ui/src/screens/HostMetrics/HostMetricsDeleteButton.js b/awx/ui/src/screens/HostMetrics/HostMetricsDeleteButton.js index 9519ca519e..46c8fcee14 100644 --- a/awx/ui/src/screens/HostMetrics/HostMetricsDeleteButton.js +++ b/awx/ui/src/screens/HostMetrics/HostMetricsDeleteButton.js @@ -36,7 +36,6 @@ const ItemToDelete = shape({ function HostMetricsDeleteButton({ itemsToDelete, pluralizedItemName, - errorMessage, onDelete, deleteDetailsRequests, warningMessage, @@ -48,7 +47,6 @@ function HostMetricsDeleteButton({ const [deleteMessageError, setDeleteMessageError] = useState(); const handleDelete = () => { - console.log("Delete"); onDelete(); toggleModal(); }; @@ -78,9 +76,8 @@ function HostMetricsDeleteButton({ const renderTooltip = () => { if (itemsToDelete.length) { return t`Soft delete`; - } else { - return t`Select a row to delete`; } + return t`Select a row to delete`; }; const modalTitle = t`Soft delete ${pluralizedItemName}?`; @@ -94,11 +91,8 @@ function HostMetricsDeleteButton({ deleteMessages.push(warningMessage); } if (deleteMessage) { - if (itemsToDelete.length > 1 || deleteDetails) - { - deleteMessages.push(deleteMessage); - } else if (deleteDetails || itemsToDelete.length > 1) { - deleteMessages.push(deleteMessage); + if (itemsToDelete.length > 1 || deleteDetails) { + deleteMessages.push(deleteMessage); } } return (