Rocket.Chat.ReactNative/app/reducers/server.test.ts

70 lines
2.4 KiB
TypeScript
Raw Normal View History

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';
2023-10-19 13:38:57 +00:00
const name = 'Rocket.Chat';
mockedStore.dispatch(selectServerSuccess({ server, version, name: 'Rocket.Chat' }));
2022-01-20 15:06:12 +00:00
const state = mockedStore.getState().server;
2023-10-19 13:38:57 +00:00
const manipulated = { ...initialState, server, version, connected: true, loading: false, name };
2022-01-20 15:06:12 +00:00
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', () => {
2023-10-19 13:38:57 +00:00
mockedStore.dispatch(serverFailure());
2022-01-20 15:06:12 +00:00
const state = mockedStore.getState().server;
expect(state.failure).toEqual(true);
2022-01-19 16:30:45 +00:00
});
});