From 98978ced203b17f5bceb495d19a2c52d9ebcef53 Mon Sep 17 00:00:00 2001 From: Conrad Chan Date: Thu, 8 Oct 2020 15:59:16 -0700 Subject: [PATCH] fix(creator): Reset creator store when toggleAnnotationModeAction --- src/store/creator/__tests__/reducer-test.ts | 21 +++++++++++++++++++++ src/store/creator/reducer.ts | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) 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), );