@transferwise/components 0.0.0-experimental-4394f5b → 0.0.0-experimental-4530892
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/dateInput/DateInput.spec.tsx +45 -26
package/package.json
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { screen, fireEvent } from '@testing-library/react';
|
|
2
|
-
import userEvent from '@testing-library/user-event';
|
|
3
1
|
import { DateInput, DateInputProps, Field } from '..';
|
|
4
|
-
import { mockMatchMedia, mockResizeObserver, render } from '../test-utils';
|
|
2
|
+
import { mockMatchMedia, mockResizeObserver, render, userEvent, screen } from '../test-utils';
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
mockMatchMedia();
|
|
5
|
+
mockResizeObserver();
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
describe('Date Input Component', () => {
|
|
8
|
+
const props: DateInputProps = {
|
|
9
|
+
onChange: jest.fn(),
|
|
10
|
+
onFocus: jest.fn(),
|
|
11
|
+
onBlur: jest.fn(),
|
|
12
|
+
};
|
|
13
13
|
|
|
14
|
-
afterEach(
|
|
15
|
-
jest.resetAllMocks();
|
|
16
|
-
});
|
|
14
|
+
afterEach(jest.clearAllMocks);
|
|
17
15
|
|
|
18
16
|
describe('when initialised without a model', () => {
|
|
19
17
|
it('sets day field to empty', () => {
|
|
@@ -104,7 +102,7 @@ describe('Date Input Component', () => {
|
|
|
104
102
|
await userEvent.click(monthSelect);
|
|
105
103
|
await userEvent.click(screen.getByRole('option', { name: /January/ }));
|
|
106
104
|
expect(props.onChange).toHaveBeenCalledWith(null);
|
|
107
|
-
});
|
|
105
|
+
}, 10_000);
|
|
108
106
|
|
|
109
107
|
it('calls the onChange callback with null when changing the year but nothing else is filled out', async () => {
|
|
110
108
|
render(<DateInput {...props} />);
|
|
@@ -126,7 +124,7 @@ describe('Date Input Component', () => {
|
|
|
126
124
|
await userEvent.click(monthSelect);
|
|
127
125
|
await userEvent.click(screen.getByRole('option', { name: /January/ }));
|
|
128
126
|
expect(props.onChange).toHaveBeenCalledWith('2022-01-01');
|
|
129
|
-
});
|
|
127
|
+
}, 10_000);
|
|
130
128
|
|
|
131
129
|
it('calls the onChange callback with the correct value when changing the year', async () => {
|
|
132
130
|
render(<DateInput {...props} value="0122-12-1" />);
|
|
@@ -178,19 +176,40 @@ describe('Date Input Component', () => {
|
|
|
178
176
|
});
|
|
179
177
|
});
|
|
180
178
|
|
|
181
|
-
describe('
|
|
182
|
-
it('
|
|
183
|
-
|
|
184
|
-
|
|
179
|
+
describe('propagating focus and blur callbacks', () => {
|
|
180
|
+
it('should propagate if focusing from or blurring to external component', async () => {
|
|
181
|
+
render(
|
|
182
|
+
<>
|
|
183
|
+
<button type="button">starting point</button>
|
|
184
|
+
<DateInput {...props} />
|
|
185
|
+
</>,
|
|
186
|
+
);
|
|
187
|
+
await userEvent.tab();
|
|
188
|
+
await userEvent.tab();
|
|
189
|
+
await userEvent.tab({ shift: true });
|
|
190
|
+
expect(props.onFocus).toHaveBeenCalledTimes(1);
|
|
191
|
+
expect(props.onBlur).toHaveBeenCalledTimes(1);
|
|
192
|
+
});
|
|
185
193
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
it('should not propagate if switching between internals', async () => {
|
|
195
|
+
render(
|
|
196
|
+
<>
|
|
197
|
+
<button type="button">external button</button>
|
|
198
|
+
<DateInput {...props} />
|
|
199
|
+
</>,
|
|
200
|
+
);
|
|
201
|
+
const externalButton = screen.getByRole('button', { name: 'external button' });
|
|
202
|
+
|
|
203
|
+
await userEvent.click(externalButton);
|
|
204
|
+
await userEvent.click(screen.getByRole('textbox', { name: /day/i }));
|
|
205
|
+
await userEvent.click(screen.getByRole('textbox', { name: /year/i }));
|
|
206
|
+
await userEvent.click(externalButton);
|
|
207
|
+
|
|
208
|
+
// 1 call is caused by the initial switch to the component,
|
|
209
|
+
// as reflected in `should propagate if focusing from or
|
|
210
|
+
// blurring to external component` test
|
|
211
|
+
expect(props.onFocus).toHaveBeenCalledTimes(1);
|
|
212
|
+
expect(props.onBlur).toHaveBeenCalledTimes(1);
|
|
194
213
|
});
|
|
195
214
|
});
|
|
196
215
|
|