From 87df88b05a70af6c7f3e25fb22d78af033884029 Mon Sep 17 00:00:00 2001 From: Camille Villa <cvilla100@gmail.com> Date: Mon, 11 Mar 2019 11:44:54 -0700 Subject: [PATCH] Add tests for new action and reducer Co-Authored-By: Chris Beer <chris@cbeer.info> --- __tests__/src/actions/window.test.js | 8 ++++++-- __tests__/src/reducers/companionWindows.test.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/__tests__/src/actions/window.test.js b/__tests__/src/actions/window.test.js index ba983c88c..c144d7d2d 100644 --- a/__tests__/src/actions/window.test.js +++ b/__tests__/src/actions/window.test.js @@ -15,20 +15,24 @@ describe('window actions', () => { id: 'helloworld', canvasIndex: 1, collectionIndex: 0, - companionWindowIds: [], manifestId: null, maximized: false, rangeId: null, thumbnailNavigationPosition: 'bottom', x: 2700, y: 2700, + sideBarPanel: 'info', width: 400, height: 400, rotation: null, view: 'single', }, + companionWindows: [{ position: 'left', content: 'info' }], }; - expect(actions.addWindow(options)).toEqual(expectedAction); + const action = actions.addWindow(options); + expect(action).toMatchObject(expectedAction); + expect(action.window.companionWindowIds.length).toEqual(1); + expect(action.window.companionWindowIds[0]).toEqual(action.companionWindows[0].id); }); }); diff --git a/__tests__/src/reducers/companionWindows.test.js b/__tests__/src/reducers/companionWindows.test.js index 687758339..9f33e9ecf 100644 --- a/__tests__/src/reducers/companionWindows.test.js +++ b/__tests__/src/reducers/companionWindows.test.js @@ -20,6 +20,22 @@ describe('companionWindowsReducer', () => { }); }); + describe('ADD_WINDOW', () => { + it('adds default companion window(s)', () => { + const action = { + type: ActionTypes.ADD_WINDOW, + companionWindows: [{ id: 'banana', position: 'left', content: 'info' }, { id: 'Banane', position: 'right', content: 'canvas_navigation' }], + }; + const beforeState = {}; + const expectedState = { + banana: { id: 'banana', position: 'left', content: 'info' }, + Banane: { id: 'Banane', position: 'right', content: 'canvas_navigation' }, + }; + expect(companionWindowsReducer(beforeState, action)).toEqual(expectedState); + }); + }); + + describe('UPDATE_COMPANION_WINDOW', () => { it('updates an existing companion window', () => { const action = { -- GitLab