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(),
14 describe('ForwardConditions', () => {
15 const setup = ({ statement = FilterStatement.ALL } = {}) => {
16 const onChangeStatement = jest.fn();
17 const onChangeConditions = jest.fn();
18 const validator = jest.fn();
22 type: ConditionType.SENDER,
23 values: ['token1', 'token2'],
24 comparator: ConditionComparator.CONTAINS,
29 type: ConditionType.SUBJECT,
30 values: ['token1', 'token2'],
31 comparator: ConditionComparator.CONTAINS,
36 type: ConditionType.SUBJECT,
37 values: ['token1', 'token2'],
38 comparator: ConditionComparator.CONTAINS,
43 type: ConditionType.SUBJECT,
44 values: ['token1', 'token2'],
45 comparator: ConditionComparator.CONTAINS,
52 onChangeConditions={onChangeConditions}
53 onChangeStatement={onChangeStatement}
55 conditions={conditions}
58 return { ...utils, conditions, onChangeStatement, onChangeConditions };
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);
70 test('only the first condition should have an "If" label', () => {
71 const { getAllByText } = setup();
72 expect(getAllByText('If')).toHaveLength(1);
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);