diff --git a/src/store/creator/__tests__/reducer-test.ts b/src/store/creator/__tests__/reducer-test.ts index 88ac72f87..245a6643e 100644 --- a/src/store/creator/__tests__/reducer-test.ts +++ b/src/store/creator/__tests__/reducer-test.ts @@ -10,6 +10,7 @@ import { setStagedAction, setStatusAction, } from '../actions'; +import { toggleAnnotationModeAction } from '../../common'; describe('store/creator/reducer', () => { describe('createAnnotationAction', () => { @@ -90,4 +91,24 @@ describe('store/creator/reducer', () => { expect(newState.cursor).toEqual(2); }); }); + + describe('toggleAnnotationModeAction', () => { + test('should reset the creator state', () => { + const newState = reducer( + { + ...state, + cursor: 1, + error: new Error('error'), + status: CreatorStatus.rejected, + }, + toggleAnnotationModeAction, + ); + + expect(newState.cursor).toEqual(0); + expect(newState.error).toEqual(null); + expect(newState.message).toEqual(''); + expect(newState.staged).toEqual(null); + expect(newState.status).toEqual(CreatorStatus.init); + }); + }); }); diff --git a/src/store/creator/reducer.ts b/src/store/creator/reducer.ts index abf5478ae..f7826d460 100644 --- a/src/store/creator/reducer.ts +++ b/src/store/creator/reducer.ts @@ -9,6 +9,7 @@ import { setStagedAction, setStatusAction, } from './actions'; +import { toggleAnnotationModeAction } from '../common'; export const initialState = { cursor: 0, @@ -48,5 +49,6 @@ export default createReducer(initialState, builder => }) .addCase(setCursorAction, (state, { payload }) => { state.cursor = payload; - }), + }) + .addCase(toggleAnnotationModeAction, () => initialState), );