Skip to content

Commit 91779f8

Browse files
committed
entity slice enhancer test set up
1 parent 470d7e9 commit 91779f8

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

packages/toolkit/src/entities/tests/entity_slice_enhancer.test.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
import { createEntityAdapter, createSlice } from "../..";
2-
import type { PayloadAction, SliceCaseReducers } from "../..";
3-
import type { DraftableIdSelector, IdSelector } from "../models";
2+
import type { PayloadAction, Slice, SliceCaseReducers } from "../..";
3+
import type { DraftableIdSelector, EntityAdapter, EntityState, IdSelector } from "../models";
4+
import type { BookModel } from "./fixtures/book";
5+
6+
describe('Entity Slice Enhancer', () => {
7+
let slice: Slice<EntityState<BookModel>>;
8+
9+
beforeEach(() => {
10+
const indieSlice = entitySliceEnhancer({
11+
name: 'book',
12+
selectDraftableId: (book: BookModel) => book.id
13+
})
14+
slice = indieSlice
15+
})
16+
})
417

518
interface EntitySliceArgs<T> {
619
name: string
7-
modelReducer: SliceCaseReducers<T>
8-
selectId: IdSelector<T> // unusable
9-
selectDraftableId: DraftableIdSelector<T>
20+
selectId?: IdSelector<T> // unusable
21+
selectDraftableId?: DraftableIdSelector<T>
22+
modelReducer?: SliceCaseReducers<T>
1023
}
1124

12-
// currently this never runs, it only serves to illustrate that the containing calls are type valid
1325
function entitySliceEnhancer<T>({
1426
name,
15-
modelReducer,
16-
selectId: undraftableSelectId,
17-
selectDraftableId
27+
selectId: unusableSelectId,
28+
selectDraftableId,
29+
modelReducer
1830
}: EntitySliceArgs<T>) {
1931
const modelAdapter = createEntityAdapter<T>({
20-
selectId: selectDraftableId // undraftableSelectId would give an interesting error
32+
selectId: selectDraftableId // unusableSelectId would give an interesting error
2133
});
2234

2335
return createSlice({

0 commit comments

Comments
 (0)