2022-11-06 11:40:23 +03:00
|
|
|
import {
|
2021-12-24 15:14:13 +03:00
|
|
|
DEFAULT_SHORT_URLS_ORDERING,
|
2022-11-06 11:40:23 +03:00
|
|
|
settingsReducer,
|
2021-02-14 15:28:17 +03:00
|
|
|
toggleRealTimeUpdates,
|
|
|
|
setRealTimeUpdatesInterval,
|
|
|
|
setShortUrlCreationSettings,
|
2021-02-16 21:25:23 +03:00
|
|
|
setUiSettings,
|
2021-03-06 18:54:43 +03:00
|
|
|
setVisitsSettings,
|
2021-12-24 15:14:13 +03:00
|
|
|
setTagsSettings,
|
2021-12-24 16:15:28 +03:00
|
|
|
setShortUrlsListSettings,
|
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', () => {
|
2022-11-06 11:40:23 +03:00
|
|
|
expect(
|
|
|
|
settingsReducer(undefined, { type: toggleRealTimeUpdates.toString(), payload: { realTimeUpdates } }),
|
|
|
|
).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) => {
|
2020-09-09 20:16:04 +03:00
|
|
|
const result = toggleRealTimeUpdates(enabled);
|
2020-04-25 11:22:17 +03:00
|
|
|
|
2022-11-06 11:40:23 +03:00
|
|
|
expect(result).toEqual({
|
|
|
|
type: toggleRealTimeUpdates.toString(),
|
|
|
|
payload: { 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) => {
|
2020-09-09 20:16:04 +03:00
|
|
|
const result = setRealTimeUpdatesInterval(interval);
|
|
|
|
|
2022-11-06 11:40:23 +03:00
|
|
|
expect(result).toEqual({
|
|
|
|
type: setRealTimeUpdatesInterval.toString(),
|
|
|
|
payload: { 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 });
|
|
|
|
|
2022-11-06 11:40:23 +03:00
|
|
|
expect(result).toEqual({
|
|
|
|
type: setShortUrlCreationSettings.toString(),
|
|
|
|
payload: { 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', () => {
|
|
|
|
const result = setUiSettings({ theme: 'dark' });
|
|
|
|
|
2022-11-06 11:40:23 +03:00
|
|
|
expect(result).toEqual({
|
|
|
|
type: setUiSettings.toString(),
|
|
|
|
payload: { 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', () => {
|
2021-12-22 22:08:28 +03:00
|
|
|
const result = setVisitsSettings({ defaultInterval: 'last180Days' });
|
2021-03-06 18:54:43 +03:00
|
|
|
|
2022-11-06 11:40:23 +03:00
|
|
|
expect(result).toEqual({
|
|
|
|
type: setVisitsSettings.toString(),
|
|
|
|
payload: { 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', () => {
|
|
|
|
const result = setTagsSettings({ defaultMode: 'list' });
|
|
|
|
|
2022-11-06 11:40:23 +03:00
|
|
|
expect(result).toEqual({
|
|
|
|
type: setTagsSettings.toString(),
|
|
|
|
payload: { 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', () => {
|
|
|
|
const result = setShortUrlsListSettings({ defaultOrdering: DEFAULT_SHORT_URLS_ORDERING });
|
|
|
|
|
2022-11-06 11:40:23 +03:00
|
|
|
expect(result).toEqual({
|
|
|
|
type: setShortUrlsListSettings.toString(),
|
|
|
|
payload: { shortUrlsList: { defaultOrdering: DEFAULT_SHORT_URLS_ORDERING } },
|
|
|
|
});
|
2021-12-24 16:15:28 +03:00
|
|
|
});
|
|
|
|
});
|
2020-04-25 11:22:17 +03:00
|
|
|
});
|