2020-04-25 11:22:17 +03:00
|
|
|
import reducer, {
|
|
|
|
LOAD_REAL_TIME_UPDATES,
|
|
|
|
loadRealTimeUpdates,
|
|
|
|
setRealTimeUpdates,
|
2020-04-26 14:00:23 +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', () => {
|
2020-04-25 11:22:17 +03:00
|
|
|
const SettingsServiceMock = {
|
|
|
|
updateSettings: jest.fn(),
|
|
|
|
loadSettings: jest.fn(),
|
|
|
|
};
|
2020-04-26 14:00:23 +03:00
|
|
|
const realTimeUpdates = { enabled: true };
|
2020-04-25 11:22:17 +03:00
|
|
|
|
|
|
|
afterEach(jest.clearAllMocks);
|
|
|
|
|
|
|
|
describe('reducer', () => {
|
|
|
|
it('returns realTimeUpdates when action is LOAD_REAL_TIME_UPDATES', () => {
|
2020-04-26 14:00:23 +03:00
|
|
|
expect(reducer({}, { type: LOAD_REAL_TIME_UPDATES, realTimeUpdates })).toEqual({ realTimeUpdates });
|
2020-04-25 11:22:17 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('loadRealTimeUpdates', () => {
|
2020-04-26 14:00:23 +03:00
|
|
|
it.each([[ true ], [ false ]])('loads settings and returns LOAD_REAL_TIME_UPDATES action', (enabled) => {
|
|
|
|
const realTimeUpdates = { enabled };
|
|
|
|
|
|
|
|
SettingsServiceMock.loadSettings.mockReturnValue({ realTimeUpdates });
|
2020-04-25 11:22:17 +03:00
|
|
|
|
|
|
|
const result = loadRealTimeUpdates(SettingsServiceMock)();
|
|
|
|
|
2020-04-26 14:00:23 +03:00
|
|
|
expect(result).toEqual({
|
|
|
|
type: LOAD_REAL_TIME_UPDATES,
|
|
|
|
realTimeUpdates,
|
|
|
|
});
|
2020-04-25 11:22:17 +03:00
|
|
|
expect(SettingsServiceMock.loadSettings).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setRealTimeUpdates', () => {
|
|
|
|
it.each([[ true ], [ false ]])('updates settings with provided value and then loads updates again', (enabled) => {
|
|
|
|
const loadRealTimeUpdatesAction = jest.fn();
|
|
|
|
|
|
|
|
setRealTimeUpdates(SettingsServiceMock, loadRealTimeUpdatesAction)(enabled);
|
|
|
|
|
|
|
|
expect(SettingsServiceMock.updateSettings).toHaveBeenCalledWith({ realTimeUpdates: { enabled } });
|
|
|
|
expect(loadRealTimeUpdatesAction).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|