1 import type { OptimisticReducersMapObject, WrappedOptimisticState } from '../types';
2 import type { TestState } from '../utils/testing.utils';
4 createTestDeterministicAction,
5 createTestOptimisticHistoryItem,
7 } from '../utils/testing.utils';
8 import withOptimistic from '../with-optimistic';
9 import selectOptimisticList from './select-optimistic-list';
11 describe('selectOptimisticList', () => {
12 test('should map optimistic list items to optimistic state', () => {
13 type TestItem = { value: number };
17 items: [{ value: 1 }, { value: 2 }, { value: 3 }],
19 checkpoint: { items: [] },
21 createTestOptimisticHistoryItem('add', { value: 1 }, true),
22 createTestDeterministicAction('add', { value: 2 }),
23 createTestOptimisticHistoryItem('add', { value: 3 }, false),
26 } as WrappedOptimisticState<TestState<TestItem>>,
29 const reducerMap: OptimisticReducersMapObject<typeof state> = {
30 testOptimistic: withOptimistic([], createTestReducer<TestItem>()).reducer,
32 const result = selectOptimisticList(reducerMap)(
33 (state) => state.testOptimistic.items,
37 expect(result).toEqual([
38 { value: 1, failed: true, optimistic: true },
39 { value: 2, failed: false, optimistic: false },
40 { value: 3, failed: false, optimistic: true },