@transferwise/components 0.0.0-experimental-cc8c25a → 0.0.0-experimental-1597e95

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-cc8c25a",
3
+ "version": "0.0.0-experimental-1597e95",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -7,6 +7,9 @@ import { storyConfig } from '../test-utils';
7
7
 
8
8
  import Avatar, { AvatarType } from '.';
9
9
 
10
+ /**
11
+ * @deprecated use **`AvatarView`** components instead
12
+ */
10
13
  export default {
11
14
  component: Avatar,
12
15
  title: 'Content/Avatar',
@@ -45,7 +48,7 @@ export const Table: Story = storyConfig(
45
48
  const backgroundColor = '#d6f5e3';
46
49
  const emoji = '✈️';
47
50
  const initials = 'GN';
48
- const Icon = wiseIcons['Check'];
51
+ const Icon = wiseIcons.Check;
49
52
 
50
53
  return (
51
54
  <div>
@@ -4,7 +4,11 @@ import { ProfileType, Sentiment } from '../common';
4
4
 
5
5
  import AvatarWrapper from './AvatarWrapper';
6
6
 
7
+ /**
8
+ * @deprecated use **`AvatarView`** components instead
9
+ */
7
10
  export default {
11
+ tags: ['autodocs'],
8
12
  component: AvatarWrapper,
9
13
  title: 'Content/AvatarWrapper',
10
14
  } satisfies Meta<typeof AvatarWrapper>;
@@ -5,7 +5,11 @@ import { Size, Theme } from '../common';
5
5
 
6
6
  import Badge from './Badge';
7
7
 
8
+ /**
9
+ * @deprecated use **`<AvatarView badge={..} />`** components instead
10
+ */
8
11
  export default {
12
+ tags: ['autodocs'],
9
13
  component: Badge,
10
14
  title: 'Content/Badge',
11
15
  excludeStories: ['ExampleBadgeCss'],
@@ -1,8 +1,9 @@
1
1
  import { mockMatchMedia, mockResizeObserver, render, screen, userEvent } from '../test-utils';
2
2
 
3
- import { MoneyInput, CurrencyItem, CurrencyOptionItem } from '..';
3
+ import { MoneyInput, CurrencyItem, CurrencyOptionItem, Field } from '..';
4
4
  import { MoneyInputPropsWithInputAttributes } from './MoneyInput';
5
5
  import { within } from '@testing-library/react';
6
+ import messages from './MoneyInput.messages';
6
7
 
7
8
  mockMatchMedia();
8
9
  mockResizeObserver();
@@ -96,11 +97,6 @@ describe('Money Input', () => {
96
97
  });
97
98
  });
98
99
 
99
- it('renders Select component with generated id when id is not provided', () => {
100
- customRender();
101
- expect(getTrigger()).toHaveAttribute('id');
102
- });
103
-
104
100
  it('shows the currently active currency as active and hides its note', () => {
105
101
  customRender({ selectedCurrency: popularCurrencies[0] });
106
102
  expect(getTrigger()).toHaveTextContent(popularCurrencies[0].label);
@@ -247,11 +243,6 @@ describe('Money Input', () => {
247
243
  expect(initialProps.onAmountChange).toHaveBeenCalledWith(null);
248
244
  });
249
245
 
250
- it('passes the id given to the input element', () => {
251
- customRender({ id: 'some-id' });
252
- expect(getInput()).toHaveAttribute('id', 'some-id');
253
- });
254
-
255
246
  it('renders addon when element is passed through props', () => {
256
247
  const addonElement = <span data-testid="test-addon" />;
257
248
  customRender({ addon: addonElement });
@@ -377,4 +368,101 @@ describe('Money Input', () => {
377
368
  });
378
369
  expect(screen.getAllByRole('group')[1]).toHaveClass('selectClassName');
379
370
  });
371
+
372
+ describe('text input', () => {
373
+ it.each([
374
+ ['asd', ''],
375
+ ['1a2s3d', '123'],
376
+ ['±!@#$^*_+?><', ''],
377
+ ['1±!@#$^*,_+?><2', '1,2'],
378
+ ['12,3', '12,3'],
379
+ ['12.3', '12.3'],
380
+ ])("ignores the letters when typed '%s' and shows '%s'", async (testValue, expectedValue) => {
381
+ customRender({ amount: null });
382
+ await userEvent.type(getInput(), testValue);
383
+ expect(getInput()).toHaveValue(expectedValue);
384
+ });
385
+ });
386
+
387
+ it('supports custom `aria-labelledby` attribute', () => {
388
+ render(
389
+ <>
390
+ {/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
391
+ <label id="prioritized-label">Prioritized label</label>
392
+ <MoneyInput {...initialProps} aria-labelledby="prioritized-label" />
393
+ </>,
394
+ );
395
+
396
+ expect(screen.getAllByLabelText('Prioritized label')[0]).toHaveClass('input-group');
397
+ });
398
+
399
+ it('supports `Field` for labeling', () => {
400
+ render(
401
+ <Field label="Recipient gets">
402
+ <MoneyInput {...initialProps} />
403
+ </Field>,
404
+ );
405
+ expect(screen.getAllByRole('group')[0]).toHaveAccessibleName(/^Recipient gets/);
406
+ });
407
+
408
+ describe('ids', () => {
409
+ it('renders Select component with generated id when id is not provided', () => {
410
+ customRender();
411
+ expect(getTrigger()).toHaveAttribute('id');
412
+ });
413
+
414
+ it('passes the id given to the input element', () => {
415
+ customRender({ id: 'some-id' });
416
+ expect(getInput()).toHaveAttribute('id', 'some-id');
417
+ });
418
+
419
+ it('should guarantee id and connect the input with the selected currency via withId HoC', () => {
420
+ customRender();
421
+ expect(getInput().getAttribute('id')).toBeTruthy();
422
+ expect(getInput()).toHaveAttribute('aria-describedby', getTrigger().getAttribute('id'));
423
+ });
424
+
425
+ it('should have unique id for the select filter with predefined id', async () => {
426
+ const fieldId = 'myFieldId';
427
+ const searchPlaceholder = 'Type a currency or country';
428
+ render(
429
+ <Field label="Multiple currencies" id={fieldId}>
430
+ <MoneyInput {...initialProps} searchPlaceholder={searchPlaceholder} />
431
+ </Field>,
432
+ );
433
+ await openDropdown();
434
+ expect(screen.getByLabelText(searchPlaceholder)).toHaveAttribute(
435
+ 'id',
436
+ `${fieldId}SelectedCurrencySearch`,
437
+ );
438
+ });
439
+
440
+ it('should have unique id for the select filter without predefined id', async () => {
441
+ const searchPlaceholder = 'Type a currency or country';
442
+ render(
443
+ <Field label="Multiple currencies">
444
+ <MoneyInput {...initialProps} searchPlaceholder={searchPlaceholder} />
445
+ </Field>,
446
+ );
447
+ await openDropdown();
448
+ expect(screen.getByLabelText(searchPlaceholder)).toHaveAttribute(
449
+ 'id',
450
+ expect.stringMatching(/^:.*?:SelectedCurrencySearch$/),
451
+ );
452
+ });
453
+ });
454
+
455
+ it('should have AT label for the currency dropdown', () => {
456
+ customRender();
457
+ expect(getTrigger()).toHaveAttribute('aria-label', messages.selectCurrencyLabel.defaultMessage);
458
+ });
459
+
460
+ it('should have a listbox label', async () => {
461
+ customRender();
462
+ const trigger = getTrigger();
463
+ await openDropdown();
464
+ const triggerLabel = trigger.getAttribute('aria-label');
465
+ expect(triggerLabel).toBeTruthy();
466
+ expect(screen.getByRole('listbox', { name: triggerLabel ?? '' })).toBeInTheDocument();
467
+ });
380
468
  });
@@ -1,149 +0,0 @@
1
- import { Field } from '../field/Field';
2
- import { mockMatchMedia, mockResizeObserver, render, screen, userEvent } from '../test-utils';
3
-
4
- import MoneyInput from './MoneyInput';
5
- import messages from './MoneyInput.messages';
6
-
7
- mockMatchMedia();
8
- mockResizeObserver();
9
-
10
- describe('MoneyInput', () => {
11
- const currencies = [
12
- {
13
- header: 'Popular currencies',
14
- },
15
- {
16
- value: 'EUR',
17
- label: 'EUR',
18
- note: 'Euro',
19
- currency: 'eur',
20
- searchable: 'Spain, Germany, France, Austria, Estonia',
21
- },
22
- {
23
- value: 'USD',
24
- label: 'USD',
25
- note: 'United States dollar',
26
- currency: 'usd',
27
- searchable: 'Hong Kong, Saudi Arabia',
28
- },
29
- {
30
- value: 'GBP',
31
- label: 'GBP',
32
- note: 'British pound',
33
- currency: 'gbp',
34
- searchable: 'England, Scotland, Wales',
35
- },
36
- {
37
- header: 'Some other currencies',
38
- },
39
- {
40
- value: 'CAD',
41
- label: 'CAD',
42
- note: 'Canadian dollar',
43
- currency: 'cad',
44
- },
45
- {
46
- value: 'AUD',
47
- label: 'AUD',
48
- note: 'Australian dollar',
49
- currency: 'aud',
50
- },
51
- ] as const;
52
- const props = {
53
- currencies,
54
- selectedCurrency: currencies[1],
55
- searchPlaceholder: 'Type a currency / country',
56
- amount: 1000,
57
- onAmountChange: jest.fn(),
58
- onCurrencyChange: jest.fn(),
59
- };
60
- it.each([
61
- ['asd', ''],
62
- ['1a2s3d', '123'],
63
- ['±!@#$^*_+?><', ''],
64
- ['1±!@#$^*,_+?><2', '1,2'],
65
- ['12,3', '12,3'],
66
- ['12.3', '12.3'],
67
- ])("ignores the letters when typed '%s' and shows '%s'", async (testValue, expectedValue) => {
68
- render(<MoneyInput {...props} amount={null} />);
69
-
70
- const input = screen.getByRole('textbox');
71
- await userEvent.type(input, testValue);
72
- expect(input).toHaveValue(expectedValue);
73
- });
74
-
75
- it('supports custom `aria-labelledby` attribute', () => {
76
- render(
77
- <>
78
- {/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
79
- <label id="prioritized-label">Prioritized label</label>
80
- <MoneyInput {...props} aria-labelledby="prioritized-label" />
81
- </>,
82
- );
83
-
84
- expect(screen.getAllByLabelText('Prioritized label')[0]).toHaveClass('input-group');
85
- });
86
-
87
- it('supports `Field` for labeling', () => {
88
- render(
89
- <Field label="Recipient gets">
90
- <MoneyInput {...props} />
91
- </Field>,
92
- );
93
- expect(screen.getAllByRole('group')[0]).toHaveAccessibleName(/^Recipient gets/);
94
- });
95
-
96
- describe('ids', () => {
97
- it('should guarantee id and connect the input with the selected currency via withId HoC', () => {
98
- render(<MoneyInput {...props} />);
99
- const input = screen.getByRole('textbox');
100
- const button = screen.getByRole('combobox');
101
- expect(input.getAttribute('id')).toBeTruthy();
102
- expect(input).toHaveAttribute('aria-describedby', button.getAttribute('id'));
103
- });
104
-
105
- it('should have unique id for the select filter with predefined id', async () => {
106
- const fieldId = 'myFieldId';
107
- render(
108
- <Field label="Multiple currencies" id={fieldId}>
109
- <MoneyInput {...props} />
110
- </Field>,
111
- );
112
- await userEvent.click(screen.getByRole('combobox'));
113
- expect(screen.getByLabelText(props.searchPlaceholder)).toHaveAttribute(
114
- 'id',
115
- `${fieldId}SelectedCurrencySearch`,
116
- );
117
- });
118
-
119
- it('should have unique id for the select filter without predefined id', async () => {
120
- render(
121
- <Field label="Multiple currencies">
122
- <MoneyInput {...props} />
123
- </Field>,
124
- );
125
- await userEvent.click(screen.getByRole('combobox'));
126
- expect(screen.getByLabelText(props.searchPlaceholder)).toHaveAttribute(
127
- 'id',
128
- expect.stringMatching(/^:.*?:SelectedCurrencySearch$/),
129
- );
130
- });
131
- });
132
-
133
- it('should have AT label for the currency dropdown', () => {
134
- render(<MoneyInput {...props} />);
135
- expect(screen.getByRole('combobox')).toHaveAttribute(
136
- 'aria-label',
137
- messages.selectCurrencyLabel.defaultMessage,
138
- );
139
- });
140
-
141
- it('should have a listbox label', async () => {
142
- render(<MoneyInput {...props} />);
143
- const trigger = screen.getByRole('combobox');
144
- await userEvent.click(trigger);
145
- const triggerLabel = trigger.getAttribute('aria-label');
146
- expect(triggerLabel).toBeTruthy();
147
- expect(screen.getByRole('listbox', { name: triggerLabel ?? '' })).toBeInTheDocument();
148
- });
149
- });