From b2f79bc61f751f72dc751c7541ccc4b0c248e6db Mon Sep 17 00:00:00 2001 From: echenley Date: Wed, 10 Feb 2016 11:36:35 -0600 Subject: [PATCH] add currentStateIndex test --- test/instrument.spec.js | 52 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/test/instrument.spec.js b/test/instrument.spec.js index 50bbac3d..59a4f789 100644 --- a/test/instrument.spec.js +++ b/test/instrument.spec.js @@ -335,7 +335,7 @@ describe('instrument', () => { expect(liftedStoreState.currentStateIndex).toBe(2); }); - it('should handle skipped actions', () => { + it('should remove skipped actions once committed', () => { configuredStore.dispatch({ type: 'INCREMENT' }); configuredLiftedStore.dispatch(ActionCreators.toggleAction(1)); configuredStore.dispatch({ type: 'INCREMENT' }); @@ -382,6 +382,56 @@ describe('instrument', () => { spy.restore(); }); + + it('should update currentStateIndex when auto-committing', () => { + let spy = spyOn(console, 'error'); + + configuredStore.dispatch({ type: 'INCREMENT' }); + configuredStore.dispatch({ type: 'INCREMENT' }); + + let liftedStoreState = configuredLiftedStore.getState(); + expect(liftedStoreState.currentStateIndex).toBe(2); + + configuredStore.dispatch({ type: 'INCREMENT' }); + + liftedStoreState = configuredLiftedStore.getState(); + let currentComputedState = liftedStoreState.computedStates[liftedStoreState.currentStateIndex]; + // currentStateIndex stays at 2 when an action is committed + expect(liftedStoreState.currentStateIndex).toBe(2); + expect(currentComputedState.state).toBe(3); + + configuredStore.replaceReducer(counterWithBug); + configuredStore.dispatch({ type: 'DECREMENT' }); + configuredStore.dispatch({ type: 'DECREMENT' }); + configuredStore.dispatch({ type: 'DECREMENT' }); + configuredStore.dispatch({ type: 'INCREMENT' }); + configuredStore.dispatch({ type: 'INCREMENT' }); + liftedStoreState = configuredLiftedStore.getState(); + currentComputedState = liftedStoreState.computedStates[liftedStoreState.currentStateIndex]; + // currentStateIndex continues to increment while non-committed action causes error + expect(liftedStoreState.currentStateIndex).toBe(5); + expect(currentComputedState.state).toBe(3); + expect(currentComputedState.error).toExist; + + configuredStore.replaceReducer(counterWithAnotherBug); + liftedStoreState = configuredLiftedStore.getState(); + currentComputedState = liftedStoreState.computedStates[liftedStoreState.currentStateIndex]; + // currentStateIndex adjusts correctly when multiple actions are committed + expect(liftedStoreState.currentStateIndex).toBe(2); + expect(currentComputedState.state).toBe(0); + expect(currentComputedState.error).toExist; + + configuredLiftedStore.dispatch(ActionCreators.jumpToState(0)); + configuredStore.replaceReducer(counter); + liftedStoreState = configuredLiftedStore.getState(); + // currentStateIndex stays at 0 as actions are committed + currentComputedState = liftedStoreState.computedStates[liftedStoreState.currentStateIndex]; + expect(liftedStoreState.currentStateIndex).toBe(0); + expect(currentComputedState.state).toBe(0); + expect(currentComputedState.error).toNotExist; + + spy.restore(); + }); }); describe('Import State', () => {