@@ -69,6 +69,24 @@ describe('Unsorted State Adapter', () => {
6969 } )
7070 } )
7171
72+ it ( 'should let you add many entities to the state from a dictionary' , ( ) => {
73+ const withOneEntity = adapter . addOne ( state , TheGreatGatsby )
74+
75+ const withManyMore = adapter . addMany ( withOneEntity , {
76+ [ AClockworkOrange . id ] : AClockworkOrange ,
77+ [ AnimalFarm . id ] : AnimalFarm
78+ } )
79+
80+ expect ( withManyMore ) . toEqual ( {
81+ ids : [ TheGreatGatsby . id , AClockworkOrange . id , AnimalFarm . id ] ,
82+ entities : {
83+ [ TheGreatGatsby . id ] : TheGreatGatsby ,
84+ [ AClockworkOrange . id ] : AClockworkOrange ,
85+ [ AnimalFarm . id ] : AnimalFarm
86+ }
87+ } )
88+ } )
89+
7290 it ( 'should remove existing and add new ones on setAll' , ( ) => {
7391 const withOneEntity = adapter . addOne ( state , TheGreatGatsby )
7492
@@ -86,6 +104,23 @@ describe('Unsorted State Adapter', () => {
86104 } )
87105 } )
88106
107+ it ( 'should remove existing and add new ones on setAll when passing in a dictionary' , ( ) => {
108+ const withOneEntity = adapter . addOne ( state , TheGreatGatsby )
109+
110+ const withAll = adapter . setAll ( withOneEntity , {
111+ [ AClockworkOrange . id ] : AClockworkOrange ,
112+ [ AnimalFarm . id ] : AnimalFarm
113+ } )
114+
115+ expect ( withAll ) . toEqual ( {
116+ ids : [ AClockworkOrange . id , AnimalFarm . id ] ,
117+ entities : {
118+ [ AClockworkOrange . id ] : AClockworkOrange ,
119+ [ AnimalFarm . id ] : AnimalFarm
120+ }
121+ } )
122+ } )
123+
89124 it ( 'should let you add remove an entity from the state' , ( ) => {
90125 const withOneEntity = adapter . addOne ( state , TheGreatGatsby )
91126
@@ -230,14 +265,11 @@ describe('Unsorted State Adapter', () => {
230265
231266 /*
232267 Original code failed with a mish-mash of values, like:
233-
234268 {
235269 ids: [ 'c' ],
236270 entities: { b: { id: 'b', title: 'First' }, c: { id: 'c' } }
237271 }
238-
239272 We now expect that only 'c' will be left:
240-
241273 {
242274 ids: [ 'c' ],
243275 entities: { c: { id: 'c', title: 'First' } }
@@ -299,4 +331,25 @@ describe('Unsorted State Adapter', () => {
299331 }
300332 } )
301333 } )
334+
335+ it ( 'should let you upsert many entities in the state when passing in a dictionary' , ( ) => {
336+ const firstChange = { title : 'Zack' }
337+ const withMany = adapter . setAll ( state , [ TheGreatGatsby ] )
338+
339+ const withUpserts = adapter . upsertMany ( withMany , {
340+ [ TheGreatGatsby . id ] : { ...TheGreatGatsby , ...firstChange } ,
341+ [ AClockworkOrange . id ] : AClockworkOrange
342+ } )
343+
344+ expect ( withUpserts ) . toEqual ( {
345+ ids : [ TheGreatGatsby . id , AClockworkOrange . id ] ,
346+ entities : {
347+ [ TheGreatGatsby . id ] : {
348+ ...TheGreatGatsby ,
349+ ...firstChange
350+ } ,
351+ [ AClockworkOrange . id ] : AClockworkOrange
352+ }
353+ } )
354+ } )
302355} )
0 commit comments