Skip to content

Commit bb93ce0

Browse files
committed
test(nav): SCIX-813 add test for graphics count badge
Also fix MSW graphics handler route (missing leading slash on :id param).
1 parent 7455f1e commit bb93ce0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/components/__tests__/AbstractSideNav.test.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { render } from '@/test-utils';
2-
import { test, vi } from 'vitest';
1+
import { render, screen, waitFor } from '@/test-utils';
2+
import { expect, test, vi } from 'vitest';
33
import { AbstractSideNav } from '@/components/AbstractSideNav';
44
import { IDocsEntity } from '@/api/search/types';
55

@@ -18,3 +18,17 @@ const doc =
1818
test('renders without crashing', () => {
1919
render(<AbstractSideNav doc={JSON.parse(doc) as IDocsEntity} />);
2020
});
21+
22+
test('displays graphics count badge when graphics are available', async () => {
23+
render(<AbstractSideNav doc={JSON.parse(doc) as IDocsEntity} />);
24+
25+
// The MSW mock handler returns 7 figures for the graphics endpoint.
26+
// Wait for the badge "7" to appear near the Graphics label.
27+
await waitFor(() => {
28+
const graphicsText = screen.getAllByText('Graphics');
29+
// Walk up to the nearest button/link container
30+
const container = graphicsText[0].closest('a, button');
31+
expect(container).toBeTruthy();
32+
expect(container).toHaveTextContent('7');
33+
});
34+
});

src/mocks/handlers/graphics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IADSApiGraphicsParams } from '@/api/graphics/types';
55
import { ApiTargets } from '@/api/models';
66

77
export const graphicsHandlers = [
8-
rest.get<IADSApiGraphicsParams>(apiHandlerRoute(ApiTargets.GRAPHICS, ':id'), (req, res, ctx) => {
8+
rest.get<IADSApiGraphicsParams>(apiHandlerRoute(ApiTargets.GRAPHICS, '/:id'), (req, res, ctx) => {
99
return res(
1010
ctx.status(200),
1111
ctx.json({

0 commit comments

Comments
 (0)