|
| 1 | +import { act, renderHook } from '@testing-library/react'; |
| 2 | +import React from 'react'; |
| 3 | +import { Provider } from 'react-redux'; |
| 4 | +import { WEB_SAFE_FONTS, WEB_SAFE_MONOSPACE_FONTS } from '../../../src/constants'; |
| 5 | +import { useSettingsForm } from '../../../src/hooks/useSettingsForm'; |
| 6 | +import { createMockStore } from '../../utils'; |
| 7 | + |
| 8 | +describe('useSettingsForm', () => { |
| 9 | + const renderUseSettingsForm = () => { |
| 10 | + const store = createMockStore({ |
| 11 | + config: { |
| 12 | + theme: 'default', |
| 13 | + fontFamily: 'Custom Sans', |
| 14 | + fontFamilyMonospace: 'Custom Mono', |
| 15 | + }, |
| 16 | + }); |
| 17 | + |
| 18 | + return renderHook(() => useSettingsForm(), { |
| 19 | + wrapper: ({ children }) => <Provider store={store}>{children}</Provider>, |
| 20 | + }); |
| 21 | + }; |
| 22 | + |
| 23 | + test('updates the theme and resets custom fonts when select mode is chosen', () => { |
| 24 | + const { result } = renderUseSettingsForm(); |
| 25 | + |
| 26 | + act(() => { |
| 27 | + result.current.handleToggleTheme('aurora'); |
| 28 | + result.current.handleFontInputModeChange({} as React.MouseEvent<HTMLElement>, 'select'); |
| 29 | + result.current.handleFontInputModeMonospaceChange({} as React.MouseEvent<HTMLElement>, 'select'); |
| 30 | + }); |
| 31 | + |
| 32 | + expect(result.current.themeType).toBe('aurora'); |
| 33 | + expect(result.current.fontInputMode).toBe('select'); |
| 34 | + expect(result.current.fontFamily).toBe(WEB_SAFE_FONTS[0]); |
| 35 | + expect(result.current.fontInputModeMonospace).toBe('select'); |
| 36 | + expect(result.current.fontFamilyMonospace).toBe(WEB_SAFE_MONOSPACE_FONTS[0]); |
| 37 | + }); |
| 38 | +}); |
0 commit comments