Skip to content

Commit 9aac283

Browse files
committed
test: improve test coverage for useSyntaxHighlighterTheme
1 parent 7d413cf commit 9aac283

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { createTheme, ThemeProvider } from '@mui/material/styles';
2+
import { renderHook } from '@testing-library/react';
3+
import React from 'react';
4+
import { atomDark, coy, vs } from 'react-syntax-highlighter/dist/esm/styles/prism';
5+
import { useSyntaxHighlighterTheme } from '../../../src/hooks/useSyntaxHighlighterTheme';
6+
7+
const createWrapper = (mode: 'light' | 'dark') => {
8+
const theme = createTheme({ palette: { mode } });
9+
10+
function ThemeWrapper({ children }: { children: React.ReactNode }) {
11+
return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
12+
}
13+
14+
return ThemeWrapper;
15+
};
16+
17+
describe('useSyntaxHighlighterTheme', () => {
18+
test('returns atomDark when auto mode uses a dark palette', () => {
19+
const { result } = renderHook(() => useSyntaxHighlighterTheme('auto'), {
20+
wrapper: createWrapper('dark'),
21+
});
22+
23+
expect(result.current).toBe(atomDark);
24+
});
25+
26+
test('returns vs when auto mode uses a light palette', () => {
27+
const { result } = renderHook(() => useSyntaxHighlighterTheme('auto'), {
28+
wrapper: createWrapper('light'),
29+
});
30+
31+
expect(result.current).toBe(vs);
32+
});
33+
34+
test('returns the selected theme when the name is known', () => {
35+
const { result } = renderHook(() => useSyntaxHighlighterTheme('coy'), {
36+
wrapper: createWrapper('light'),
37+
});
38+
39+
expect(result.current).toBe(coy);
40+
});
41+
42+
test('falls back to atomDark when the theme name is unknown', () => {
43+
const { result } = renderHook(() => useSyntaxHighlighterTheme('unknown-theme'), {
44+
wrapper: createWrapper('light'),
45+
});
46+
47+
expect(result.current).toBe(atomDark);
48+
});
49+
});

0 commit comments

Comments
 (0)