1 import type { WrappedOptimisticState } from '../types';
2 import type { TestState } from '../utils/testing.utils';
3 import { createTestOptimisticHistoryItem } from '../utils/testing.utils';
4 import selectFailedAction from './select-failed-action';
6 describe('select failed action', () => {
7 test('should return first failed action matching optimisticId', () => {
8 const failedAction = createTestOptimisticHistoryItem('test', {}, true);
14 checkpoint: { items: [] },
15 history: [failedAction],
17 } as WrappedOptimisticState<TestState>,
20 const result = selectFailedAction(failedAction.id)(state.test);
21 expect(result).toEqual(failedAction);
24 test('should return undefined if action is not failed', () => {
25 const failedAction = createTestOptimisticHistoryItem('test', {}, false);
31 checkpoint: { items: [] },
32 history: [failedAction],
34 } as WrappedOptimisticState<TestState>,
37 const result = selectFailedAction(failedAction.id)(state.test);
38 expect(result).toEqual(undefined);
41 test('should return undefined if no match', () => {
42 const failedAction = createTestOptimisticHistoryItem('test', {}, false);
48 checkpoint: { items: [] },
49 history: [failedAction],
51 } as WrappedOptimisticState<TestState>,
54 const result = selectFailedAction('unknown-id')(state.test);
55 expect(result).toEqual(undefined);