Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / optimistic / selectors / select-failed-action.spec.ts
blobcd6d5c43de9e84d459472eea912ff057a9668a2f
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);
10         const state = {
11             test: {
12                 items: [],
13                 optimistic: {
14                     checkpoint: { items: [] },
15                     history: [failedAction],
16                 },
17             } as WrappedOptimisticState<TestState>,
18         };
20         const result = selectFailedAction(failedAction.id)(state.test);
21         expect(result).toEqual(failedAction);
22     });
24     test('should return undefined if action is not failed', () => {
25         const failedAction = createTestOptimisticHistoryItem('test', {}, false);
27         const state = {
28             test: {
29                 items: [],
30                 optimistic: {
31                     checkpoint: { items: [] },
32                     history: [failedAction],
33                 },
34             } as WrappedOptimisticState<TestState>,
35         };
37         const result = selectFailedAction(failedAction.id)(state.test);
38         expect(result).toEqual(undefined);
39     });
41     test('should return undefined if no match', () => {
42         const failedAction = createTestOptimisticHistoryItem('test', {}, false);
44         const state = {
45             test: {
46                 items: [],
47                 optimistic: {
48                     checkpoint: { items: [] },
49                     history: [failedAction],
50                 },
51             } as WrappedOptimisticState<TestState>,
52         };
54         const result = selectFailedAction('unknown-id')(state.test);
55         expect(result).toEqual(undefined);
56     });
57 });