From 41ed27751ef92ee8be1ec4ff7d5ad1f490028037 Mon Sep 17 00:00:00 2001 From: crockwave Date: Wed, 8 Jul 2020 19:22:49 -0500 Subject: [PATCH] debugged reducer tests --- .../reducers/__tests__/list_adder-test.js | 48 +++---- .../reducers/__tests__/list_editor-test.js | 128 ++++++++++++++++++ 2 files changed, 152 insertions(+), 24 deletions(-) diff --git a/app/soapbox/reducers/__tests__/list_adder-test.js b/app/soapbox/reducers/__tests__/list_adder-test.js index b88423957..9c34cee17 100644 --- a/app/soapbox/reducers/__tests__/list_adder-test.js +++ b/app/soapbox/reducers/__tests__/list_adder-test.js @@ -1,6 +1,6 @@ import reducer from '../list_adder'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; -import * as actions from '../list_adder'; +import * as actions from 'soapbox/actions/lists'; describe('list_adder reducer', () => { it('should return the initial state', () => { @@ -39,29 +39,29 @@ describe('list_adder reducer', () => { })); }); - // it('should handle LIST_ADDER_LISTS_FETCH_REQUEST', () => { - // const state = ImmutableMap({ - // accountId: null, - // - // lists: ImmutableMap({ - // items: ImmutableList(), - // loaded: false, - // isLoading: false, - // }), - // }); - // const action = { - // type: actions.LIST_ADDER_LISTS_FETCH_REQUEST, - // }; - // expect(reducer(state, action)).toEqual(ImmutableMap({ - // accountId: null, - // - // lists: ImmutableMap({ - // items: ImmutableList(), - // loaded: false, - // isLoading: true, - // }), - // })); - // }); + it('should handle LIST_ADDER_LISTS_FETCH_REQUEST', () => { + const state = ImmutableMap({ + accountId: null, + + lists: ImmutableMap({ + items: ImmutableList(), + loaded: false, + isLoading: false, + }), + }); + const action = { + type: actions.LIST_ADDER_LISTS_FETCH_REQUEST, + }; + expect(reducer(state, action)).toEqual(ImmutableMap({ + accountId: null, + + lists: ImmutableMap({ + items: ImmutableList(), + loaded: false, + isLoading: true, + }), + })); + }); it('should handle LIST_ADDER_LISTS_FETCH_FAIL', () => { const state = ImmutableMap({ diff --git a/app/soapbox/reducers/__tests__/list_editor-test.js b/app/soapbox/reducers/__tests__/list_editor-test.js index 46dc79c3f..356bc8d7e 100644 --- a/app/soapbox/reducers/__tests__/list_editor-test.js +++ b/app/soapbox/reducers/__tests__/list_editor-test.js @@ -1,5 +1,6 @@ import reducer from '../list_editor'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; +import * as actions from 'soapbox/actions/lists'; describe('list_editor reducer', () => { it('should return the initial state', () => { @@ -21,4 +22,131 @@ describe('list_editor reducer', () => { }), })); }); + + it('should handle LIST_EDITOR_RESET', () => { + const state = ImmutableMap({ + listId: null, + isSubmitting: false, + isChanged: false, + title: '', + + accounts: ImmutableMap({ + items: ImmutableList(), + loaded: false, + isLoading: false, + }), + + suggestions: ImmutableMap({ + value: '', + items: ImmutableList(), + }), + }); + const action = { + type: actions.LIST_EDITOR_RESET, + }; + expect(reducer(state, action)).toEqual(ImmutableMap({ + listId: null, + isSubmitting: false, + isChanged: false, + title: '', + + accounts: ImmutableMap({ + items: ImmutableList(), + loaded: false, + isLoading: false, + }), + + suggestions: ImmutableMap({ + value: '', + items: ImmutableList(), + }), + })); + }); + + it('should handle LIST_EDITOR_SETUP', () => { + const state = ImmutableMap({ + listId: null, + isSubmitting: false, + isChanged: false, + title: '', + + accounts: ImmutableMap({ + items: ImmutableList(), + loaded: false, + isLoading: false, + }), + + suggestions: ImmutableMap({ + value: '', + items: ImmutableList(), + }), + }); + const action = { + type: actions.LIST_EDITOR_SETUP, + list: ImmutableMap({ + id: '22', + title: 'list 1', + }), + }; + expect(reducer(state, action)).toEqual(ImmutableMap({ + listId: '22', + isSubmitting: false, + isChanged: false, + title: 'list 1', + + accounts: ImmutableMap({ + items: ImmutableList(), + loaded: false, + isLoading: false, + }), + + suggestions: ImmutableMap({ + value: '', + items: ImmutableList(), + }), + })); + }); + + it('should handle LIST_EDITOR_TITLE_CHANGE', () => { + const state = ImmutableMap({ + title: 'list 1', + isChanged: false, + }); + const action = { + type: actions.LIST_EDITOR_TITLE_CHANGE, + value: 'list 1 edited', + }; + expect(reducer(state, action).toJS()).toMatchObject({ + isChanged: true, + title: 'list 1 edited', + }); + }); + + it('should handle LIST_UPDATE_REQUEST', () => { + const state = ImmutableMap({ + isSubmitting: false, + isChanged: true, + }); + const action = { + type: actions.LIST_UPDATE_REQUEST, + }; + expect(reducer(state, action).toJS()).toMatchObject({ + isSubmitting: true, + isChanged: false, + }); + }); + + it('should handle LIST_UPDATE_FAIL', () => { + debugger; + const state = ImmutableMap({ + isSubmitting: true, + }); + const action = { + type: actions.LIST_UPDATE_FAIL, + }; + expect(reducer(state, action).toJS()).toMatchObject({ + isSubmitting: false, + }); + }); + });