Skip to content

Commit 2560e73

Browse files
kyarorucallmephilip
authored andcommitted
fix ''should not push route with duplicated key" issue (#7)
* fix ''should not push route with duplicated key" issue * added test spec for the fix "should not push route with duplicated key"
1 parent e974a57 commit 2560e73

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/reducers/card-stack.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export function cardStackReducer(initialState) {
2929

3030
switch (action.type) {
3131
case PUSH_ROUTE:
32+
if (state.routes[state.index].key === (action.payload && action.payload.route.key)) return state;
3233
return StateUtils.push(state, action.payload.route);
3334
case POP_ROUTE:
3435
return StateUtils.pop(state);

test/unit/reducers.js

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const cardStackInitialState = {
2121
}]
2222
};
2323

24+
const repeatedRoute = {
25+
key: 'route-1',
26+
title: 'Route 1'
27+
};
28+
2429
const tabInitialState = {
2530
key: 'ta-key',
2631
index: 0,
@@ -151,6 +156,14 @@ describe('reducers', () => {
151156
expect(returnValue).to.equal('StateUtils.push');
152157
});
153158

159+
it('does not call RN\'s StateUtils.push when pushRoute action has payload.key same with current route state.key and returns current nav state', () => {
160+
const action = pushRoute({ key: 'route' }, repeatedRoute.key);
161+
162+
const returnValue = reducer(cardStackInitialState, action);
163+
expect(pushSpy.callCount).to.equal(0);
164+
expect(returnValue).to.equal(cardStackInitialState);
165+
});
166+
154167
it('does not call RN\'s StateUtils.push when pushRoute action has payload.key different from state.key and returns current nav state', () => {
155168
const action = pushRoute({ key: 'route' }, 'nav');
156169

0 commit comments

Comments
 (0)