[CHORE] Example of reducer & selectors specs
This commit is contained in:
parent
fcea2952c5
commit
202ecf3cab
5 changed files with 102 additions and 2 deletions
|
@ -0,0 +1,27 @@
|
|||
import { Cluster, ServerStatus } from 'generated-sources';
|
||||
|
||||
export const onlineClusterPayload: Cluster = {
|
||||
name: 'secondLocal',
|
||||
defaultCluster: true,
|
||||
status: ServerStatus.Online,
|
||||
brokerCount: 1,
|
||||
onlinePartitionCount: 6,
|
||||
topicCount: 3,
|
||||
bytesInPerSec: 1.55,
|
||||
bytesOutPerSec: 9.314,
|
||||
};
|
||||
export const offlineClusterPayload: Cluster = {
|
||||
name: 'local',
|
||||
defaultCluster: false,
|
||||
status: ServerStatus.Offline,
|
||||
brokerCount: 1,
|
||||
onlinePartitionCount: 2,
|
||||
topicCount: 2,
|
||||
bytesInPerSec: 3.42,
|
||||
bytesOutPerSec: 4.14,
|
||||
};
|
||||
|
||||
export const clustersPayload: Cluster[] = [
|
||||
onlineClusterPayload,
|
||||
offlineClusterPayload,
|
||||
];
|
|
@ -0,0 +1,15 @@
|
|||
import { fetchClusterListAction } from 'redux/actions';
|
||||
import reducer from 'redux/reducers/clusters/reducer';
|
||||
import { clustersPayload } from './fixtures';
|
||||
|
||||
describe('Clusters reducer', () => {
|
||||
it('returns the initial state', () => {
|
||||
expect(reducer(undefined, fetchClusterListAction.request())).toEqual([]);
|
||||
});
|
||||
|
||||
it('reacts on GET_CLUSTERS__SUCCESS and returns payload', () => {
|
||||
expect(
|
||||
reducer(undefined, fetchClusterListAction.success(clustersPayload))
|
||||
).toEqual(clustersPayload);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,58 @@
|
|||
import { fetchClusterListAction } from 'redux/actions';
|
||||
import configureStore from 'redux/store/configureStore';
|
||||
import * as selectors from '../selectors';
|
||||
import {
|
||||
clustersPayload,
|
||||
offlineClusterPayload,
|
||||
onlineClusterPayload,
|
||||
} from './fixtures';
|
||||
|
||||
const store = configureStore();
|
||||
|
||||
describe('Clusters selectors', () => {
|
||||
describe('Initial State', () => {
|
||||
it('returns fetch status', () => {
|
||||
expect(selectors.getIsClusterListFetched(store.getState())).toBeFalsy();
|
||||
});
|
||||
|
||||
it('returns cluster list', () => {
|
||||
expect(selectors.getClusterList(store.getState())).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns online cluster list', () => {
|
||||
expect(selectors.getOnlineClusters(store.getState())).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns offline cluster list', () => {
|
||||
expect(selectors.getOfflineClusters(store.getState())).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('state', () => {
|
||||
beforeAll(() => {
|
||||
store.dispatch(fetchClusterListAction.success(clustersPayload));
|
||||
});
|
||||
|
||||
it('returns fetch status', () => {
|
||||
expect(selectors.getIsClusterListFetched(store.getState())).toBeTruthy();
|
||||
});
|
||||
|
||||
it('returns cluster list', () => {
|
||||
expect(selectors.getClusterList(store.getState())).toEqual(
|
||||
clustersPayload
|
||||
);
|
||||
});
|
||||
|
||||
it('returns online cluster list', () => {
|
||||
expect(selectors.getOnlineClusters(store.getState())).toEqual([
|
||||
onlineClusterPayload,
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns offline cluster list', () => {
|
||||
expect(selectors.getOfflineClusters(store.getState())).toEqual([
|
||||
offlineClusterPayload,
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,7 +2,7 @@ import { createStore, applyMiddleware, compose } from 'redux';
|
|||
import thunk, { ThunkMiddleware } from 'redux-thunk';
|
||||
import { RootState } from 'redux/interfaces';
|
||||
import { Action } from 'typesafe-actions';
|
||||
import rootReducer from '../../reducers';
|
||||
import rootReducer from 'redux/reducers';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { createStore, applyMiddleware } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
import rootReducer from '../../reducers';
|
||||
import rootReducer from 'redux/reducers';
|
||||
|
||||
export default () => {
|
||||
const middlewares = [thunk];
|
||||
|
|
Loading…
Add table
Reference in a new issue