2021-02-14 15:28:17 +03:00
|
|
|
import reducer, {
|
|
|
|
SET_SETTINGS,
|
|
|
|
toggleRealTimeUpdates,
|
|
|
|
setRealTimeUpdatesInterval,
|
|
|
|
setShortUrlCreationSettings,
|
2021-02-16 21:25:23 +03:00
|
|
|
setUiSettings,
|
2021-02-14 15:28:17 +03:00
|
|
|
} from '../../../src/settings/reducers/settings';
|
2020-04-25 11:22:17 +03:00
|
|
|
|
2020-04-26 14:00:23 +03:00
|
|
|
describe('settingsReducer', () => {
|
|
|
|
const realTimeUpdates = { enabled: true };
|
2021-02-14 15:23:42 +03:00
|
|
|
const shortUrlCreation = { validateUrls: false };
|
2021-02-16 21:25:23 +03:00
|
|
|
const ui = { theme: 'light' };
|
|
|
|
const settings = { realTimeUpdates, shortUrlCreation, ui };
|
2020-04-25 11:22:17 +03:00
|
|
|
|
|
|
|
describe('reducer', () => {
|
2021-02-14 15:28:17 +03:00
|
|
|
it('returns realTimeUpdates when action is SET_SETTINGS', () => {
|
2021-02-14 15:23:42 +03:00
|
|
|
expect(reducer(undefined, { type: SET_SETTINGS, realTimeUpdates })).toEqual(settings);
|
2020-04-25 11:22:17 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-09 20:16:04 +03:00
|
|
|
describe('toggleRealTimeUpdates', () => {
|
2020-04-25 11:22:17 +03:00
|
|
|
it.each([[ true ], [ false ]])('updates settings with provided value and then loads updates again', (enabled) => {
|
2020-09-09 20:16:04 +03:00
|
|
|
const result = toggleRealTimeUpdates(enabled);
|
2020-04-25 11:22:17 +03:00
|
|
|
|
2021-02-14 15:23:42 +03:00
|
|
|
expect(result).toEqual({ type: SET_SETTINGS, realTimeUpdates: { enabled } });
|
2020-04-25 11:22:17 +03:00
|
|
|
});
|
|
|
|
});
|
2020-09-09 20:16:04 +03:00
|
|
|
|
|
|
|
describe('setRealTimeUpdatesInterval', () => {
|
|
|
|
it.each([[ 0 ], [ 1 ], [ 2 ], [ 10 ]])('updates settings with provided value and then loads updates again', (interval) => {
|
|
|
|
const result = setRealTimeUpdatesInterval(interval);
|
|
|
|
|
2021-02-14 15:23:42 +03:00
|
|
|
expect(result).toEqual({ type: SET_SETTINGS, realTimeUpdates: { interval } });
|
2020-09-09 20:16:04 +03:00
|
|
|
});
|
|
|
|
});
|
2021-02-14 15:28:17 +03:00
|
|
|
|
|
|
|
describe('setShortUrlCreationSettings', () => {
|
|
|
|
it('creates action to set shortUrlCreation settings', () => {
|
|
|
|
const result = setShortUrlCreationSettings({ validateUrls: true });
|
|
|
|
|
|
|
|
expect(result).toEqual({ type: SET_SETTINGS, shortUrlCreation: { validateUrls: true } });
|
|
|
|
});
|
|
|
|
});
|
2021-02-16 21:25:23 +03:00
|
|
|
|
|
|
|
describe('setUiSettings', () => {
|
|
|
|
it('creates action to set ui settings', () => {
|
|
|
|
const result = setUiSettings({ theme: 'dark' });
|
|
|
|
|
|
|
|
expect(result).toEqual({ type: SET_SETTINGS, ui: { theme: 'dark' } });
|
|
|
|
});
|
|
|
|
});
|
2020-04-25 11:22:17 +03:00
|
|
|
});
|