@@ -7,44 +7,47 @@ import {
77} from '@reduxjs/toolkit'
88import type {
99 PayloadAction ,
10+ Slice ,
1011 SliceCaseReducers ,
11- ValidateSliceCaseReducers ,
12+ UnknownAction ,
1213} from '../..'
1314import type { EntityId , EntityState , IdSelector } from '../models'
14- import { AClockworkOrange , type BookModel } from './fixtures/book'
15+ import type { BookModel } from './fixtures/book'
1516
1617describe ( 'Entity Slice Enhancer' , ( ) => {
17- let slice : ReturnType < typeof entitySliceEnhancer < BookModel , string > >
18+ let slice : Slice < EntityState < BookModel , BookModel [ 'id' ] > >
1819
1920 beforeEach ( ( ) => {
20- slice = entitySliceEnhancer ( {
21+ const indieSlice = entitySliceEnhancer ( {
2122 name : 'book' ,
2223 selectId : ( book : BookModel ) => book . id ,
2324 } )
25+ slice = indieSlice
2426 } )
2527
2628 it ( 'exposes oneAdded' , ( ) => {
27- const action = slice . actions . oneAdded ( AClockworkOrange )
28- const oneAdded = slice . reducer ( undefined , action )
29- expect ( oneAdded . entities [ AClockworkOrange . id ] ) . toBe ( AClockworkOrange )
29+ const book = {
30+ id : '0' ,
31+ title : 'Der Steppenwolf' ,
32+ author : 'Herman Hesse' ,
33+ }
34+ const action = slice . actions . oneAdded ( book )
35+ const oneAdded = slice . reducer ( undefined , action as UnknownAction )
36+ expect ( oneAdded . entities [ '0' ] ) . toBe ( book )
3037 } )
3138} )
3239
33- interface EntitySliceArgs <
34- T ,
35- Id extends EntityId ,
36- CaseReducers extends SliceCaseReducers < EntityState < T , Id > > ,
37- > {
40+ interface EntitySliceArgs < T , Id extends EntityId > {
3841 name : string
3942 selectId : IdSelector < T , Id >
40- modelReducer ?: ValidateSliceCaseReducers < EntityState < T , Id > , CaseReducers >
43+ modelReducer ?: SliceCaseReducers < T >
4144}
4245
43- function entitySliceEnhancer <
44- T ,
45- Id extends EntityId ,
46- CaseReducers extends SliceCaseReducers < EntityState < T , Id > > = { } ,
47- > ( { name , selectId , modelReducer } : EntitySliceArgs < T , Id , CaseReducers > ) {
46+ function entitySliceEnhancer < T , Id extends EntityId > ( {
47+ name ,
48+ selectId ,
49+ modelReducer ,
50+ } : EntitySliceArgs < T , Id > ) {
4851 const modelAdapter = createEntityAdapter ( {
4952 selectId,
5053 } )
0 commit comments