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-03-06 18:54:43 +03:00
|
|
|
setVisitsSettings,
|
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' };
|
2021-03-06 12:56:49 +03:00
|
|
|
const visits = { defaultInterval: 'last30Days' };
|
|
|
|
const settings = { realTimeUpdates, shortUrlCreation, ui, visits };
|
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' } });
|
|
|
|
});
|
|
|
|
});
|
2021-03-06 18:54:43 +03:00
|
|
|
|
|
|
|
describe('setVisitsSettings', () => {
|
|
|
|
it('creates action to set visits settings', () => {
|
|
|
|
const result = setVisitsSettings({ defaultInterval: 'last180days' });
|
|
|
|
|
|
|
|
expect(result).toEqual({ type: SET_SETTINGS, visits: { defaultInterval: 'last180days' } });
|
|
|
|
});
|
|
|
|
});
|
2020-04-25 11:22:17 +03:00
|
|
|
});
|