2018-08-26 11:52:45 +03:00
|
|
|
import reducer, {
|
2018-12-18 21:45:09 +03:00
|
|
|
selectServer,
|
2018-08-12 10:22:18 +03:00
|
|
|
resetSelectedServer,
|
2018-12-18 21:45:09 +03:00
|
|
|
RESET_SELECTED_SERVER,
|
2018-08-12 10:22:18 +03:00
|
|
|
SELECT_SERVER,
|
|
|
|
} from '../../../src/servers/reducers/selectedServer';
|
|
|
|
import { RESET_SHORT_URL_PARAMS } from '../../../src/short-urls/reducers/shortUrlsListParams';
|
|
|
|
|
|
|
|
describe('selectedServerReducer', () => {
|
2018-08-26 11:52:45 +03:00
|
|
|
describe('reducer', () => {
|
2018-08-12 10:34:14 +03:00
|
|
|
it('returns default when action is RESET_SELECTED_SERVER', () =>
|
2018-08-26 11:52:45 +03:00
|
|
|
expect(reducer(null, { type: RESET_SELECTED_SERVER })).toEqual(null));
|
2018-08-12 10:34:14 +03:00
|
|
|
|
|
|
|
it('returns selected server when action is SELECT_SERVER', () => {
|
|
|
|
const selectedServer = { id: 'abc123' };
|
2018-08-26 00:39:27 +03:00
|
|
|
|
2018-08-26 11:52:45 +03:00
|
|
|
expect(reducer(null, { type: SELECT_SERVER, selectedServer })).toEqual(selectedServer);
|
2018-08-12 10:34:14 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-12 10:22:18 +03:00
|
|
|
describe('resetSelectedServer', () => {
|
|
|
|
it('returns proper action', () => {
|
|
|
|
expect(resetSelectedServer()).toEqual({ type: RESET_SELECTED_SERVER });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-12 10:34:14 +03:00
|
|
|
describe('selectServer', () => {
|
2018-08-12 10:22:18 +03:00
|
|
|
const serverId = 'abc123';
|
|
|
|
const selectedServer = {
|
2018-08-26 00:39:27 +03:00
|
|
|
id: serverId,
|
2018-08-12 10:22:18 +03:00
|
|
|
};
|
|
|
|
const ServersServiceMock = {
|
2019-04-19 11:29:49 +03:00
|
|
|
findServerById: jest.fn(() => selectedServer),
|
2018-08-12 10:22:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
2019-04-19 11:29:49 +03:00
|
|
|
ServersServiceMock.findServerById.mockClear();
|
2018-08-12 10:22:18 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches proper actions', () => {
|
2019-04-19 11:29:49 +03:00
|
|
|
const dispatch = jest.fn();
|
2018-08-12 10:22:18 +03:00
|
|
|
|
2018-12-18 21:45:09 +03:00
|
|
|
selectServer(ServersServiceMock)(serverId)(dispatch);
|
2018-08-12 10:22:18 +03:00
|
|
|
|
2019-04-19 13:52:55 +03:00
|
|
|
expect(dispatch).toHaveBeenCalledTimes(2);
|
|
|
|
expect(dispatch).toHaveBeenNthCalledWith(1, { type: RESET_SHORT_URL_PARAMS });
|
|
|
|
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SELECT_SERVER, selectedServer });
|
2018-08-12 10:22:18 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('invokes dependencies', () => {
|
2018-12-18 21:45:09 +03:00
|
|
|
selectServer(ServersServiceMock)(serverId)(() => {});
|
2018-08-12 10:22:18 +03:00
|
|
|
|
2019-04-19 11:29:49 +03:00
|
|
|
expect(ServersServiceMock.findServerById).toHaveBeenCalledTimes(1);
|
2018-08-12 10:22:18 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|