Skip to content

Commit

Permalink
added tests for project loading states
Browse files Browse the repository at this point in the history
  • Loading branch information
benjiwheeler committed Jan 6, 2020
1 parent 461877b commit 50265fe
Showing 1 changed file with 65 additions and 19 deletions.
84 changes: 65 additions & 19 deletions test/unit/reducers/project-state-reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -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
};
Expand All @@ -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
Expand Down

0 comments on commit 50265fe

Please sign in to comment.