Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/api/graphics/graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const useGetGraphicsCount: ADSQuery<
queryKey: graphicsKeys.primary(bibcode),
queryFn: fetchGraphics,
retry: retryFn,
staleTime: 1000 * 60 * 5,
meta: { params, skipGlobalErrorHandler: true },
...options,
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/AbstractSideNav/AbstractSideNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const useGetItems = ({
href: { pathname: `${abstractPath}/${encodedDocId}/${Routes.GRAPHICS}` },
label: 'Graphics',
icon: <PhotographIcon />,
rightElement: null,
rightElement: <CountBadge count={graphicsCount} />,
disabled: graphicsCount === 0,
tooltip: 'View thumbnails of graphics published in this record',
},
Expand Down
18 changes: 16 additions & 2 deletions src/components/__tests__/AbstractSideNav.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render } from '@/test-utils';
import { test, vi } from 'vitest';
import { render, screen, waitFor } from '@/test-utils';
import { expect, test, vi } from 'vitest';
import { AbstractSideNav } from '@/components/AbstractSideNav';
import { IDocsEntity } from '@/api/search/types';

Expand All @@ -18,3 +18,17 @@ const doc =
test('renders without crashing', () => {
render(<AbstractSideNav doc={JSON.parse(doc) as IDocsEntity} />);
});

test('displays graphics count badge when graphics are available', async () => {
render(<AbstractSideNav doc={JSON.parse(doc) as IDocsEntity} />);

// The MSW mock handler returns 7 figures for the graphics endpoint.
// Wait for the badge "7" to appear near the Graphics label.
await waitFor(() => {
const graphicsText = screen.getAllByText('Graphics');
// Walk up to the nearest button/link container
const container = graphicsText[0].closest('a, button');
expect(container).toBeTruthy();
expect(container).toHaveTextContent('7');
});
Comment on lines +27 to +33
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test assertion is fairly brittle: it relies on getAllByText('Graphics'), picks the first match, then walks up the DOM with closest('a, button'). This can become flaky if both the side + top nav render in the DOM or if the markup changes. Prefer querying the specific nav item by accessible role/name (e.g., a link/button named "Graphics") and then asserting the badge within that element (using Testing Library within), ideally with findBy... instead of wrapping synchronous queries in waitFor.

Copilot uses AI. Check for mistakes.
});
2 changes: 1 addition & 1 deletion src/mocks/handlers/graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IADSApiGraphicsParams } from '@/api/graphics/types';
import { ApiTargets } from '@/api/models';

export const graphicsHandlers = [
rest.get<IADSApiGraphicsParams>(apiHandlerRoute(ApiTargets.GRAPHICS, ':id'), (req, res, ctx) => {
rest.get<IADSApiGraphicsParams>(apiHandlerRoute(ApiTargets.GRAPHICS, '/:id'), (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
Expand Down
Loading