2022-11-06 11:40:23 +03:00
|
|
|
import {
|
2021-12-24 15:14:13 +03:00
|
|
|
DEFAULT_SHORT_URLS_ORDERING,
|
2021-02-14 15:28:17 +03:00
|
|
|
setRealTimeUpdatesInterval,
|
|
|
|
setShortUrlCreationSettings,
|
2023-02-18 13:11:01 +03:00
|
|
|
setShortUrlsListSettings,
|
|
|
|
setTagsSettings,
|
|
|
|
settingsReducer,
|
2021-02-16 21:25:23 +03:00
|
|
|
setUiSettings,
|
2021-03-06 18:54:43 +03:00
|
|
|
setVisitsSettings,
|
2023-02-18 13:11:01 +03:00
|
|
|
toggleRealTimeUpdates,
|
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' };
|
2021-12-24 16:15:28 +03:00
|
|
|
const shortUrlsList = { defaultOrdering: DEFAULT_SHORT_URLS_ORDERING };
|
|
|
|
const settings = { realTimeUpdates, shortUrlCreation, ui, visits, shortUrlsList };
|
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', () => {
|
2023-03-18 14:35:33 +03:00
|
|
|
expect(settingsReducer(undefined, toggleRealTimeUpdates(realTimeUpdates.enabled))).toEqual(settings);
|
2020-04-25 11:22:17 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-09 20:16:04 +03:00
|
|
|
describe('toggleRealTimeUpdates', () => {
|
2022-03-26 14:17:42 +03:00
|
|
|
it.each([[true], [false]])('updates settings with provided value and then loads updates again', (enabled) => {
|
2023-03-18 14:35:33 +03:00
|
|
|
const { payload } = toggleRealTimeUpdates(enabled);
|
|
|
|
expect(payload).toEqual({ realTimeUpdates: { enabled } });
|
2020-04-25 11:22:17 +03:00
|
|
|
});
|
|
|
|
});
|
2020-09-09 20:16:04 +03:00
|
|
|
|
|
|
|
describe('setRealTimeUpdatesInterval', () => {
|
2022-03-26 14:17:42 +03:00
|
|
|
it.each([[0], [1], [2], [10]])('updates settings with provided value and then loads updates again', (interval) => {
|
2023-03-18 14:35:33 +03:00
|
|
|
const { payload } = setRealTimeUpdatesInterval(interval);
|
|
|
|
expect(payload).toEqual({ 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', () => {
|
2023-03-18 14:35:33 +03:00
|
|
|
const { payload } = setShortUrlCreationSettings({ validateUrls: true });
|
|
|
|
expect(payload).toEqual({ shortUrlCreation: { validateUrls: true } });
|
2021-02-14 15:28:17 +03:00
|
|
|
});
|
|
|
|
});
|
2021-02-16 21:25:23 +03:00
|
|
|
|
|
|
|
describe('setUiSettings', () => {
|
|
|
|
it('creates action to set ui settings', () => {
|
2023-03-18 14:35:33 +03:00
|
|
|
const { payload } = setUiSettings({ theme: 'dark' });
|
|
|
|
expect(payload).toEqual({ ui: { theme: 'dark' } });
|
2021-02-16 21:25:23 +03:00
|
|
|
});
|
|
|
|
});
|
2021-03-06 18:54:43 +03:00
|
|
|
|
|
|
|
describe('setVisitsSettings', () => {
|
|
|
|
it('creates action to set visits settings', () => {
|
2023-03-18 14:35:33 +03:00
|
|
|
const { payload } = setVisitsSettings({ defaultInterval: 'last180Days' });
|
|
|
|
expect(payload).toEqual({ visits: { defaultInterval: 'last180Days' } });
|
2021-03-06 18:54:43 +03:00
|
|
|
});
|
|
|
|
});
|
2021-12-24 15:14:13 +03:00
|
|
|
|
|
|
|
describe('setTagsSettings', () => {
|
|
|
|
it('creates action to set tags settings', () => {
|
2023-03-18 14:35:33 +03:00
|
|
|
const { payload } = setTagsSettings({ defaultMode: 'list' });
|
|
|
|
expect(payload).toEqual({ tags: { defaultMode: 'list' } });
|
2021-12-24 15:14:13 +03:00
|
|
|
});
|
|
|
|
});
|
2021-12-24 16:15:28 +03:00
|
|
|
|
|
|
|
describe('setShortUrlsListSettings', () => {
|
|
|
|
it('creates action to set short URLs list settings', () => {
|
2023-03-18 14:35:33 +03:00
|
|
|
const { payload } = setShortUrlsListSettings({ defaultOrdering: DEFAULT_SHORT_URLS_ORDERING });
|
|
|
|
expect(payload).toEqual({ shortUrlsList: { defaultOrdering: DEFAULT_SHORT_URLS_ORDERING } });
|
2021-12-24 16:15:28 +03:00
|
|
|
});
|
|
|
|
});
|
2020-04-25 11:22:17 +03:00
|
|
|
});
|