|
1 | 1 | import React from 'react';
|
2 |
| -import { render, screen } from '@testing-library/react'; |
| 2 | +import { fireEvent, render, screen } from '@testing-library/react'; |
3 | 3 | import userEvent from '@testing-library/user-event';
|
4 | 4 | import { mockStore } from '@deriv/stores';
|
5 | 5 | import ModulesProvider from 'Stores/Providers/modules-providers';
|
@@ -90,46 +90,56 @@ describe('TakeProfitAndStopLossInput', () => {
|
90 | 90 | expect(screen.getByText(accu_content)).toBeInTheDocument();
|
91 | 91 | });
|
92 | 92 |
|
93 |
| - it('should call focusAndOpenKeyboard, when ToggleSwitch is switched to true.', () => { |
| 93 | + it('should call focusAndOpenKeyboard, when ToggleSwitch is switched to true.', async () => { |
94 | 94 | const mockFocusAndOpenKeyboard = jest.spyOn(utils, 'focusAndOpenKeyboard');
|
95 | 95 | mockTakeProfitAndStopLossInput();
|
96 | 96 |
|
97 | 97 | const toggle_switcher = screen.getAllByRole('button')[0];
|
98 |
| - userEvent.click(toggle_switcher); |
| 98 | + await userEvent.click(toggle_switcher); |
99 | 99 | expect(mockFocusAndOpenKeyboard).toBeCalledTimes(1);
|
100 | 100 | });
|
101 | 101 |
|
102 |
| - it('should call focusAndOpenKeyboard, when user clicks on Take Profit overlay.', () => { |
| 102 | + it('should call focusAndOpenKeyboard, when user clicks on Take Profit overlay.', async () => { |
103 | 103 | const mockFocusAndOpenKeyboard = jest.spyOn(utils, 'focusAndOpenKeyboard');
|
104 | 104 | mockTakeProfitAndStopLossInput();
|
105 | 105 |
|
106 | 106 | const take_profit_overlay = screen.getByTestId('dt_take_profit_overlay');
|
107 |
| - userEvent.click(take_profit_overlay); |
| 107 | + await userEvent.click(take_profit_overlay); |
108 | 108 |
|
109 | 109 | expect(mockFocusAndOpenKeyboard).toBeCalledTimes(1);
|
110 | 110 | });
|
111 | 111 |
|
112 |
| - it('should render take profit overlay if ToggleSwitch was switched to false', () => { |
| 112 | + it('should render take profit overlay if ToggleSwitch was switched to false', async () => { |
113 | 113 | default_mock_store.modules.trade.has_take_profit = true;
|
114 | 114 | default_mock_store.modules.trade.take_profit = '5';
|
115 | 115 | mockTakeProfitAndStopLossInput();
|
116 | 116 |
|
117 | 117 | expect(screen.queryByTestId('dt_take_profit_overlay')).not.toBeInTheDocument();
|
118 | 118 | const toggle_switcher = screen.getAllByRole('button')[0];
|
119 |
| - userEvent.click(toggle_switcher); |
| 119 | + await userEvent.click(toggle_switcher); |
120 | 120 |
|
121 | 121 | expect(screen.getByTestId('dt_take_profit_overlay')).toBeInTheDocument();
|
122 | 122 | });
|
123 | 123 |
|
124 |
| - it('should call onChangeMultiple when user click on Save button, if there are no API errors', () => { |
| 124 | + it('should call onChangeMultiple when user click on Save button, if there are no API errors', async () => { |
125 | 125 | default_mock_store.modules.trade.has_take_profit = true;
|
126 | 126 | default_mock_store.modules.trade.take_profit = '5';
|
127 | 127 | mockTakeProfitAndStopLossInput();
|
128 | 128 |
|
129 |
| - userEvent.type(screen.getByTestId(tp_data_testid), '2'); |
| 129 | + await userEvent.type(screen.getByTestId(tp_data_testid), '2'); |
130 | 130 | const save_button = screen.getByText('Save');
|
131 |
| - userEvent.click(save_button); |
| 131 | + await userEvent.click(save_button); |
132 | 132 |
|
133 | 133 | expect(default_mock_store.modules.trade.onChangeMultiple).toBeCalled();
|
134 | 134 | });
|
| 135 | + |
| 136 | + it('should have max length of 10 for take profit input when currency is USD', async () => { |
| 137 | + default_mock_store.modules.trade.has_take_profit = true; |
| 138 | + default_mock_store.modules.trade.take_profit = '5'; |
| 139 | + mockTakeProfitAndStopLossInput(); |
| 140 | + const input_field = screen.getByTestId(tp_data_testid); |
| 141 | + await userEvent.type(input_field, '12345678901'); |
| 142 | + |
| 143 | + expect(input_field).toHaveValue('5123456789'); |
| 144 | + }); |
135 | 145 | });
|
0 commit comments