Skip to content

Commit

Permalink
fix(RHINENG-5953): Fix zero state not loading on no systems
Browse files Browse the repository at this point in the history
Fixes https://issues.redhat.com/browse/RHINENG-5953.

The zero state component is now correctly rendered if there are no conventional nor immutable systems available for account.
  • Loading branch information
gkarat committed Jan 5, 2024
1 parent 8831d1d commit d0b1280
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,19 @@ export const Routes = () => {
const stalenessAndDeletionEnabled = useFeatureFlag('hbi.custom-staleness');

useEffect(() => {
// zero state check
try {
(async () => {
const hasConventionalSystems = await inventoryHasConventionalSystems();
setHasConventionalSystems(hasConventionalSystems);

if (edgeParityInventoryListEnabled) {
const hasEdgeSystems = await inventoryHasEdgeSystems();
setHasConventionalSystems(hasConventionalSystems);
setHasEdgeDevices(hasEdgeSystems);
}
})();
} catch (e) {
console.log(e);
console.error(e);
}
}, []);

Expand Down
45 changes: 45 additions & 0 deletions src/Routes.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/display-name */
/* eslint-disable react/prop-types */
import '@testing-library/jest-dom';
import { render, screen, waitFor } from '@testing-library/react';
Expand All @@ -6,10 +7,18 @@ import { MemoryRouter } from 'react-router-dom';
import { Routes } from './Routes';
import useFeatureFlag from './Utilities/useFeatureFlag';
import InventoryGroups from './components/InventoryGroups';
import { inventoryHasConventionalSystems } from './Utilities/conventional';
import { inventoryHasEdgeSystems } from './Utilities/edge';

jest.mock('./Utilities/useFeatureFlag');
jest.mock('./components/InventoryGroups');
jest.mock('./Utilities/conventional');
jest.mock('./Utilities/edge');
jest.mock(
'@redhat-cloud-services/frontend-components/AsyncComponent',
() => () => <span>Zero state</span>
);
jest.mock('./Utilities/Wrapper', () => () => <span>Route component</span>);

const TestWrapper = ({ route }) => (
<MemoryRouter initialEntries={[route]}>
Expand Down Expand Up @@ -49,3 +58,39 @@ describe('/groups', () => {
});
});
});

describe('zero state', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('renderes zero state when there are no systems', async () => {
inventoryHasConventionalSystems.mockReturnValue(false);
inventoryHasEdgeSystems.mockReturnValue(false);
render(<TestWrapper route={'/'} />);

await waitFor(() => {
expect(screen.getByText('Zero state')).toBeVisible();
});
});

it('renders a route when there are some conventional systems', async () => {
inventoryHasConventionalSystems.mockReturnValue(true);
inventoryHasEdgeSystems.mockReturnValue(false);
render(<TestWrapper route={'/'} />);

await waitFor(() => {
expect(screen.getByText('Route component')).toBeVisible();
});
});

it('renders a route when there are some edge systems', async () => {
inventoryHasConventionalSystems.mockReturnValue(false);
inventoryHasEdgeSystems.mockReturnValue(true);
render(<TestWrapper route={'/'} />);

await waitFor(() => {
expect(screen.getByText('Route component')).toBeVisible();
});
});
});

0 comments on commit d0b1280

Please sign in to comment.