Fix linting issues

This commit is contained in:
Zita Nemeckova
2023-02-28 11:51:34 +01:00
committed by John Westcott IV
parent 610f75fcb1
commit 32a56311e6
3 changed files with 79 additions and 18 deletions

View File

@@ -11,23 +11,22 @@ import DataListToolbar from 'components/DataListToolbar';
import { getQSConfig, parseQueryString } from 'util/qs'; import { getQSConfig, parseQueryString } from 'util/qs';
import {Card, PageSection} from "@patternfly/react-core"; import {Card, PageSection} from "@patternfly/react-core";
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import useSelected from 'hooks/useSelected';
import HostMetricsListItem from "./HostMetricsListItem"; import HostMetricsListItem from "./HostMetricsListItem";
import HostMetricsDeleteButton from "./HostMetricsDeleteButton"; 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() { function HostMetrics() {
const location = useLocation(); const location = useLocation();
const [breadcrumbConfig] = useState({ const [breadcrumbConfig] = useState({
'/host_metrics': t`Host Metrics`, '/host_metrics': t`Host Metrics`,
}); });
const QS_CONFIG = getQSConfig('host_metrics', {
page: 1,
page_size: 20,
order_by: 'hostname',
});
const { const {
result: { count, results }, result: { count, results },
isLoading, isLoading,
@@ -41,7 +40,7 @@ function HostMetrics() {
count: list.data.count, count: list.data.count,
results: list.data.results results: list.data.results
}; };
}, [location.search]), }, [location]),
{ results: [], count: 0 } { results: [], count: 0 }
); );
@@ -81,7 +80,7 @@ function HostMetrics() {
renderToolbar={(props) => renderToolbar={(props) =>
<DataListToolbar <DataListToolbar
{...props} {...props}
advancedSearchDisabled={true} advancedSearchDisabled
fillWidth fillWidth
isAllSelected={isAllSelected} isAllSelected={isAllSelected}
onSelectAll={selectAll} onSelectAll={selectAll}

View File

@@ -0,0 +1,68 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { HostMetricsAPI } from 'api';
import {
mountWithContexts,
waitForElement,
} from '../../../testUtils/enzymeHelpers';
import HostMetrics from './HostMetrics';
jest.mock('../../api');
const mockHostMetrics = [
{
hostname: 'Host name',
first_automation: 'now',
last_automation: 'now',
automated_counter: 1,
used_in_inventories: 1,
deleted_counter: 1,
id: 1,
}
];
function waitForLoaded(wrapper) {
return waitForElement(
wrapper,
'HostList',
(el) => el.find('ContentLoading').length === 0
);
}
describe('<HostMetrics />', () => {
beforeEach(() => {
HostMetricsAPI.read.mockResolvedValue({
data: {
count: mockHostMetrics.length,
results: mockHostMetrics,
},
});
});
afterEach(() => {
jest.clearAllMocks();
});
test('initially renders successfully', async () => {
await act(async () => {
mountWithContexts(
<HostMetrics
match={{ path: '/hosts', url: '/hosts' }}
location={{ search: '', pathname: '/hosts' }}
/>
);
});
});
test('HostMetrics are retrieved from the api and the components finishes loading', async () => {
let wrapper;
await act(async () => {
wrapper = mountWithContexts(<HostMetrics />);
});
await waitForLoaded(wrapper);
expect(HostMetricsAPI.read).toHaveBeenCalled();
expect(wrapper.find('HostMetricsListItem')).toHaveLength(1);
});
});

View File

@@ -36,7 +36,6 @@ const ItemToDelete = shape({
function HostMetricsDeleteButton({ function HostMetricsDeleteButton({
itemsToDelete, itemsToDelete,
pluralizedItemName, pluralizedItemName,
errorMessage,
onDelete, onDelete,
deleteDetailsRequests, deleteDetailsRequests,
warningMessage, warningMessage,
@@ -48,7 +47,6 @@ function HostMetricsDeleteButton({
const [deleteMessageError, setDeleteMessageError] = useState(); const [deleteMessageError, setDeleteMessageError] = useState();
const handleDelete = () => { const handleDelete = () => {
console.log("Delete");
onDelete(); onDelete();
toggleModal(); toggleModal();
}; };
@@ -78,9 +76,8 @@ function HostMetricsDeleteButton({
const renderTooltip = () => { const renderTooltip = () => {
if (itemsToDelete.length) { if (itemsToDelete.length) {
return t`Soft delete`; 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}?`; const modalTitle = t`Soft delete ${pluralizedItemName}?`;
@@ -94,10 +91,7 @@ function HostMetricsDeleteButton({
deleteMessages.push(warningMessage); deleteMessages.push(warningMessage);
} }
if (deleteMessage) { if (deleteMessage) {
if (itemsToDelete.length > 1 || deleteDetails) if (itemsToDelete.length > 1 || deleteDetails) {
{
deleteMessages.push(deleteMessage);
} else if (deleteDetails || itemsToDelete.length > 1) {
deleteMessages.push(deleteMessage); deleteMessages.push(deleteMessage);
} }
} }