Merge pull request #3294 from benjiwheeler/join-flow-unit-test-which

add tests for navigation reducer
This commit is contained in:
Benjamin Wheeler 2019-08-27 11:42:50 -04:00 committed by GitHub
commit de5297bf9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,241 @@
const {
handleToggleAccountNav,
navigationReducer,
setAccountNavOpen,
setCanceledDeletionOpen,
setLoginError,
setLoginOpen,
setRegistrationOpen,
setSearchTerm,
toggleLoginOpen
} = require('../../../src/redux/navigation');
describe('unit test lib/validate.js', () => {
test('initialState', () => {
let defaultState;
/* navigationReducer(state, action) */
expect(navigationReducer(defaultState, {type: 'anything'})).toBeDefined();
expect(navigationReducer(defaultState, {type: 'anything'}).accountNavOpen).toBe(false);
expect(navigationReducer(defaultState, {type: 'anything'}).canceledDeletionOpen).toBe(false);
expect(navigationReducer(defaultState, {type: 'anything'}).loginError).toBe(null);
expect(navigationReducer(defaultState, {type: 'anything'}).loginOpen).toBe(false);
expect(navigationReducer(defaultState, {type: 'anything'}).registrationOpen).toBe(false);
expect(navigationReducer(defaultState, {type: 'anything'}).searchTerm).toBe('');
expect(navigationReducer(defaultState, {type: 'anything'}).useScratch3Registration).toBe(false);
});
// handleToggleAccountNav
test('handleToggleAccountNav can toggle on', () => {
const initialState = {
accountNavOpen: false
};
const action = handleToggleAccountNav();
const resultState = navigationReducer(initialState, action);
expect(resultState.accountNavOpen).toBe(true);
});
test('handleToggleAccountNav can toggle off', () => {
const initialState = {
accountNavOpen: true
};
const action = handleToggleAccountNav();
const resultState = navigationReducer(initialState, action);
expect(resultState.accountNavOpen).toBe(false);
});
// setAccountNavOpen
test('setAccountNavOpen opens account nav, if it is closed', () => {
const initialState = {
accountNavOpen: false
};
const action = setAccountNavOpen(true);
const resultState = navigationReducer(initialState, action);
expect(resultState.accountNavOpen).toBe(true);
});
test('setAccountNavOpen leaves account nav open, if it is already open', () => {
const initialState = {
accountNavOpen: true
};
const action = setAccountNavOpen(true);
const resultState = navigationReducer(initialState, action);
expect(resultState.accountNavOpen).toBe(true);
});
test('setAccountNavOpen closes account nav, if it is open', () => {
const initialState = {
accountNavOpen: true
};
const action = setAccountNavOpen(false);
const resultState = navigationReducer(initialState, action);
expect(resultState.accountNavOpen).toBe(false);
});
test('setAccountNavOpen leaves account nav closed, if it is already closed', () => {
const initialState = {
accountNavOpen: false
};
const action = setAccountNavOpen(false);
const resultState = navigationReducer(initialState, action);
expect(resultState.accountNavOpen).toBe(false);
});
// setCanceledDeletionOpen
test('setCanceledDeletionOpen opens account nav, if it is closed', () => {
const initialState = {
canceledDeletionOpen: false
};
const action = setCanceledDeletionOpen(true);
const resultState = navigationReducer(initialState, action);
expect(resultState.canceledDeletionOpen).toBe(true);
});
test('setCanceledDeletionOpen leaves account nav open, if it is already open', () => {
const initialState = {
canceledDeletionOpen: true
};
const action = setCanceledDeletionOpen(true);
const resultState = navigationReducer(initialState, action);
expect(resultState.canceledDeletionOpen).toBe(true);
});
test('setCanceledDeletionOpen closes account nav, if it is open', () => {
const initialState = {
canceledDeletionOpen: true
};
const action = setCanceledDeletionOpen(false);
const resultState = navigationReducer(initialState, action);
expect(resultState.canceledDeletionOpen).toBe(false);
});
test('setCanceledDeletionOpen leaves account nav closed, if it is already closed', () => {
const initialState = {
canceledDeletionOpen: false
};
const action = setCanceledDeletionOpen(false);
const resultState = navigationReducer(initialState, action);
expect(resultState.canceledDeletionOpen).toBe(false);
});
// setLoginError
test('setLoginError sets login error', () => {
const initialState = {
loginError: null
};
const action = setLoginError('Danger! Error! Mistake!');
const resultState = navigationReducer(initialState, action);
expect(resultState.loginError).toBe('Danger! Error! Mistake!');
});
// setLoginOpen
test('setLoginOpen opens account nav, if it is closed', () => {
const initialState = {
loginOpen: false
};
const action = setLoginOpen(true);
const resultState = navigationReducer(initialState, action);
expect(resultState.loginOpen).toBe(true);
});
test('setLoginOpen leaves account nav open, if it is already open', () => {
const initialState = {
loginOpen: true
};
const action = setLoginOpen(true);
const resultState = navigationReducer(initialState, action);
expect(resultState.loginOpen).toBe(true);
});
test('setLoginOpen closes account nav, if it is open', () => {
const initialState = {
loginOpen: true
};
const action = setLoginOpen(false);
const resultState = navigationReducer(initialState, action);
expect(resultState.loginOpen).toBe(false);
});
test('setLoginOpen leaves account nav closed, if it is already closed', () => {
const initialState = {
loginOpen: false
};
const action = setLoginOpen(false);
const resultState = navigationReducer(initialState, action);
expect(resultState.loginOpen).toBe(false);
});
// setRegistrationOpen
test('setRegistrationOpen opens account nav, if it is closed', () => {
const initialState = {
registrationOpen: false
};
const action = setRegistrationOpen(true);
const resultState = navigationReducer(initialState, action);
expect(resultState.registrationOpen).toBe(true);
});
test('setRegistrationOpen leaves account nav open, if it is already open', () => {
const initialState = {
registrationOpen: true
};
const action = setRegistrationOpen(true);
const resultState = navigationReducer(initialState, action);
expect(resultState.registrationOpen).toBe(true);
});
test('setRegistrationOpen closes account nav, if it is open', () => {
const initialState = {
registrationOpen: true
};
const action = setRegistrationOpen(false);
const resultState = navigationReducer(initialState, action);
expect(resultState.registrationOpen).toBe(false);
});
test('setRegistrationOpen leaves account nav closed, if it is already closed', () => {
const initialState = {
registrationOpen: false
};
const action = setRegistrationOpen(false);
const resultState = navigationReducer(initialState, action);
expect(resultState.registrationOpen).toBe(false);
});
// setSearchTerm
test('setSearchTerm sets search term', () => {
const initialState = {
searchTerm: null
};
const action = setSearchTerm('outer space');
const resultState = navigationReducer(initialState, action);
expect(resultState.searchTerm).toBe('outer space');
});
// toggleLoginOpen
test('toggleLoginOpen can toggle on', () => {
const initialState = {
loginOpen: false
};
const action = toggleLoginOpen();
const resultState = navigationReducer(initialState, action);
expect(resultState.loginOpen).toBe(true);
});
test('toggleLoginOpen can toggle off', () => {
const initialState = {
loginOpen: true
};
const action = toggleLoginOpen();
const resultState = navigationReducer(initialState, action);
expect(resultState.loginOpen).toBe(false);
});
});