shlink-web-client/test/settings/reducers/settings.test.ts

106 lines
3.3 KiB
TypeScript
Raw Normal View History

2022-11-06 11:40:23 +03:00
import {
DEFAULT_SHORT_URLS_ORDERING,
2022-11-06 11:40:23 +03:00
settingsReducer,
toggleRealTimeUpdates,
setRealTimeUpdatesInterval,
setShortUrlCreationSettings,
setUiSettings,
setVisitsSettings,
setTagsSettings,
setShortUrlsListSettings,
} from '../../../src/settings/reducers/settings';
describe('settingsReducer', () => {
const realTimeUpdates = { enabled: true };
const shortUrlCreation = { validateUrls: false };
const ui = { theme: 'light' };
2021-03-06 12:56:49 +03:00
const visits = { defaultInterval: 'last30Days' };
const shortUrlsList = { defaultOrdering: DEFAULT_SHORT_URLS_ORDERING };
const settings = { realTimeUpdates, shortUrlCreation, ui, visits, shortUrlsList };
describe('reducer', () => {
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);
});
});
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) => {
const result = toggleRealTimeUpdates(enabled);
2022-11-06 11:40:23 +03:00
expect(result).toEqual({
type: toggleRealTimeUpdates.toString(),
payload: { realTimeUpdates: { enabled } },
});
});
});
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) => {
const result = setRealTimeUpdatesInterval(interval);
2022-11-06 11:40:23 +03:00
expect(result).toEqual({
type: setRealTimeUpdatesInterval.toString(),
payload: { realTimeUpdates: { interval } },
});
});
});
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 } },
});
});
});
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' } },
});
});
});
describe('setVisitsSettings', () => {
it('creates action to set visits settings', () => {
const result = setVisitsSettings({ defaultInterval: 'last180Days' });
2022-11-06 11:40:23 +03:00
expect(result).toEqual({
type: setVisitsSettings.toString(),
payload: { visits: { defaultInterval: 'last180Days' } },
});
});
});
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' } },
});
});
});
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 } },
});
});
});
});