diff --git a/src/actions/app/__tests__/index.test.js b/src/actions/app/__tests__/index.test.js index 9708fd5..5cfe04b 100644 --- a/src/actions/app/__tests__/index.test.js +++ b/src/actions/app/__tests__/index.test.js @@ -1,13 +1,28 @@ -import { actions, togglePreferred, togglePreferredMember } from '../' +import { + actions, + addNewPatterns, + resetEstimations, + togglePreferred, + togglePreferredMember, + toggleList, +} from '../' describe('actions/app', () => { const expectedActions = { + RESET_ESTIMATIONS: 'RESET_ESTIMATIONS', TOGGLE_PREFERRED: 'TOGGLE_PREFERRED', TOGGLE_PREFERRED_MEMBER: 'TOGGLE_PREFERRED_MEMBER', + TOGGLE_PREFERRED_LIST: 'TOGGLE_PREFERRED_LIST', + REGISTER_PATTERN: 'REGISTER_PATTERN', } test('returns the correct actions', () => { - expect(actions).toMatchObject(expectedActions) + expect(actions).toEqual(expectedActions) + }) + + test('addNewPatterns should return correct actions object', () => { + const pattern = ['pattern-1', 'pattern-2'] + expect(addNewPatterns(pattern)).toMatchObject({ type: actions.REGISTER_PATTERN, pattern }) }) test('togglePreferred should return correct actions object', () => { @@ -20,4 +35,14 @@ describe('actions/app', () => { memberId: 'mb1', }) }) + + test('toggleList should return correct actions object', () => { + const pattern = 'pattern-1' + expect(toggleList(pattern)).toMatchObject({ type: actions.TOGGLE_PREFERRED_LIST, pattern }) + }) + + test('resetEstimations should return correct actions object', () => { + const pattern = 'pattern-1' + expect(resetEstimations(pattern)).toMatchObject({ type: actions.RESET_ESTIMATIONS, pattern }) + }) }) diff --git a/src/actions/lists/index.js b/src/actions/lists/index.js index a4998dd..c78f709 100644 --- a/src/actions/lists/index.js +++ b/src/actions/lists/index.js @@ -23,7 +23,7 @@ const receiveLists = (boardId, data, error = null) => ({ const requestLists = (board, config) => async dispatch => { dispatch(startRequestList(board.id)) - // TODO: optimise + // TODO: optimise and write tests for history.* // eg. url: http://localhost:2222/#/?pattern=#sprint1,#sprint2,#sprint3 let newRegexSearch = [] let newRegexHash = [] diff --git a/src/reducers/app/__tests__/index.test.js b/src/reducers/app/__tests__/index.test.js index 29cce31..e0a09e2 100644 --- a/src/reducers/app/__tests__/index.test.js +++ b/src/reducers/app/__tests__/index.test.js @@ -3,21 +3,31 @@ import { reducer as app } from '../' describe('reducers/app', () => { const initialState = { - memberToggle: { - togglePreferred: false, - togglePreferredMember: null, - }, + config: { lists: ['/#upcoming/'] }, + listToggle: { toggleList: '/#upcoming/' }, + memberToggle: { togglePreferred: false, togglePreferredMember: null }, } test('returns the correct initial state', () => { const testState = app() - expect(testState).toMatchObject(initialState) + expect(testState).toEqual(initialState) + }) + + test('returns a correct new state when REGISTER_PATTERN is triggered with a pattern array', () => { + const action = { type: actions.REGISTER_PATTERN, pattern: [/pattern-1/, /pattern-2/] } + const result = app(initialState, action) + expect(result).toEqual({ + ...initialState, + config: { lists: ['/pattern-1/', '/pattern-2/'] }, + listToggle: { toggleList: '/pattern-1/' }, + }) }) test('returns a new togglePreferred state when TOGGLE_PREFERRED is triggered with toggle=true', () => { const action = { type: actions.TOGGLE_PREFERRED, toggle: true } const result = app(initialState, action) - expect(result).toMatchObject({ + expect(result).toEqual({ + ...initialState, memberToggle: { togglePreferred: true, togglePreferredMember: null, @@ -37,7 +47,10 @@ describe('reducers/app', () => { // dispatch action const action = { type: actions.TOGGLE_PREFERRED_MEMBER, memberId: togglePreferredMember } const result = app(initialState, action) - expect(result).toMatchObject(expectedState) + expect(result).toEqual({ + ...initialState, + ...expectedState, + }) }) test('resets togglePreferredMember when TOGGLE_PREFERRED is triggered with toggle=false', () => { @@ -49,11 +62,21 @@ describe('reducers/app', () => { // test new action const action = { type: actions.TOGGLE_PREFERRED, toggle: false } const result = app(initialState, action) - expect(result).toMatchObject({ + expect(result).toEqual({ + ...initialState, memberToggle: { togglePreferred: false, togglePreferredMember: null, }, }) }) + + test('toggles list when TOGGLE_PREFERRED_LIST is triggered', () => { + const action = { type: actions.TOGGLE_PREFERRED_LIST, pattern: /new-pattern/ } + const result = app(initialState, action) + expect(result).toEqual({ + ...initialState, + listToggle: { toggleList: /new-pattern/ }, + }) + }) })