From 457bc36d7f83ef2fa5f461517df482d12f613797 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 9 May 2017 19:10:48 +0200 Subject: [PATCH] web: clear mock store actions after each test --- web/src/js/__tests__/ducks/ui/keyboardSpec.js | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/web/src/js/__tests__/ducks/ui/keyboardSpec.js b/web/src/js/__tests__/ducks/ui/keyboardSpec.js index 126197744..500733cb6 100644 --- a/web/src/js/__tests__/ducks/ui/keyboardSpec.js +++ b/web/src/js/__tests__/ducks/ui/keyboardSpec.js @@ -23,65 +23,74 @@ describe('onKeyDown', () => { return onKeyDown({ keyCode, shiftKey, ctrlKey, preventDefault: jest.fn() }) } + afterEach(() => { + store.clearActions() + fetchApi.mockClear() + }); + it('should handle cursor up', () => { store.getState().flows = reduceFlows(flows, flowsActions.select(2)) store.dispatch(createKeyEvent(Key.K)) expect(store.getActions()).toEqual([{ flowIds: [1], type: flowsActions.SELECT }]) + store.clearActions() store.dispatch(createKeyEvent(Key.UP)) - expect(store.getActions().pop()).toEqual({ flowIds: [1], type: flowsActions.SELECT }) + expect(store.getActions()).toEqual([{ flowIds: [1], type: flowsActions.SELECT }]) }) it('should handle cursor down', () => { store.dispatch(createKeyEvent(Key.J)) - expect(store.getActions().pop()).toEqual({ flowIds: [3], type: flowsActions.SELECT }) + expect(store.getActions()).toEqual([{ flowIds: [3], type: flowsActions.SELECT }]) + store.clearActions() store.dispatch(createKeyEvent(Key.DOWN)) - expect(store.getActions().pop()).toEqual({ flowIds: [3], type: flowsActions.SELECT }) + expect(store.getActions()).toEqual([{ flowIds: [3], type: flowsActions.SELECT }]) }) it('should handle page down', () => { store.dispatch(createKeyEvent(Key.SPACE)) - expect(store.getActions().pop()).toEqual({ flowIds: [12], type: flowsActions.SELECT }) + expect(store.getActions()).toEqual([{ flowIds: [12], type: flowsActions.SELECT }]) store.getState().flows = reduceFlows(flows, flowsActions.select(1)) + store.clearActions() store.dispatch(createKeyEvent(Key.PAGE_DOWN)) - expect(store.getActions().pop()).toEqual({ flowIds: [11], type: flowsActions.SELECT }) + expect(store.getActions()).toEqual([{ flowIds: [11], type: flowsActions.SELECT }]) }) it('should handle page up', () => { store.getState().flows = reduceFlows(flows, flowsActions.select(11)) store.dispatch(createKeyEvent(Key.PAGE_UP)) - expect(store.getActions().pop()).toEqual({ flowIds: [1], type: flowsActions.SELECT }) + expect(store.getActions()).toEqual([{ flowIds: [1], type: flowsActions.SELECT }]) }) it('should handle select first', () => { store.dispatch(createKeyEvent(Key.HOME)) - expect(store.getActions().pop()).toEqual({ flowIds: [1], type: flowsActions.SELECT }) + expect(store.getActions()).toEqual([{ flowIds: [1], type: flowsActions.SELECT }]) }) it('should handle select last', () => { store.getState().flows = reduceFlows(flows, flowsActions.select(1)) store.dispatch(createKeyEvent(Key.END)) - expect(store.getActions().pop()).toEqual({ flowIds: [12], type: flowsActions.SELECT }) + expect(store.getActions()).toEqual([{ flowIds: [12], type: flowsActions.SELECT }]) }) it('should handle deselect', () => { store.dispatch(createKeyEvent(Key.ESC)) - expect(store.getActions().pop()).toEqual({ flowIds: [], type: flowsActions.SELECT }) + expect(store.getActions()).toEqual([{ flowIds: [], type: flowsActions.SELECT }]) }) it('should handle switch to left tab', () => { store.dispatch(createKeyEvent(Key.LEFT)) - expect(store.getActions().pop()).toEqual({ tab: 'details', type: UIActions.SET_TAB }) + expect(store.getActions()).toEqual([{ tab: 'details', type: UIActions.SET_TAB }]) }) it('should handle switch to right tab', () => { store.dispatch(createKeyEvent(Key.TAB)) - expect(store.getActions().pop()).toEqual({ tab: 'response', type: UIActions.SET_TAB }) + expect(store.getActions()).toEqual([{ tab: 'response', type: UIActions.SET_TAB }]) + store.clearActions() store.dispatch(createKeyEvent(Key.RIGHT)) - expect(store.getActions().pop()).toEqual({ tab: 'response', type: UIActions.SET_TAB }) + expect(store.getActions()).toEqual([{ tab: 'response', type: UIActions.SET_TAB }]) }) it('should handle delete action', () => { @@ -131,7 +140,6 @@ describe('onKeyDown', () => { }) it('should stop on some action with no flow is selected', () => { - fetchApi.mockClear() store.getState().flows = reduceFlows(undefined, {}) store.dispatch(createKeyEvent(Key.LEFT)) store.dispatch(createKeyEvent(Key.TAB))