@transferwise/components 0.0.0-experimental-cb1ee1c → 0.0.0-experimental-fe1dc6d
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 +3 -3
- package/src/dateInput/DateInput.spec.tsx +44 -48
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-fe1dc6d",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
"rollup-preserve-directives": "^1.1.1",
|
|
93
93
|
"storybook": "^8.2.2",
|
|
94
94
|
"@transferwise/less-config": "3.1.0",
|
|
95
|
-
"@
|
|
96
|
-
"@
|
|
95
|
+
"@wise/components-theming": "1.6.1",
|
|
96
|
+
"@transferwise/neptune-css": "14.20.1"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"@transferwise/icons": "^3.13.1",
|
|
@@ -1,15 +1,15 @@
|
|
|
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
14
|
afterEach(jest.clearAllMocks);
|
|
15
15
|
|
|
@@ -97,24 +97,11 @@ describe('Date Input Component', () => {
|
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
it('calls the onChange callback with null when changing the month but nothing else is filled out', async () => {
|
|
100
|
-
console.time("t1");
|
|
101
100
|
render(<DateInput {...props} />);
|
|
102
101
|
const monthSelect = screen.getByLabelText(/month/i);
|
|
103
|
-
console.log(monthSelect ? '>>> monthSelect' : '>>> no monthSelect');
|
|
104
|
-
console.log('----------------------');
|
|
105
102
|
await userEvent.click(monthSelect);
|
|
106
|
-
|
|
107
|
-
const january = screen.getByRole('option', { name: /January/ });
|
|
108
|
-
console.log(january? '>>> january' : '>>> no january');
|
|
109
|
-
console.log('----------------------');
|
|
110
|
-
await userEvent.click(january);
|
|
111
|
-
|
|
112
|
-
// @ts-expect-error test
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
114
|
-
console.log(props.onChange?.mock?.calls);
|
|
103
|
+
await userEvent.click(screen.getByRole('option', { name: /January/ }));
|
|
115
104
|
expect(props.onChange).toHaveBeenCalledWith(null);
|
|
116
|
-
|
|
117
|
-
console.timeEnd("t1");
|
|
118
105
|
}, 10_000);
|
|
119
106
|
|
|
120
107
|
it('calls the onChange callback with null when changing the year but nothing else is filled out', async () => {
|
|
@@ -132,23 +119,11 @@ describe('Date Input Component', () => {
|
|
|
132
119
|
});
|
|
133
120
|
|
|
134
121
|
it('calls the onChange callback with the correct value when changing the month', async () => {
|
|
135
|
-
console.time("t2");
|
|
136
122
|
render(<DateInput {...props} value="2022-12-1" />);
|
|
137
123
|
const monthSelect = screen.getByRole('combobox', { name: /month/i });
|
|
138
|
-
console.log(monthSelect ? '>>> monthSelect' : '>>> no monthSelect');
|
|
139
|
-
console.log('----------------------');
|
|
140
124
|
await userEvent.click(monthSelect);
|
|
141
|
-
|
|
142
|
-
const january = screen.getByRole('option', { name: /January/ });
|
|
143
|
-
console.log(january? '>>> january' : '>>> no january');
|
|
144
|
-
console.log('----------------------');
|
|
145
|
-
await userEvent.click(january);
|
|
146
|
-
|
|
147
|
-
// @ts-expect-error test
|
|
148
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
149
|
-
console.log(props.onChange.mock.calls);
|
|
125
|
+
await userEvent.click(screen.getByRole('option', { name: /January/ }));
|
|
150
126
|
expect(props.onChange).toHaveBeenCalledWith('2022-01-01');
|
|
151
|
-
console.timeEnd("t2");
|
|
152
127
|
}, 10_000);
|
|
153
128
|
|
|
154
129
|
it('calls the onChange callback with the correct value when changing the year', async () => {
|
|
@@ -201,19 +176,40 @@ describe('Date Input Component', () => {
|
|
|
201
176
|
});
|
|
202
177
|
});
|
|
203
178
|
|
|
204
|
-
describe('
|
|
205
|
-
it('
|
|
206
|
-
|
|
207
|
-
|
|
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
|
+
});
|
|
208
193
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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);
|
|
217
213
|
});
|
|
218
214
|
});
|
|
219
215
|
|