From 75745d2c46fed14aca2521daee777988374779c5 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 13 May 2022 15:08:38 -0500 Subject: [PATCH] Clean up contexts test --- app/soapbox/jest/test-helpers.tsx | 2 +- .../reducers/__tests__/contexts-test.js | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/soapbox/jest/test-helpers.tsx b/app/soapbox/jest/test-helpers.tsx index 49bf08bf2..459049b52 100644 --- a/app/soapbox/jest/test-helpers.tsx +++ b/app/soapbox/jest/test-helpers.tsx @@ -18,7 +18,7 @@ const middlewares = [thunk]; const mockStore = configureMockStore(middlewares); let rootState = rootReducer(undefined, {} as Action); -// Apply actions to the state, one at a time +/** Apply actions to the state, one at a time. */ const applyActions = (state: any, actions: any, reducer: any) => { return actions.reduce((state: any, action: any) => reducer(state, action), state); }; diff --git a/app/soapbox/reducers/__tests__/contexts-test.js b/app/soapbox/reducers/__tests__/contexts-test.js index 30de0a49c..9708120bb 100644 --- a/app/soapbox/reducers/__tests__/contexts-test.js +++ b/app/soapbox/reducers/__tests__/contexts-test.js @@ -6,8 +6,10 @@ import { import context1 from 'soapbox/__fixtures__/context_1.json'; import context2 from 'soapbox/__fixtures__/context_2.json'; +import { STATUSES_IMPORT } from 'soapbox/actions/importer'; import { CONTEXT_FETCH_SUCCESS } from 'soapbox/actions/statuses'; import { TIMELINE_DELETE } from 'soapbox/actions/timelines'; +import { applyActions } from 'soapbox/jest/test-helpers'; import reducer, { ReducerRecord } from '../contexts'; @@ -21,9 +23,27 @@ describe('contexts reducer', () => { it('should support rendering a complete tree', () => { // https://gitlab.com/soapbox-pub/soapbox-fe/-/issues/422 - let result; - result = reducer(result, { type: CONTEXT_FETCH_SUCCESS, id: '9zIH8WYwtnUx4yDzUm', ancestors: context1.ancestors, descendants: context1.descendants }); - result = reducer(result, { type: CONTEXT_FETCH_SUCCESS, id: '9zIH7PUdhK3Ircg4hM', ancestors: context2.ancestors, descendants: context2.descendants }); + const actions = [{ + type: STATUSES_IMPORT, + statuses: [ + ...context1.ancestors, + ...context1.descendants, + ...context2.ancestors, + ...context2.descendants, + ], + }, { + type: CONTEXT_FETCH_SUCCESS, + id: '9zIH8WYwtnUx4yDzUm', + ancestors: context1.ancestors, + descendants: context1.descendants, + }, { + type: CONTEXT_FETCH_SUCCESS, + id: '9zIH7PUdhK3Ircg4hM', + ancestors: context2.ancestors, + descendants: context2.descendants, + }]; + + const result = applyActions(undefined, actions, reducer); expect(result).toEqual(ReducerRecord({ inReplyTos: ImmutableMap({