@transferwise/components 0.0.0-experimental-b684c07 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-b684c07",
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
- "@transferwise/neptune-css": "14.20.1",
96
- "@wise/components-theming": "1.6.1"
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
- describe('Date Input Component', () => {
7
- const props: DateInputProps = { onChange: jest.fn() };
4
+ mockMatchMedia();
5
+ mockResizeObserver();
8
6
 
9
- beforeEach(() => {
10
- mockMatchMedia();
11
- mockResizeObserver();
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
 
@@ -176,19 +176,40 @@ describe('Date Input Component', () => {
176
176
  });
177
177
  });
178
178
 
179
- describe('when switching from day input to year input', () => {
180
- it('does not call onBlur nor onFocus', () => {
181
- const onFocus = jest.fn();
182
- const onBlur = jest.fn();
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
+ });
183
193
 
184
- render(<DateInput {...props} />);
185
- const dayInput = screen.getByRole('textbox', { name: /day/i });
186
- const yearInput = screen.getByRole('textbox', { name: /year/i });
187
- fireEvent.focus(dayInput);
188
- fireEvent.blur(dayInput);
189
- fireEvent.focus(yearInput);
190
- expect(onFocus).not.toHaveBeenCalled();
191
- expect(onBlur).not.toHaveBeenCalled();
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);
192
213
  });
193
214
  });
194
215