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 {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) =>
<DataListToolbar
{...props}
advancedSearchDisabled={true}
advancedSearchDisabled
fillWidth
isAllSelected={isAllSelected}
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({
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 (