Skip to content

Commit a4fd5de

Browse files
committed
unit test route reducer
1 parent 54d46e5 commit a4fd5de

File tree

5 files changed

+31
-49
lines changed

5 files changed

+31
-49
lines changed

src/modules/route/MenuLink/index.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/modules/route/RouteButton/index.tsx

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/modules/route/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import {ROUTE_SET} from './types';
22

3+
/**
4+
* Sets a route
5+
* @param {string} route route name
6+
* @returns thunk
7+
*/
38
export function routeSet(route: string): Redux.ThunkAction<any, any, {}> {
49
return (dispatch, getState) => {
510
if (getState().route !== route) {

src/modules/route/reducer.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import route from './reducer';
2+
3+
describe('route reducer', () => {
4+
5+
it('should set the initial route to "start"', () => {
6+
const action = { type: 'unknown'};
7+
expect(route(undefined, action)).toBe('start');
8+
});
9+
10+
it('should trigger route changes on ROUTE_SET', () => {
11+
const action = { type: 'ROUTE_SET', payload: { route: 'next' } };
12+
expect(route(undefined, action)).toBe('next');
13+
});
14+
15+
it('maintains existing route if no change', () => {
16+
const action = { type: 'unknown'};
17+
expect(route('current', action)).toBe('current');
18+
});
19+
20+
});

src/modules/route/reducer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import {ROUTE_SET} from './types';
22

33
const _route = 'start';
44

5+
/**
6+
* Sets the route name
7+
* @param {} route=_route route name
8+
* @param {Action} action redux action
9+
* @returns string route name
10+
*/
511
export default function routeReducer(
612
route = _route, action: Action
713
): string {

0 commit comments

Comments
 (0)