Skip to content

Commit

Permalink
fix detail page tests
Browse files Browse the repository at this point in the history
Signed-off-by: ac892247 <[email protected]>
  • Loading branch information
achmelo committed Feb 3, 2025
1 parent 1ce0c4f commit d9fa48b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,4 @@ describe('>>> Catalog tiles actions tests', () => {
expect(actions.fetchNewServiceSuccess([])).toEqual(expectedAction);
});

it('should create when storing current tile ID', () => {
const expectedAction = {
type: constants.STORE_CURRENT_TILEID,
payload: 'id',
};

expect(actions.storeCurrentTileId('id')).toEqual(expectedAction);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,6 @@ describe('>>> Dashboard component tests', () => {
);
});

it('should stop epic on unmount', () => {
const fetchTilesStop = jest.fn();
const clear = jest.fn();
const {unmount} = render(
<Dashboard
tiles={null}
fetchTilesStart={jest.fn()}
fetchTilesStop={fetchTilesStop}
clearService={jest.fn()}
clear={clear}
assertAuthorization={jest.fn()}
authentication={jest.fn()}
/>
);
unmount();
expect(fetchTilesStop).toHaveBeenCalled();
expect(clear).toHaveBeenCalled();
});

it('should trigger filterText on handleSearch', async () => {
const filterText = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ function DetailPage({
fetchServiceStop();
setError(formatError(fetchServiceError));
}
return () => {
fetchServiceStop();
}
}, [fetchServiceError,fetchServiceStop,fetchNewService]);


Expand Down
101 changes: 37 additions & 64 deletions api-catalog-ui/frontend/src/components/DetailPage/DetailPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const tile = {
title: 'API Catalog',
description:
'API ML Microservice to locate and display API documentation for API ML discovered microservices',
tileDescription: 'Description of the tile',
status: 'UP',
secured: false,
homePageUrl: '/ui/v1/apicatalog',
Expand All @@ -49,47 +50,49 @@ jest.mock('react-router', () => {
useNavigate: () => mockNavigate,
};
});

jest.mock("../ServiceTab/ServiceTabContainer", () => ({
__esModule: true,
default: jest.fn(() => ({})),
}));
describe('>>> Detailed Page component tests', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('should start epic on mount', () => {
const fetchTilesStart = jest.fn();
const fetchNewTiles = jest.fn();
const fetchNewService = jest.fn();

renderWithProviders(<BrowserRouter>
<Routes>
<Route path="*" element={<DetailPage
tiles={[tile]}
services={tile.services}
currentTileId="apicatalog"
fetchTilesStart={fetchTilesStart}
fetchNewTiles={fetchNewTiles}
fetchTilesStop={jest.fn()}
fetchNewService={fetchNewService}
fetchServiceStop={jest.fn()}
/>}/>
</Routes>
</BrowserRouter>
);
expect(fetchTilesStart).toHaveBeenCalled();
expect(fetchNewService).toHaveBeenCalled();
});

it('should stop epic on unmount', () => {
const fetchTilesStop = jest.fn();
const fetchServiceStop = jest.fn();
const {unmount} = renderWithProviders(
<BrowserRouter>
<Routes>
<Route path="*" element={<DetailPage
tiles={[tile]}
fetchNewTiles={jest.fn()}
fetchTilesStart={jest.fn()}
fetchTilesStop={fetchTilesStop}
fetchNewService={jest.fn()}
fetchServiceStop={fetchServiceStop}
/>}/>
</Routes>
</BrowserRouter>
);
unmount();
expect(fetchTilesStop).toHaveBeenCalled();
expect(fetchServiceStop).toHaveBeenCalled();
});

it('should handle a back button click', () => {
Expand All @@ -98,11 +101,10 @@ describe('>>> Detailed Page component tests', () => {
<Routes>
<Route path="*" element={<DetailPage
tiles={[tile]}
services={tile.services}
service={tile.services[0]}
currentTileId="apicatalog"
fetchTilesStart={jest.fn()}
fetchNewTiles={jest.fn()}
fetchTilesStop={jest.fn()}
fetchNewService={jest.fn()}
fetchServiceStop={jest.fn()}
/>}/>
</Routes>
</BrowserRouter>
Expand All @@ -119,8 +121,8 @@ describe('>>> Detailed Page component tests', () => {
<Route path="*" element={<DetailPage
tiles={[tile]}
fetchTilesStart={jest.fn()}
fetchNewTiles={jest.fn()}
fetchTilesStop={jest.fn()}
fetchNewService={jest.fn()}
fetchServiceStop={jest.fn()}
isLoading={isLoading}
/>}/>
</Routes>
Expand All @@ -137,49 +139,48 @@ describe('>>> Detailed Page component tests', () => {
<Routes>
<Route path="*" element={<DetailPage
tiles={[tile]}
services={tile.services}
service={tile.services[0]}
currentTileId="apicatalog"
fetchTilesStart={jest.fn()}
fetchNewTiles={jest.fn()}
fetchTilesStop={jest.fn()}
fetchNewService={jest.fn()}
fetchServiceStop={jest.fn()}
isLoading={isLoading}
/>}/>
</Routes>
</BrowserRouter>
);
const catalogTile = screen.getByText('API Mediation Layer for z/OS internal API services');
expect(catalogTile).toBeInTheDocument();
const catalogDescription = screen.getByText('Description of the tile');
expect(catalogDescription).toBeInTheDocument();
});

it('should stop fetch tiles for 404 response code', () => {
it('should stop fetch service for 404 response code', () => {
const isLoading = false;
const fetchTilesStop = jest.fn();
const fetchTilesError = {
const fetchServiceStop = jest.fn();
const fetchServiceError = {
status: 404,
};
renderWithProviders(
const {unmount} = renderWithProviders(
<BrowserRouter>
<Routes>
<Route path="*" element={<DetailPage
tiles={[tile]}
fetchTilesStart={jest.fn()}
fetchNewTiles={jest.fn()}
fetchTilesStop={fetchTilesStop}
fetchTilesError={fetchTilesError}
fetchNewService={jest.fn()}
fetchServiceStop={fetchServiceStop}
fetchServiceError={fetchServiceError}
isLoading={isLoading}
/>}/>
</Routes>
</BrowserRouter>
);
expect(fetchTilesStop).toHaveBeenCalled();

expect(fetchServiceStop).toHaveBeenCalled();
});

it('should stop fetch tiles for error message', () => {
const isLoading = false;
const fetchTilesStop = jest.fn();
const fetchTilesError = {
const fetchServiceStop = jest.fn();
const fetchServiceError = {
message: 'some message',
};
renderWithProviders(
Expand All @@ -188,43 +189,15 @@ describe('>>> Detailed Page component tests', () => {
<Route path="*" element={<DetailPage
tiles={[tile]}
fetchTilesStart={jest.fn()}
fetchNewTiles={jest.fn()}
fetchTilesStop={fetchTilesStop}
fetchTilesError={fetchTilesError}
isLoading={isLoading}
/>}/>
</Routes>
</BrowserRouter>
);
expect(fetchTilesStop).toHaveBeenCalled();
});

it('should clear the selected service, stop and restart fetching if a different tile is selected ', () => {
const isLoading = false;
const fetchTilesError = null;
const fetchTilesStop = jest.fn();
const fetchTilesStart = jest.fn();
const clearService = jest.fn();
const selectedTile = 'apicatalog';
renderWithProviders(
<BrowserRouter>
<Routes>
<Route path="*" element={<DetailPage
tiles={[tile]}
clearService={clearService}
fetchTilesStart={fetchTilesStart}
fetchNewTiles={jest.fn()}
fetchTilesStop={fetchTilesStop}
fetchTilesError={fetchTilesError}
fetchNewService={jest.fn()}
fetchServiceStop={fetchServiceStop}
fetchServiceError={fetchServiceError}
isLoading={isLoading}
selectedTile={selectedTile}
/>}/>
</Routes>
</BrowserRouter>
);
expect(fetchTilesStop).toHaveBeenCalled();
expect(clearService).toHaveBeenCalled();
expect(fetchTilesStart).toHaveBeenCalled();
expect(fetchServiceStop).toHaveBeenCalled();
});


Expand Down

0 comments on commit d9fa48b

Please sign in to comment.