Added option to customize initial state fo the 'Validate URL' option

This commit is contained in:
Alejandro Celaya
2021-02-14 13:23:42 +01:00
parent 872890e674
commit 4885088d59
8 changed files with 89 additions and 22 deletions

View File

@@ -1,11 +1,13 @@
import reducer, { SET_REAL_TIME_UPDATES, toggleRealTimeUpdates, setRealTimeUpdatesInterval } from '../../../src/settings/reducers/settings';
import reducer, { SET_SETTINGS, toggleRealTimeUpdates, setRealTimeUpdatesInterval } from '../../../src/settings/reducers/settings';
describe('settingsReducer', () => {
const realTimeUpdates = { enabled: true };
const shortUrlCreation = { validateUrls: false };
const settings = { realTimeUpdates, shortUrlCreation };
describe('reducer', () => {
it('returns realTimeUpdates when action is SET_REAL_TIME_UPDATES', () => {
expect(reducer(undefined, { type: SET_REAL_TIME_UPDATES, realTimeUpdates })).toEqual({ realTimeUpdates });
expect(reducer(undefined, { type: SET_SETTINGS, realTimeUpdates })).toEqual(settings);
});
});
@@ -13,7 +15,7 @@ describe('settingsReducer', () => {
it.each([[ true ], [ false ]])('updates settings with provided value and then loads updates again', (enabled) => {
const result = toggleRealTimeUpdates(enabled);
expect(result).toEqual({ type: SET_REAL_TIME_UPDATES, realTimeUpdates: { enabled } });
expect(result).toEqual({ type: SET_SETTINGS, realTimeUpdates: { enabled } });
});
});
@@ -21,7 +23,7 @@ describe('settingsReducer', () => {
it.each([[ 0 ], [ 1 ], [ 2 ], [ 10 ]])('updates settings with provided value and then loads updates again', (interval) => {
const result = setRealTimeUpdatesInterval(interval);
expect(result).toEqual({ type: SET_REAL_TIME_UPDATES, realTimeUpdates: { interval } });
expect(result).toEqual({ type: SET_SETTINGS, realTimeUpdates: { interval } });
});
});
});

View File

@@ -6,10 +6,12 @@ import { Input } from 'reactstrap';
import createShortUrlsCreator from '../../src/short-urls/CreateShortUrl';
import DateInput from '../../src/utils/DateInput';
import { ShortUrlCreation } from '../../src/short-urls/reducers/shortUrlCreation';
import { Settings } from '../../src/settings/reducers/settings';
describe('<CreateShortUrl />', () => {
let wrapper: ShallowWrapper;
const TagsSelector = () => null;
const shortUrlCreation = { validateUrls: true };
const shortUrlCreationResult = Mock.all<ShortUrlCreation>();
const createShortUrl = jest.fn(async () => Promise.resolve());
@@ -22,6 +24,7 @@ describe('<CreateShortUrl />', () => {
createShortUrl={createShortUrl}
selectedServer={null}
resetCreateShortUrl={() => {}}
settings={Mock.of<Settings>({ shortUrlCreation })}
/>,
);
});