diff --git a/src/settings/UserInterface.tsx b/src/settings/UserInterface.tsx index 89597320..608cf65f 100644 --- a/src/settings/UserInterface.tsx +++ b/src/settings/UserInterface.tsx @@ -20,7 +20,7 @@ export const UserInterface: FC = ({ settings: { ui }, setUiS changeThemeInMarkup(theme); }} > - Use dark theme + Use dark theme. ); diff --git a/test/settings/ShortUrlCreation.test.tsx b/test/settings/ShortUrlCreation.test.tsx index 07d0bd7b..1cb92d9a 100644 --- a/test/settings/ShortUrlCreation.test.tsx +++ b/test/settings/ShortUrlCreation.test.tsx @@ -25,7 +25,7 @@ describe('', () => { [{ validateUrls: true }, true ], [{ validateUrls: false }, false ], [ undefined, false ], - ])('switch is toggled if option is tru', (shortUrlCreation, expectedChecked) => { + ])('switch is toggled if option is true', (shortUrlCreation, expectedChecked) => { const wrapper = createWrapper(shortUrlCreation); const toggle = wrapper.find(ToggleSwitch); diff --git a/test/settings/UserInterface.test.tsx b/test/settings/UserInterface.test.tsx new file mode 100644 index 00000000..e5c295e3 --- /dev/null +++ b/test/settings/UserInterface.test.tsx @@ -0,0 +1,47 @@ +import { shallow, ShallowWrapper } from 'enzyme'; +import { Mock } from 'ts-mockery'; +import { Settings, UiSettings } from '../../src/settings/reducers/settings'; +import { UserInterface } from '../../src/settings/UserInterface'; +import ToggleSwitch from '../../src/utils/ToggleSwitch'; +import { Theme } from '../../src/utils/theme'; + +describe('', () => { + let wrapper: ShallowWrapper; + const setUiSettings = jest.fn(); + const createWrapper = (ui?: UiSettings) => { + wrapper = shallow( + ({ ui })} + setUiSettings={setUiSettings} + />, + ); + + return wrapper; + }; + + afterEach(() => wrapper?.unmount()); + afterEach(jest.clearAllMocks); + + it.each([ + [{ theme: 'dark' as Theme }, true ], + [{ theme: 'light' as Theme }, false ], + [ undefined, false ], + ])('switch is toggled if theme is dark', (ui, expectedChecked) => { + const wrapper = createWrapper(ui); + const toggle = wrapper.find(ToggleSwitch); + + expect(toggle.prop('checked')).toEqual(expectedChecked); + }); + + it.each([ + [ true, 'dark' ], + [ false, 'light' ], + ])('invokes setUiSettings when toggle value changes', (checked, theme) => { + const wrapper = createWrapper(); + const toggle = wrapper.find(ToggleSwitch); + + expect(setUiSettings).not.toHaveBeenCalled(); + toggle.simulate('change', checked); + expect(setUiSettings).toHaveBeenCalledWith({ theme }); + }); +});