2022-01-20 15:06:12 +00:00
|
|
|
import {
|
|
|
|
selectServerRequest,
|
|
|
|
serverRequest,
|
|
|
|
selectServerSuccess,
|
|
|
|
serverInitAdd,
|
|
|
|
serverFailure,
|
|
|
|
serverFinishAdd,
|
|
|
|
selectServerFailure
|
|
|
|
} from '../actions/server';
|
2022-01-19 16:30:45 +00:00
|
|
|
import { mockedStore } from './mockedStore';
|
|
|
|
import { initialState } from './server';
|
|
|
|
|
|
|
|
describe('test server reducer', () => {
|
|
|
|
it('should return initial state', () => {
|
|
|
|
const state = mockedStore.getState().server;
|
|
|
|
expect(state).toEqual(initialState);
|
|
|
|
});
|
|
|
|
|
2022-01-20 15:06:12 +00:00
|
|
|
it('should return modified store after serverRequest', () => {
|
|
|
|
const server = 'https://open.rocket.chat/';
|
|
|
|
mockedStore.dispatch(serverRequest(server));
|
|
|
|
const state = mockedStore.getState().server;
|
|
|
|
const manipulated = { ...initialState, connecting: true, failure: false };
|
|
|
|
expect(state).toEqual(manipulated);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return modified store after selectServerFailure', () => {
|
|
|
|
mockedStore.dispatch(selectServerFailure());
|
|
|
|
const state = mockedStore.getState().server;
|
|
|
|
const manipulated = { ...initialState, connecting: false, connected: false, loading: false, changingServer: false };
|
|
|
|
expect(state).toEqual(manipulated);
|
|
|
|
});
|
|
|
|
|
2022-01-19 16:30:45 +00:00
|
|
|
it('should return modified store after selectServer', () => {
|
|
|
|
const server = 'https://open.rocket.chat/';
|
|
|
|
mockedStore.dispatch(selectServerRequest(server));
|
|
|
|
const state = mockedStore.getState().server.server;
|
|
|
|
expect(state).toEqual(server);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return modified store after selectServerSucess', () => {
|
2022-01-20 15:06:12 +00:00
|
|
|
const server = 'https://open.rocket.chat/';
|
|
|
|
const version = '4.1.0';
|
|
|
|
mockedStore.dispatch(selectServerSuccess(server, version));
|
|
|
|
const state = mockedStore.getState().server;
|
|
|
|
const manipulated = { ...initialState, server, version, connected: true, loading: false };
|
|
|
|
expect(state).toEqual(manipulated);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return modified store after serverRequestInitAdd', () => {
|
|
|
|
const previousServer = 'https://mobile.rocket.chat';
|
|
|
|
mockedStore.dispatch(serverInitAdd(previousServer));
|
|
|
|
const state = mockedStore.getState().server.previousServer;
|
|
|
|
expect(state).toEqual(previousServer);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return modified store after serverFinishAdd', () => {
|
|
|
|
mockedStore.dispatch(serverFinishAdd());
|
|
|
|
const state = mockedStore.getState().server.previousServer;
|
|
|
|
expect(state).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return modified store after serverRequestFailure', () => {
|
|
|
|
mockedStore.dispatch(serverFailure('error'));
|
|
|
|
const state = mockedStore.getState().server;
|
|
|
|
expect(state.failure).toEqual(true);
|
2022-01-19 16:30:45 +00:00
|
|
|
});
|
|
|
|
});
|