Skip to content

Commit 82c9262

Browse files
committed
reset more entity files
1 parent 31c4794 commit 82c9262

File tree

5 files changed

+28
-29
lines changed

5 files changed

+28
-29
lines changed

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

+22-19
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
1-
import { createEntityAdapter, createSlice } from '@reduxjs/toolkit'
1+
import { createEntityAdapter, createSlice } from '../..'
22
import type {
33
PayloadAction,
4+
Slice,
45
SliceCaseReducers,
5-
ValidateSliceCaseReducers,
6+
UnknownAction,
67
} from '../..'
78
import type { EntityId, EntityState, IdSelector } from '../models'
8-
import { AClockworkOrange, type BookModel } from './fixtures/book'
9+
import type { BookModel } from './fixtures/book'
910

1011
describe('Entity Slice Enhancer', () => {
11-
let slice: ReturnType<typeof entitySliceEnhancer<BookModel, string>>
12+
let slice: Slice<EntityState<BookModel, BookModel['id']>>
1213

1314
beforeEach(() => {
14-
slice = entitySliceEnhancer({
15+
const indieSlice = entitySliceEnhancer({
1516
name: 'book',
1617
selectId: (book: BookModel) => book.id,
1718
})
19+
slice = indieSlice
1820
})
1921

2022
it('exposes oneAdded', () => {
21-
const action = slice.actions.oneAdded(AClockworkOrange)
22-
const oneAdded = slice.reducer(undefined, action)
23-
expect(oneAdded.entities[AClockworkOrange.id]).toBe(AClockworkOrange)
23+
const book = {
24+
id: '0',
25+
title: 'Der Steppenwolf',
26+
author: 'Herman Hesse',
27+
}
28+
const action = slice.actions.oneAdded(book)
29+
const oneAdded = slice.reducer(undefined, action as UnknownAction)
30+
expect(oneAdded.entities['0']).toBe(book)
2431
})
2532
})
2633

27-
interface EntitySliceArgs<
28-
T,
29-
Id extends EntityId,
30-
CaseReducers extends SliceCaseReducers<EntityState<T, Id>>,
31-
> {
34+
interface EntitySliceArgs<T, Id extends EntityId> {
3235
name: string
3336
selectId: IdSelector<T, Id>
34-
modelReducer?: ValidateSliceCaseReducers<EntityState<T, Id>, CaseReducers>
37+
modelReducer?: SliceCaseReducers<T>
3538
}
3639

37-
function entitySliceEnhancer<
38-
T,
39-
Id extends EntityId,
40-
CaseReducers extends SliceCaseReducers<EntityState<T, Id>> = {},
41-
>({ name, selectId, modelReducer }: EntitySliceArgs<T, Id, CaseReducers>) {
40+
function entitySliceEnhancer<T, Id extends EntityId>({
41+
name,
42+
selectId,
43+
modelReducer,
44+
}: EntitySliceArgs<T, Id>) {
4245
const modelAdapter = createEntityAdapter({
4346
selectId,
4447
})

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { EntityAdapter } from '../models'
2-
import { createEntityAdapter } from '../create_adapter'
1+
import type { EntityAdapter } from '../index'
2+
import { createEntityAdapter } from '../index'
33
import type { PayloadAction } from '../../createAction'
44
import { createAction } from '../../createAction'
55
import { createSlice } from '../../createSlice'

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { EntityAdapter } from '../models'
2-
import { createEntityAdapter } from '../create_adapter'
1+
import type { EntityAdapter } from '../index'
2+
import { createEntityAdapter } from '../index'
33
import type { PayloadAction } from '../../createAction'
44
import { configureStore } from '../../configureStore'
55
import { createSlice } from '../../createSlice'

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createDraftSafeSelectorCreator } from '../../createDraftSafeSelector'
2-
import type { EntityAdapter, EntityState } from '../models'
3-
import { createEntityAdapter } from '../create_adapter'
2+
import type { EntityAdapter, EntityState } from '../index'
3+
import { createEntityAdapter } from '../index'
44
import type { EntitySelectors } from '../models'
55
import type { BookModel } from './fixtures/book'
66
import { AClockworkOrange, AnimalFarm, TheGreatGatsby } from './fixtures/book'

packages/toolkit/src/entities/utils.ts

-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,3 @@ export function splitAddedUpdatedEntities<T, Id extends EntityId>(
5555
}
5656
return [added, updated]
5757
}
58-
59-
export function capitalize<S extends string>(str: S) {
60-
return str && (str.replace(str[0], str[0].toUpperCase()) as Capitalize<S>)
61-
}

0 commit comments

Comments
 (0)