Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / components / containers / forward / ForwardConditions.spec.tsx
blob04ba6e0b314422ab585c40a1b4c7aeecc23b3064
1 import { render } from '@testing-library/react';
3 import useNotifications from '@proton/components/hooks/useNotifications';
5 import { ConditionComparator, ConditionType, FilterStatement } from '../filters/interfaces';
6 import ForwardConditions from './ForwardConditions';
8 jest.mock('@proton/components/hooks/useNotifications');
9 const mockUseNotifications = useNotifications as jest.MockedFunction<any>;
10 mockUseNotifications.mockReturnValue({
11     createNotification: jest.fn(),
12 });
14 describe('ForwardConditions', () => {
15     const setup = ({ statement = FilterStatement.ALL } = {}) => {
16         const onChangeStatement = jest.fn();
17         const onChangeConditions = jest.fn();
18         const validator = jest.fn();
19         const conditions = [
20             {
21                 id: 'id1',
22                 type: ConditionType.SENDER,
23                 values: ['token1', 'token2'],
24                 comparator: ConditionComparator.CONTAINS,
25                 isOpen: true,
26             },
27             {
28                 id: 'id2',
29                 type: ConditionType.SUBJECT,
30                 values: ['token1', 'token2'],
31                 comparator: ConditionComparator.CONTAINS,
32                 isOpen: true,
33             },
34             {
35                 id: 'id3',
36                 type: ConditionType.SUBJECT,
37                 values: ['token1', 'token2'],
38                 comparator: ConditionComparator.CONTAINS,
39                 isOpen: true,
40             },
41             {
42                 id: 'id4',
43                 type: ConditionType.SUBJECT,
44                 values: ['token1', 'token2'],
45                 comparator: ConditionComparator.CONTAINS,
46                 isOpen: true,
47             },
48         ];
49         const utils = render(
50             <ForwardConditions
51                 statement={statement}
52                 onChangeConditions={onChangeConditions}
53                 onChangeStatement={onChangeStatement}
54                 validator={validator}
55                 conditions={conditions}
56             />
57         );
58         return { ...utils, conditions, onChangeStatement, onChangeConditions };
59     };
61     describe('when the statement change', () => {
62         it('should change all statements', () => {
63             const { getAllByText, conditions } = setup();
64             const numberOfSelect = conditions.length - 1;
65             expect(getAllByText('And')).toHaveLength(numberOfSelect);
66             expect(setup({ statement: FilterStatement.ANY }).getAllByText('Or')).toHaveLength(numberOfSelect);
67         });
68     });
70     test('only the first condition should have an "If" label', () => {
71         const { getAllByText } = setup();
72         expect(getAllByText('If')).toHaveLength(1);
73     });
75     it('should have 1 delete button per condition', () => {
76         const { getAllByTestId, conditions } = setup();
77         expect(getAllByTestId('forward:condition:delete-button_', { exact: false })).toHaveLength(conditions.length);
78     });
79 });