diff --git a/src/Reducer.js b/src/Reducer.js index 05d4f3269..f388c3883 100644 --- a/src/Reducer.js +++ b/src/Reducer.js @@ -230,7 +230,7 @@ function inject(state, action, props, scenes) { props, scenes, state.index, - action, + { ...action, parentIndex: state.children[ind].parentIndex }, ); return { ...state, index: ind }; diff --git a/test/Reducer.test.js b/test/Reducer.test.js index 9566e3a36..e5d9665e5 100644 --- a/test/Reducer.test.js +++ b/test/Reducer.test.js @@ -18,6 +18,7 @@ export default function getCurrent(state) { const id = 0; const guid = () => id + 1; const noop = () => {}; +const component = React.Component; const scenesData = ( { beforeEach(() => { const scene = ( - + - - + + + + + + + + + + + + ); @@ -148,9 +159,28 @@ describe('handling actions', () => { it('switches to a correct tab on JUMP', () => { Actions.main(); Actions.hello(); - expect(current.key).to.eq('hello_0_hello_'); }); + + it('maintains scene parentIndex when switching tabs', () => { + Actions.world(); + expect(current.key).to.eq('world_0_world_content'); + + Actions.maps({ type: 'push' }); + expect(current.key).to.eq('maps_0_maps_content'); + + Actions.map_tabs(); + expect(current.key).to.eq('map_tabs_0_map_tab_1_'); + expect(current.parentIndex).to.eq(1); + + Actions.map_tab_2(); + expect(current.key).to.eq('map_tab_2_0_map_tab_2_'); + expect(current.parentIndex).to.eq(1); + + Actions.map_tab_3(); + expect(current.key).to.eq('map_tab_3_0_map_tab_3_'); + expect(current.parentIndex).to.eq(1); + }); }); describe('passing props from actions', () => {