chore: add tests and migrate RootEnum
This commit is contained in:
parent
16e04c7232
commit
701361a686
|
@ -1,6 +1,6 @@
|
||||||
import { Action } from 'redux';
|
import { Action } from 'redux';
|
||||||
|
|
||||||
import { TRootEnum } from '../definitions';
|
import { RootEnum } from '../definitions';
|
||||||
import { APP } from './actionsTypes';
|
import { APP } from './actionsTypes';
|
||||||
|
|
||||||
export const ROOT_OUTSIDE = 'outside';
|
export const ROOT_OUTSIDE = 'outside';
|
||||||
|
@ -9,7 +9,7 @@ export const ROOT_LOADING = 'loading';
|
||||||
export const ROOT_SET_USERNAME = 'setUsername';
|
export const ROOT_SET_USERNAME = 'setUsername';
|
||||||
|
|
||||||
interface IAppStart extends Action {
|
interface IAppStart extends Action {
|
||||||
root: TRootEnum;
|
root: RootEnum;
|
||||||
text?: string;
|
text?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ interface ISetMasterDetail extends Action {
|
||||||
|
|
||||||
export type TActionApp = IAppStart & ISetMasterDetail;
|
export type TActionApp = IAppStart & ISetMasterDetail;
|
||||||
|
|
||||||
export function appStart({ root, ...args }: { root: TRootEnum }): IAppStart {
|
export function appStart({ root, ...args }: { root: RootEnum }): IAppStart {
|
||||||
return {
|
return {
|
||||||
type: APP.START,
|
type: APP.START,
|
||||||
root,
|
root,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export type TRootEnum = {
|
export enum RootEnum {
|
||||||
ROOT_OUTSIDE: 'outside';
|
ROOT_OUTSIDE = 'outside',
|
||||||
ROOT_INSIDE: 'inside';
|
ROOT_INSIDE = 'inside',
|
||||||
ROOT_LOADING: 'loading';
|
ROOT_LOADING = 'loading',
|
||||||
ROOT_SET_USERNAME: 'setUsername';
|
ROOT_SET_USERNAME = 'setUsername'
|
||||||
};
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { appStart, appInit, setMasterDetail } from '../actions/app';
|
||||||
|
import { initialState } from './app';
|
||||||
|
import { mockedStore } from './mockedStore';
|
||||||
|
import { RootEnum } from '../definitions';
|
||||||
|
import { APP_STATE } from '../actions/actionsTypes';
|
||||||
|
|
||||||
|
describe('test reducer', () => {
|
||||||
|
it('should return initial state', () => {
|
||||||
|
const state = mockedStore.getState().app;
|
||||||
|
expect(state).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return root state after dispatch appStart action', () => {
|
||||||
|
mockedStore.dispatch(appStart({ root: RootEnum.ROOT_INSIDE }));
|
||||||
|
const { root } = mockedStore.getState().app;
|
||||||
|
expect(root).toEqual(RootEnum.ROOT_INSIDE);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return ready state after dispatch appInit action', () => {
|
||||||
|
mockedStore.dispatch(appInit());
|
||||||
|
const { ready } = mockedStore.getState().app;
|
||||||
|
expect(ready).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return ready state after dispatch setMasterDetail action', () => {
|
||||||
|
mockedStore.dispatch(setMasterDetail(false));
|
||||||
|
const { isMasterDetail } = mockedStore.getState().app;
|
||||||
|
expect(isMasterDetail).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct state after app go to foreground', () => {
|
||||||
|
mockedStore.dispatch({ type: APP_STATE.FOREGROUND });
|
||||||
|
const { foreground, background } = mockedStore.getState().app;
|
||||||
|
expect(foreground).toEqual(true);
|
||||||
|
expect(background).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct state after app go to background', () => {
|
||||||
|
mockedStore.dispatch({ type: APP_STATE.BACKGROUND });
|
||||||
|
const { foreground, background } = mockedStore.getState().app;
|
||||||
|
expect(foreground).toEqual(false);
|
||||||
|
expect(background).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,9 +1,9 @@
|
||||||
import { TActionApp } from '../actions/app';
|
import { TActionApp } from '../actions/app';
|
||||||
import { TRootEnum } from '../definitions';
|
import { RootEnum } from '../definitions';
|
||||||
import { APP, APP_STATE } from '../actions/actionsTypes';
|
import { APP, APP_STATE } from '../actions/actionsTypes';
|
||||||
|
|
||||||
export interface IApp {
|
export interface IApp {
|
||||||
root?: TRootEnum;
|
root?: RootEnum;
|
||||||
isMasterDetail: boolean;
|
isMasterDetail: boolean;
|
||||||
text?: string;
|
text?: string;
|
||||||
ready: boolean;
|
ready: boolean;
|
||||||
|
@ -11,7 +11,7 @@ export interface IApp {
|
||||||
background: boolean;
|
background: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: IApp = {
|
export const initialState: IApp = {
|
||||||
root: undefined,
|
root: undefined,
|
||||||
isMasterDetail: false,
|
isMasterDetail: false,
|
||||||
text: undefined,
|
text: undefined,
|
||||||
|
|
Loading…
Reference in New Issue