mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 04:06:39 +00:00
Created single reducer to handle settings
This commit is contained in:
@@ -2,34 +2,35 @@ import reducer, {
|
||||
LOAD_REAL_TIME_UPDATES,
|
||||
loadRealTimeUpdates,
|
||||
setRealTimeUpdates,
|
||||
} from '../../../src/settings/reducers/realTimeUpdates';
|
||||
} from '../../../src/settings/reducers/settings';
|
||||
|
||||
describe('realTimeUpdatesReducer', () => {
|
||||
describe('settingsReducer', () => {
|
||||
const SettingsServiceMock = {
|
||||
updateSettings: jest.fn(),
|
||||
loadSettings: jest.fn(),
|
||||
};
|
||||
const realTimeUpdates = { enabled: true };
|
||||
|
||||
afterEach(jest.clearAllMocks);
|
||||
|
||||
describe('reducer', () => {
|
||||
it('returns realTimeUpdates when action is LOAD_REAL_TIME_UPDATES', () => {
|
||||
expect(reducer({}, { type: LOAD_REAL_TIME_UPDATES, enabled: true })).toEqual({ enabled: true });
|
||||
expect(reducer({}, { type: LOAD_REAL_TIME_UPDATES, realTimeUpdates })).toEqual({ realTimeUpdates });
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadRealTimeUpdates', () => {
|
||||
it.each([
|
||||
[{}, true ],
|
||||
[{ realTimeUpdates: {} }, true ],
|
||||
[{ realTimeUpdates: { enabled: true } }, true ],
|
||||
[{ realTimeUpdates: { enabled: false } }, false ],
|
||||
])('loads settings and returns LOAD_REAL_TIME_UPDATES action', (loadedSettings, expectedEnabled) => {
|
||||
SettingsServiceMock.loadSettings.mockReturnValue(loadedSettings);
|
||||
it.each([[ true ], [ false ]])('loads settings and returns LOAD_REAL_TIME_UPDATES action', (enabled) => {
|
||||
const realTimeUpdates = { enabled };
|
||||
|
||||
SettingsServiceMock.loadSettings.mockReturnValue({ realTimeUpdates });
|
||||
|
||||
const result = loadRealTimeUpdates(SettingsServiceMock)();
|
||||
|
||||
expect(result).toEqual({ type: LOAD_REAL_TIME_UPDATES, enabled: expectedEnabled });
|
||||
expect(result).toEqual({
|
||||
type: LOAD_REAL_TIME_UPDATES,
|
||||
realTimeUpdates,
|
||||
});
|
||||
expect(SettingsServiceMock.loadSettings).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,7 @@ describe('<ShortUrlsList />', () => {
|
||||
const ShortUrlsRow = () => '';
|
||||
const listShortUrlsMock = jest.fn();
|
||||
const resetShortUrlParamsMock = jest.fn();
|
||||
const realTimeUpdates = { enabled: true };
|
||||
|
||||
const ShortUrlsList = shortUrlsListCreator(ShortUrlsRow);
|
||||
|
||||
@@ -37,6 +38,7 @@ describe('<ShortUrlsList />', () => {
|
||||
]
|
||||
}
|
||||
mercureInfo={{ loading: true }}
|
||||
settings={{ realTimeUpdates }}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -21,6 +21,7 @@ describe('<ShortUrlVisits />', () => {
|
||||
const history = {
|
||||
goBack: jest.fn(),
|
||||
};
|
||||
const realTimeUpdates = { enabled: true };
|
||||
|
||||
const createComponent = (shortUrlVisits) => {
|
||||
const ShortUrlVisits = createShortUrlVisits({ processStatsFromVisits, normalizeVisits: identity }, () => '');
|
||||
@@ -36,6 +37,7 @@ describe('<ShortUrlVisits />', () => {
|
||||
shortUrlDetail={{}}
|
||||
cancelGetShortUrlVisits={identity}
|
||||
matchMedia={() => ({ matches: false })}
|
||||
settings={{ realTimeUpdates }}
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user