Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
adonispuente committed Oct 18, 2023
1 parent 9672ed0 commit 45e2ae1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,9 @@ export const patchStalenessData = (data) => {
};

export const fetchEdgeSystem = () => {
return instance.get(`${EDGE_API_BASE}/devices/devicesview?limit=1`);
try {
return instance.get(`${EDGE_API_BASE}/devices/devicesview?limit=1`);
} catch (err) {
console.log(err);
}
};
7 changes: 5 additions & 2 deletions src/components/InventoryHostStaleness/HostStalenessCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [isFormValid, setIsFormValid] = useState(true);
const [hasEdgeSystems, setHasEdgeSystems] = useState(true);
const [isLoading, setIsLoading] = useState(true);
const [hostStalenessImmutableDefaults, setHostStalenessImmutableDefaults] =
useState({});
const [
hostStalenessConventionalDefaults,
setHostStalenessConventionalDefaults,
] = useState({});

const [isLoading, setIsLoading] = useState(true);
const dispatch = useDispatch();

const handleTabClick = (_event, tabIndex) => {
Expand Down Expand Up @@ -169,9 +169,12 @@ const HostStalenessCard = ({ canModifyHostStaleness }) => {
...immutableFilter,
});
};
const edgeSystemCheck = () => {
fetchEdgeSystem().then((res) => setHasEdgeSystems(res.data.total > 0));
};

const batchedApi = async () => {
fetchEdgeSystem().then((res) => setHasEdgeSystems(res.data.total > 0));
edgeSystemCheck();
fetchApiStalenessData();
fetchDefaultValues();
setIsLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import HostStalenessCard from '../HostStalenessCard';
import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import { getStore } from '../../../store';
import MockAdapter from 'axios-mock-adapter';
import { instance } from '@redhat-cloud-services/frontend-components-utilities/interceptors';

jest.mock('react-redux', () => {
return {
...jest.requireActual('react-redux'),
useDispatch: () => {},
describe('Table Renders', () => {
const mock = new MockAdapter(instance);
const stalenessData = {
conventional_staleness_delta: 86400,
conventional_stale_warning_delta: 604800,
conventional_culling_delta: 1209600,
immutable_staleness_delta: 172800,
immutable_stale_warning_delta: 1290600,
immutable_culling_delta: 15552000,
id: 'system_default',
};
});

describe('Table Renders', () => {
it('Renders table with two tabs and updates when edit is selected', () => {
render(<HostStalenessCard canModifyHostStaleness={true} />);
render(
<MemoryRouter>
<Provider store={getStore()}>
<HostStalenessCard canModifyHostStaleness={true} />
</Provider>
</MemoryRouter>
);
mock
.onGet(`/api/edge/v1/devices/devicesview?limit=1`)
.reply(200, { data: { total: 1 } });
mock.onGet('/api/inventory/v1/account/staleness').reply(200, stalenessData);

expect(
screen.getByRole('tab', { name: 'Conventional (RPM-DNF)' })
Expand Down

0 comments on commit 45e2ae1

Please sign in to comment.