diff --git a/src/state/__tests__/reducer.ts b/src/state/__tests__/reducer.ts index d12ea1effbfe..8979cad5b965 100644 --- a/src/state/__tests__/reducer.ts +++ b/src/state/__tests__/reducer.ts @@ -15,6 +15,10 @@ describe('reducer', () => { expiresAt: 5000500000, }, }; + const partialResultAction: ReceiveAction = { + ...action, + payload: { id, title: 'hello', content: undefined }, + }; const iniState = { entities: {}, results: {}, @@ -33,6 +37,21 @@ describe('reducer', () => { expect(nextEntity).not.toBe(prevEntity); expect(nextEntity).toBeDefined(); }) + it('should merge partial entity with existing entity', () => { + const getEntity = (state: any): ArticleResource => state.entities[ArticleResource.getKey()][`${ArticleResource.pk(action.payload)}`] + const prevEntity = getEntity(newState); + expect(prevEntity).toBeDefined(); + const nextState = reducer(newState, partialResultAction); + const nextEntity = getEntity(nextState); + expect(nextEntity).not.toBe(prevEntity); + expect(nextEntity).toBeDefined(); + + expect(nextEntity.title).not.toBe(prevEntity.title); + expect(nextEntity.title).toBe(partialResultAction.payload.title); + + expect(nextEntity.content).toBe(prevEntity.content); + expect(nextEntity.content).not.toBe(partialResultAction.payload.content); + }) }); it('mutate should never change results', () => { const id = 20;