From 50265fe843ca57e42928b84e39b421e3f62762a2 Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Mon, 6 Jan 2020 15:10:51 -0500 Subject: [PATCH] added tests for project loading states --- .../reducers/project-state-reducer.test.js | 84 ++++++++++++++----- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/test/unit/reducers/project-state-reducer.test.js b/test/unit/reducers/project-state-reducer.test.js index 2683c5beec1..6938085a345 100644 --- a/test/unit/reducers/project-state-reducer.test.js +++ b/test/unit/reducers/project-state-reducer.test.js @@ -92,16 +92,49 @@ test('onFetchedProjectData new loads project data into vm', () => { expect(resultState.projectData).toBe('1010101'); }); -test('onLoadedProject upload, with canSave false, shows without id', () => { +// onLoadedProject: LOADING_VM_WITH_ID + +test('onLoadedProject (LOADING_VM_WITH_ID, true, true) shows with id', () => { const initialState = { - loadingState: LoadingState.LOADING_VM_FILE_UPLOAD + loadingState: LoadingState.LOADING_VM_WITH_ID }; - const action = onLoadedProject(initialState.loadingState, false, true); + const action = onLoadedProject(initialState.loadingState, true, true); + const resultState = projectStateReducer(initialState, action); + expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID); +}); + +test('onLoadedProject (LOADING_VM_WITH_ID, false, true) shows with id', () => { + const initialState = { + loadingState: LoadingState.LOADING_VM_WITH_ID + }; + const action = onLoadedProject(initialState.loadingState, true, true); + const resultState = projectStateReducer(initialState, action); + expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID); +}); + +test('onLoadedProject (LOADING_VM_WITH_ID, false, false), with project id, shows with id', () => { + const initialState = { + loadingState: LoadingState.LOADING_VM_WITH_ID, + projectId: '12345' + }; + const action = onLoadedProject(initialState.loadingState, false, false); + const resultState = projectStateReducer(initialState, action); + expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID); +}); + +test('onLoadedProject (LOADING_VM_WITH_ID, false, false), with no project id, shows without id', () => { + const initialState = { + loadingState: LoadingState.LOADING_VM_WITH_ID, + projectId: null + }; + const action = onLoadedProject(initialState.loadingState, false, false); const resultState = projectStateReducer(initialState, action); expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID); }); -test('onLoadedProject upload, with canSave true, prepares to save', () => { +// onLoadedProject: LOADING_VM_FILE_UPLOAD + +test('onLoadedProject(LOADING_VM_FILE_UPLOAD, true, true) prepares to save', () => { const initialState = { loadingState: LoadingState.LOADING_VM_FILE_UPLOAD }; @@ -110,25 +143,38 @@ test('onLoadedProject upload, with canSave true, prepares to save', () => { expect(resultState.loadingState).toBe(LoadingState.AUTO_UPDATING); }); -test('onLoadedProject with id shows with id', () => { +test('onLoadedProject (LOADING_VM_FILE_UPLOAD, false, true) shows without id', () => { const initialState = { - loadingState: LoadingState.LOADING_VM_WITH_ID + loadingState: LoadingState.LOADING_VM_FILE_UPLOAD }; - const action = onLoadedProject(initialState.loadingState, true, true); + const action = onLoadedProject(initialState.loadingState, false, true); + const resultState = projectStateReducer(initialState, action); + expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID); +}); + +test('onLoadedProject (LOADING_VM_FILE_UPLOAD, false, false), with project id, shows with id', () => { + const initialState = { + loadingState: LoadingState.LOADING_VM_FILE_UPLOAD, + projectId: '12345' + }; + const action = onLoadedProject(initialState.loadingState, false, false); const resultState = projectStateReducer(initialState, action); expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID); }); -test('onLoadedProject new shows without id', () => { +test('onLoadedProject (LOADING_VM_FILE_UPLOAD, false, false), with no project id, shows without id', () => { const initialState = { - loadingState: LoadingState.LOADING_VM_NEW_DEFAULT + loadingState: LoadingState.LOADING_VM_FILE_UPLOAD, + projectId: null }; - const action = onLoadedProject(initialState.loadingState, false, true); + const action = onLoadedProject(initialState.loadingState, false, false); const resultState = projectStateReducer(initialState, action); expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID); }); -test('onLoadedProject new, to save shows without id', () => { +// onLoadedProject: LOADING_VM_NEW_DEFAULT + +test('onLoadedProject (LOADING_VM_NEW_DEFAULT, true, true) shows without id', () => { const initialState = { loadingState: LoadingState.LOADING_VM_NEW_DEFAULT }; @@ -137,26 +183,26 @@ test('onLoadedProject new, to save shows without id', () => { expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID); }); -test('onLoadedProject with success false, no project id, shows without id', () => { +test('onLoadedProject (LOADING_VM_NEW_DEFAULT, false, true) shows without id', () => { const initialState = { - loadingState: LoadingState.LOADING_VM_WITH_ID, - projectId: null + loadingState: LoadingState.LOADING_VM_NEW_DEFAULT }; - const action = onLoadedProject(initialState.loadingState, false, false); + const action = onLoadedProject(initialState.loadingState, false, true); const resultState = projectStateReducer(initialState, action); expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITHOUT_ID); }); -test('onLoadedProject with success false, valid project id, shows with id', () => { +test('onLoadedProject (LOADING_VM_NEW_DEFAULT, false, false) shows error', () => { const initialState = { - loadingState: LoadingState.LOADING_VM_WITH_ID, - projectId: '12345' + loadingState: LoadingState.LOADING_VM_NEW_DEFAULT }; const action = onLoadedProject(initialState.loadingState, false, false); const resultState = projectStateReducer(initialState, action); - expect(resultState.loadingState).toBe(LoadingState.SHOWING_WITH_ID); + expect(resultState.loadingState).toBe(LoadingState.ERROR); }); +// doneUpdatingProject + test('doneUpdatingProject with id shows with id', () => { const initialState = { loadingState: LoadingState.MANUAL_UPDATING