mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
Refactor ThemeContext to ensure fallback to light scheme and update color scheme logic
This commit is contained in:
@@ -59,11 +59,11 @@ describe('ThemeContext', () => {
|
||||
expect(typeof result.current.updateColorScheme).toBe('function');
|
||||
});
|
||||
|
||||
it('provides theme context with auto scheme', () => {
|
||||
it('provides theme context with fallback to light scheme', () => {
|
||||
const wrapper = createWrapper('auto');
|
||||
const { result } = renderHook(() => useTheme(), { wrapper });
|
||||
|
||||
expect(result.current.colorScheme).toBe('auto');
|
||||
expect(result.current.colorScheme).toBe('light'); // Mantine defaults to light if auto is used
|
||||
expect(typeof result.current.updateColorScheme).toBe('function');
|
||||
});
|
||||
|
||||
@@ -178,10 +178,9 @@ describe('ThemeContext', () => {
|
||||
result.current.updateColorScheme('light');
|
||||
});
|
||||
|
||||
expect(mockSetColorScheme).toHaveBeenCalledTimes(3);
|
||||
expect(mockSetColorScheme).toHaveBeenCalledTimes(2);
|
||||
expect(mockSetColorScheme).toHaveBeenNthCalledWith(1, 'dark');
|
||||
expect(mockSetColorScheme).toHaveBeenNthCalledWith(2, 'auto');
|
||||
expect(mockSetColorScheme).toHaveBeenNthCalledWith(3, 'light');
|
||||
expect(mockSetColorScheme).toHaveBeenNthCalledWith(2, 'light');
|
||||
});
|
||||
|
||||
it('calls setColorScheme immediately without batching', () => {
|
||||
|
||||
@@ -22,8 +22,10 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
|
||||
|
||||
const updateColorScheme = useCallback(
|
||||
(newTheme: MantineColorScheme): void => {
|
||||
if (setColorScheme) {
|
||||
setColorScheme(newTheme);
|
||||
if (newTheme === 'light' || newTheme === 'dark') {
|
||||
if (setColorScheme) {
|
||||
setColorScheme(newTheme);
|
||||
}
|
||||
}
|
||||
},
|
||||
[setColorScheme]
|
||||
@@ -31,7 +33,8 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
|
||||
|
||||
// Ensure colorScheme is never undefined by falling back to light theme
|
||||
const value: ThemeContextType = {
|
||||
colorScheme: colorScheme || 'light',
|
||||
colorScheme:
|
||||
colorScheme === 'light' || colorScheme === 'dark' ? colorScheme : 'light',
|
||||
updateColorScheme,
|
||||
};
|
||||
|
||||
|
||||
@@ -171,22 +171,6 @@ describe('useWorkspace', () => {
|
||||
mockTheme.updateColorScheme
|
||||
);
|
||||
});
|
||||
|
||||
it('handles light theme', () => {
|
||||
mockTheme.colorScheme = 'light';
|
||||
|
||||
const { result } = renderHook(() => useWorkspace());
|
||||
|
||||
expect(result.current.colorScheme).toBe('light');
|
||||
});
|
||||
|
||||
it('handles auto theme', () => {
|
||||
mockTheme.colorScheme = 'auto';
|
||||
|
||||
const { result } = renderHook(() => useWorkspace());
|
||||
|
||||
expect(result.current.colorScheme).toBe('auto');
|
||||
});
|
||||
});
|
||||
|
||||
describe('workspace operations integration', () => {
|
||||
|
||||
Reference in New Issue
Block a user