@transferwise/components 0.0.0-experimental-08d336e → 0.0.0-experimental-b069e0c

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.
Files changed (36) hide show
  1. package/build/index.esm.js +1308 -1237
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +1306 -1236
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +1 -1
  6. package/build/styles/main.css +1 -1
  7. package/build/styles/moneyInput/MoneyInput.css +1 -1
  8. package/build/types/common/hooks/useLayout/useLayout.d.ts +6 -9
  9. package/build/types/common/hooks/useLayout/useLayout.d.ts.map +1 -1
  10. package/build/types/index.d.ts +0 -1
  11. package/build/types/index.d.ts.map +1 -1
  12. package/build/types/inputs/SelectInput.d.ts +2 -1
  13. package/build/types/inputs/SelectInput.d.ts.map +1 -1
  14. package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
  15. package/package.json +1 -1
  16. package/src/common/hooks/useLayout/useLayout.ts +49 -21
  17. package/src/common/responsivePanel/ResponsivePanel.spec.js +1 -3
  18. package/src/dateLookup/DateLookup.testingLibrary.spec.js +19 -1
  19. package/src/dateLookup/dateHeader/DateHeader.spec.js +0 -2
  20. package/src/drawer/Drawer.rtl.spec.js +1 -3
  21. package/src/drawer/Drawer.spec.js +0 -2
  22. package/src/index.ts +0 -1
  23. package/src/info/Info.spec.js +11 -7
  24. package/src/inputs/SelectInput.tsx +8 -0
  25. package/src/main.css +1 -1
  26. package/src/modal/Modal.rtl.spec.js +1 -3
  27. package/src/modal/Modal.spec.js +0 -2
  28. package/src/modal/Modal.tsx +2 -2
  29. package/src/moneyInput/MoneyInput.css +1 -1
  30. package/src/moneyInput/MoneyInput.js +85 -44
  31. package/src/moneyInput/MoneyInput.less +35 -161
  32. package/src/moneyInput/MoneyInput.rtl.spec.js +71 -0
  33. package/src/moneyInput/MoneyInput.spec.js +245 -117
  34. package/src/moneyInput/MoneyInput.story.tsx +78 -1
  35. package/src/ssr.spec.js +0 -1
  36. package/src/uploadInput/UploadInput.spec.tsx +1 -3
@@ -1,11 +1,10 @@
1
- import { render } from '@testing-library/react';
2
- import userEvent from '@testing-library/user-event';
3
1
  import { shallow } from 'enzyme';
4
2
 
5
- import { Select, MoneyInput, Title, Input } from '..';
6
- import { mockMatchMedia } from '../test-utils';
3
+ import { MoneyInput, Title, Input, SelectInput } from '..';
4
+ import { mockMatchMedia, mockResizeObserver } from '../test-utils';
7
5
 
8
6
  mockMatchMedia();
7
+ mockResizeObserver();
9
8
 
10
9
  jest.mock('./currencyFormatting', () => ({
11
10
  parseAmount: jest.fn(),
@@ -86,7 +85,7 @@ describe('Money Input', () => {
86
85
  });
87
86
 
88
87
  function currencySelect() {
89
- return component.find(Select);
88
+ return component.find(SelectInput);
90
89
  }
91
90
 
92
91
  function fixedCurrencyDisplay() {
@@ -99,7 +98,11 @@ describe('Money Input', () => {
99
98
  }
100
99
 
101
100
  function displayedCurrencies() {
102
- return currencySelect().prop('options');
101
+ return currencySelect().prop('items');
102
+ }
103
+
104
+ function getFooter() {
105
+ return currencySelect().prop('renderFooter');
103
106
  }
104
107
 
105
108
  function amountInput() {
@@ -125,31 +128,86 @@ describe('Money Input', () => {
125
128
 
126
129
  it('renders a select with all the currencies as options', () => {
127
130
  expect(currencySelect()).toHaveLength(1);
128
- expect(displayedCurrencies()).toStrictEqual(props.currencies);
129
- });
130
-
131
- it('renders a Select component with expected id when id is provided', () => {
132
- let componentWithId = shallow(<MoneyInput id="mock-id" {...props} />).dive();
133
- const select = componentWithId.find('Select');
134
-
135
- expect(select.prop('id')).toBe('mock-id-select');
131
+ expect(displayedCurrencies()).toStrictEqual([
132
+ {
133
+ type: 'group',
134
+ label: 'Popular currencies',
135
+ options: [
136
+ {
137
+ type: 'option',
138
+ value: {
139
+ value: 'EUR',
140
+ label: 'EUR',
141
+ note: 'Euro',
142
+ currency: 'eur',
143
+ searchable: 'Spain, Germany, France, Austria, Estonia',
144
+ },
145
+ filterMatchers: ['EUR', 'EUR', 'Euro', 'Spain, Germany, France, Austria, Estonia'],
146
+ },
147
+ {
148
+ type: 'option',
149
+ value: {
150
+ value: 'USD',
151
+ label: 'USD',
152
+ note: 'United States dollar',
153
+ currency: 'usd',
154
+ searchable: 'Hong Kong, Saudi Arabia',
155
+ },
156
+ filterMatchers: ['USD', 'USD', 'United States dollar', 'Hong Kong, Saudi Arabia'],
157
+ },
158
+ {
159
+ type: 'option',
160
+ value: {
161
+ value: 'GBP',
162
+ label: 'GBP',
163
+ note: 'British pound',
164
+ currency: 'gbp',
165
+ searchable: 'England, Scotland, Wales',
166
+ },
167
+ filterMatchers: ['GBP', 'GBP', 'British pound', 'England, Scotland, Wales'],
168
+ },
169
+ ],
170
+ },
171
+ {
172
+ type: 'group',
173
+ label: 'Some other currencies',
174
+ options: [
175
+ {
176
+ type: 'option',
177
+ value: {
178
+ value: 'CAD',
179
+ label: 'CAD',
180
+ note: 'Canadian dollar',
181
+ currency: 'cad',
182
+ },
183
+ filterMatchers: ['CAD', 'CAD', 'Canadian dollar', undefined],
184
+ },
185
+ {
186
+ type: 'option',
187
+ value: {
188
+ value: 'AUD',
189
+ label: 'AUD',
190
+ note: 'Australian dollar',
191
+ currency: 'aud',
192
+ },
193
+ filterMatchers: ['AUD', 'AUD', 'Australian dollar', undefined],
194
+ },
195
+ ],
196
+ },
197
+ ]);
136
198
  });
137
199
 
138
200
  it('renders Select component with undefined id when id is not provided', () => {
139
- const select = component.find('Select');
201
+ const select = component.find('SelectInput');
140
202
 
141
203
  expect(select.prop('id')).toBeUndefined();
142
204
  });
143
205
 
144
206
  it('shows the currently active currency as active and hides its note', () => {
145
- expect(currencySelect().prop('selected')).toStrictEqual({
207
+ expect(currencySelect().prop('value')).toStrictEqual({
146
208
  value: 'EUR',
147
- label: (
148
- <Title as="span" type="title-subsection" className="tw-money-input__text">
149
- EUR
150
- </Title>
151
- ),
152
- note: null,
209
+ label: 'EUR',
210
+ note: 'Euro',
153
211
  currency: 'eur',
154
212
  searchable: 'Spain, Germany, France, Austria, Estonia',
155
213
  });
@@ -173,22 +231,7 @@ describe('Money Input', () => {
173
231
  });
174
232
  });
175
233
 
176
- it('configures the select visually correctly', () => {
177
- const options = currencySelect().props();
178
-
179
- expect(options.required).toBe(true);
180
- expect(options.dropdownWidth).toBe('lg');
181
- expect(options.inverse).toBe(true);
182
- });
183
-
184
234
  describe('when searching', () => {
185
- it('passes search value to currency select', () => {
186
- expect(currencySelect().prop('searchValue')).toBe('');
187
-
188
- searchCurrencies('EEK');
189
- expect(currencySelect().prop('searchValue')).toBe('EEK');
190
- });
191
-
192
235
  it('hides headers', () => {
193
236
  currencies = [
194
237
  { header: 'A currency' },
@@ -197,12 +240,43 @@ describe('Money Input', () => {
197
240
  { value: 'EUR', label: 'Euro' },
198
241
  ];
199
242
  component.setProps({ currencies });
200
- expect(displayedCurrencies()).toStrictEqual(currencies);
243
+ expect(displayedCurrencies()).toStrictEqual([
244
+ {
245
+ type: 'group',
246
+ label: 'A currency',
247
+ options: [
248
+ {
249
+ type: 'option',
250
+ value: { value: 'GBP', label: 'British pound' },
251
+ filterMatchers: ['GBP', 'British pound', undefined, undefined],
252
+ },
253
+ ],
254
+ },
255
+ {
256
+ type: 'group',
257
+ label: 'Another currency',
258
+ options: [
259
+ {
260
+ type: 'option',
261
+ value: { value: 'EUR', label: 'Euro' },
262
+ filterMatchers: ['EUR', 'Euro', undefined, undefined],
263
+ },
264
+ ],
265
+ },
266
+ ]);
201
267
 
202
268
  searchCurrencies('O');
203
269
  expect(displayedCurrencies()).toStrictEqual([
204
- { value: 'GBP', label: 'British pound' },
205
- { value: 'EUR', label: 'Euro' },
270
+ {
271
+ type: 'option',
272
+ value: { value: 'GBP', label: 'British pound' },
273
+ filterMatchers: ['GBP', 'British pound', undefined, undefined],
274
+ },
275
+ {
276
+ type: 'option',
277
+ value: { value: 'EUR', label: 'Euro' },
278
+ filterMatchers: ['EUR', 'Euro', undefined, undefined],
279
+ },
206
280
  ]);
207
281
  });
208
282
 
@@ -212,10 +286,27 @@ describe('Money Input', () => {
212
286
  { value: 'EUR', label: 'Euro' },
213
287
  ];
214
288
  component.setProps({ currencies });
215
- expect(displayedCurrencies()).toStrictEqual(currencies);
289
+ expect(displayedCurrencies()).toStrictEqual([
290
+ {
291
+ type: 'option',
292
+ value: { value: 'GBP', label: 'British pound' },
293
+ filterMatchers: ['GBP', 'British pound', undefined, undefined],
294
+ },
295
+ {
296
+ type: 'option',
297
+ value: { value: 'EUR', label: 'Euro' },
298
+ filterMatchers: ['EUR', 'Euro', undefined, undefined],
299
+ },
300
+ ]);
216
301
 
217
302
  searchCurrencies('P');
218
- expect(displayedCurrencies()).toStrictEqual([{ value: 'GBP', label: 'British pound' }]);
303
+ expect(displayedCurrencies()).toStrictEqual([
304
+ {
305
+ type: 'option',
306
+ value: { value: 'GBP', label: 'British pound' },
307
+ filterMatchers: ['GBP', 'British pound', undefined, undefined],
308
+ },
309
+ ]);
219
310
  });
220
311
 
221
312
  it('searches by note', () => {
@@ -224,10 +315,27 @@ describe('Money Input', () => {
224
315
  { value: 'EUR', note: 'Other money' },
225
316
  ];
226
317
  component.setProps({ currencies });
227
- expect(displayedCurrencies()).toStrictEqual(currencies);
318
+ expect(displayedCurrencies()).toStrictEqual([
319
+ {
320
+ type: 'option',
321
+ value: { value: 'GBP', note: 'Queen money' },
322
+ filterMatchers: ['GBP', undefined, 'Queen money', undefined],
323
+ },
324
+ {
325
+ type: 'option',
326
+ value: { value: 'EUR', note: 'Other money' },
327
+ filterMatchers: ['EUR', undefined, 'Other money', undefined],
328
+ },
329
+ ]);
228
330
 
229
331
  searchCurrencies('Other');
230
- expect(displayedCurrencies()).toStrictEqual([{ value: 'EUR', note: 'Other money' }]);
332
+ expect(displayedCurrencies()).toStrictEqual([
333
+ {
334
+ type: 'option',
335
+ value: { value: 'EUR', note: 'Other money' },
336
+ filterMatchers: ['EUR', undefined, 'Other money', undefined],
337
+ },
338
+ ]);
231
339
  });
232
340
 
233
341
  it('searches by searchable string', () => {
@@ -236,11 +344,26 @@ describe('Money Input', () => {
236
344
  { value: 'EUR', searchable: 'Europe' },
237
345
  ];
238
346
  component.setProps({ currencies });
239
- expect(displayedCurrencies()).toStrictEqual(currencies);
347
+ expect(displayedCurrencies()).toStrictEqual([
348
+ {
349
+ type: 'option',
350
+ value: { value: 'GBP', searchable: 'Great Britain, United Kingdom' },
351
+ filterMatchers: ['GBP', undefined, undefined, 'Great Britain, United Kingdom'],
352
+ },
353
+ {
354
+ type: 'option',
355
+ value: { value: 'EUR', searchable: 'Europe' },
356
+ filterMatchers: ['EUR', undefined, undefined, 'Europe'],
357
+ },
358
+ ]);
240
359
 
241
360
  searchCurrencies('Britain');
242
361
  expect(displayedCurrencies()).toStrictEqual([
243
- { value: 'GBP', searchable: 'Great Britain, United Kingdom' },
362
+ {
363
+ type: 'option',
364
+ value: { value: 'GBP', searchable: 'Great Britain, United Kingdom' },
365
+ filterMatchers: ['GBP', undefined, undefined, 'Great Britain, United Kingdom'],
366
+ },
244
367
  ]);
245
368
  });
246
369
 
@@ -249,51 +372,73 @@ describe('Money Input', () => {
249
372
  { value: 'GBP', searchable: 'Great Britain, United Kingdom' },
250
373
  { value: 'EUR', searchable: 'Europe' },
251
374
  ];
252
- const CUSTOM_ACTION = 'CUSTOM_ACTION';
253
375
  component.setProps({
254
376
  currencies,
255
377
  onCustomAction: jest.fn(),
256
378
  customActionLabel: 'I am a label',
257
379
  });
258
380
  expect(displayedCurrencies()).toStrictEqual([
259
- ...currencies,
260
- { value: CUSTOM_ACTION, label: 'I am a label' },
381
+ {
382
+ type: 'option',
383
+ value: { value: 'GBP', searchable: 'Great Britain, United Kingdom' },
384
+ filterMatchers: ['GBP', undefined, undefined, 'Great Britain, United Kingdom'],
385
+ },
386
+ {
387
+ type: 'option',
388
+ value: { value: 'EUR', searchable: 'Europe' },
389
+ filterMatchers: ['EUR', undefined, undefined, 'Europe'],
390
+ },
261
391
  ]);
262
392
 
263
393
  searchCurrencies('Britain');
264
394
  expect(displayedCurrencies()).toStrictEqual([
265
- { value: 'GBP', searchable: 'Great Britain, United Kingdom' },
266
- { value: CUSTOM_ACTION, label: 'I am a label' },
395
+ {
396
+ type: 'option',
397
+ value: { value: 'GBP', searchable: 'Great Britain, United Kingdom' },
398
+ filterMatchers: ['GBP', undefined, undefined, 'Great Britain, United Kingdom'],
399
+ },
267
400
  ]);
268
401
 
269
402
  searchCurrencies('Random search string');
270
- expect(displayedCurrencies()).toStrictEqual([
271
- { value: CUSTOM_ACTION, label: 'I am a label' },
272
- ]);
403
+ expect(displayedCurrencies()).toHaveLength(0);
404
+ const footerNode = shallow(getFooter()()).find('div');
405
+ expect(footerNode).not.toBeNull();
273
406
  });
274
407
 
275
408
  it('sorts labels to first', () => {
276
409
  searchCurrencies('au');
277
410
  expect(displayedCurrencies()).toStrictEqual([
278
411
  {
279
- value: 'AUD',
280
- label: 'AUD',
281
- note: 'Australian dollar',
282
- currency: 'aud',
412
+ type: 'option',
413
+ value: {
414
+ value: 'AUD',
415
+ label: 'AUD',
416
+ note: 'Australian dollar',
417
+ currency: 'aud',
418
+ },
419
+ filterMatchers: ['AUD', 'AUD', 'Australian dollar', undefined],
283
420
  },
284
421
  {
285
- value: 'EUR',
286
- label: 'EUR',
287
- note: 'Euro',
288
- currency: 'eur',
289
- searchable: 'Spain, Germany, France, Austria, Estonia',
422
+ type: 'option',
423
+ value: {
424
+ value: 'EUR',
425
+ label: 'EUR',
426
+ note: 'Euro',
427
+ currency: 'eur',
428
+ searchable: 'Spain, Germany, France, Austria, Estonia',
429
+ },
430
+ filterMatchers: ['EUR', 'EUR', 'Euro', 'Spain, Germany, France, Austria, Estonia'],
290
431
  },
291
432
  {
292
- value: 'USD',
293
- label: 'USD',
294
- note: 'United States dollar',
295
- currency: 'usd',
296
- searchable: 'Hong Kong, Saudi Arabia',
433
+ type: 'option',
434
+ value: {
435
+ value: 'USD',
436
+ label: 'USD',
437
+ note: 'United States dollar',
438
+ currency: 'usd',
439
+ searchable: 'Hong Kong, Saudi Arabia',
440
+ },
441
+ filterMatchers: ['USD', 'USD', 'United States dollar', 'Hong Kong, Saudi Arabia'],
297
442
  },
298
443
  ]);
299
444
  });
@@ -392,7 +537,6 @@ describe('Money Input', () => {
392
537
  expect(currencySelect()).toHaveLength(0);
393
538
  expect(fixedCurrencyDisplay()).toHaveLength(1);
394
539
  expect(component.find(Title).props().children).toBe('EEK');
395
- expect(component.find('.currency-flag').hasClass('currency-flag-eek')).toBe(true);
396
540
  });
397
541
 
398
542
  it('shows fixed currency view when no function is passed to onCurrencyChange prop', () => {
@@ -411,13 +555,11 @@ describe('Money Input', () => {
411
555
 
412
556
  ['md', 'lg'].forEach((size) => {
413
557
  component.setProps({ size });
414
- expect(component.find('.tw-money-input__keyline')).toHaveLength(1);
415
- expect(component.find('.currency-flag')).toHaveLength(1);
558
+ expect(component.find('.money-input-currency-flag')).toHaveLength(1);
416
559
  });
417
560
 
418
561
  component.setProps({ size: 'sm' });
419
- expect(component.find('.tw-money-input__keyline')).toHaveLength(0);
420
- expect(component.find('.currency-flag')).toHaveLength(0);
562
+ expect(component.find('.money-input-currency-flag')).toHaveLength(0);
421
563
  });
422
564
 
423
565
  it('amount input will be disabled when there is no onAmountChange prop', () => {
@@ -437,18 +579,24 @@ describe('Money Input', () => {
437
579
 
438
580
  it('uses the passed in search placeholder', () => {
439
581
  component.setProps({ searchPlaceholder: 'a placeholder' });
440
- expect(currencySelect().prop('searchPlaceholder')).toBe('a placeholder');
582
+ expect(currencySelect().prop('filterPlaceholder')).toBe('a placeholder');
441
583
  });
442
584
 
443
585
  it('clears the search value when selecting an option', () => {
586
+ const onSearchChange = jest.fn();
587
+ component.setProps({ onSearchChange });
444
588
  searchCurrencies('eur');
445
- expect(currencySelect().prop('options')).toHaveLength(1);
446
- expect(currencySelect().prop('searchValue')).toBe('eur');
589
+ expect(onSearchChange).toHaveBeenLastCalledWith({
590
+ searchQuery: 'eur',
591
+ filteredOptions: [props.currencies[1]],
592
+ });
447
593
 
448
594
  currencySelect().prop('onChange')(props.currencies[1]);
449
595
  component.update();
450
- expect(currencySelect().prop('options')).toHaveLength(7);
451
- expect(currencySelect().prop('searchValue')).toBe('');
596
+ expect(onSearchChange).toHaveBeenLastCalledWith({
597
+ searchQuery: '',
598
+ filteredOptions: [...props.currencies],
599
+ });
452
600
  });
453
601
 
454
602
  it('shows custom action last when onCustomAction prop is passed to MoneyInput', () => {
@@ -456,21 +604,25 @@ describe('Money Input', () => {
456
604
  { value: 'GBP', searchable: 'Great Britain, United Kingdom' },
457
605
  { value: 'EUR', searchable: 'Europe' },
458
606
  ];
607
+ const onCustomActionMock = jest.fn();
459
608
  component.setProps({
460
609
  currencies,
461
- onCustomAction: jest.fn(),
610
+ onCustomAction: onCustomActionMock,
462
611
  customActionLabel: 'Label boy',
463
612
  });
464
613
 
465
- expect(displayedCurrencies()).toStrictEqual([
466
- ...currencies,
467
- { value: 'CUSTOM_ACTION', label: 'Label boy' },
468
- ]);
614
+ const options = displayedCurrencies();
469
615
 
470
- expect(displayedCurrencies()[displayedCurrencies().length - 1]).toStrictEqual({
471
- value: 'CUSTOM_ACTION',
472
- label: 'Label boy',
473
- });
616
+ expect(options).toHaveLength(2);
617
+ expect(options[0].value).toStrictEqual(currencies[0]);
618
+ expect(options[1].value).toStrictEqual(currencies[1]);
619
+
620
+ const footerNode = shallow(getFooter()()).find('div');
621
+
622
+ expect(footerNode.prop('role')).toBe('button');
623
+ expect(onCustomActionMock).toHaveBeenCalledTimes(0);
624
+ footerNode.simulate('click');
625
+ expect(onCustomActionMock).toHaveBeenCalledTimes(1);
474
626
  });
475
627
 
476
628
  it('calls onCustomAction callback when custom action is selected', () => {
@@ -479,7 +631,9 @@ describe('Money Input', () => {
479
631
  expect(onCustomAction).not.toHaveBeenCalled();
480
632
  expect(props.onCurrencyChange).not.toHaveBeenCalled();
481
633
 
482
- currencySelect().prop('onChange')({ value: 'CUSTOM_ACTION', label: '' });
634
+ const footerNode = shallow(getFooter()()).find('div');
635
+ expect(onCustomAction).toHaveBeenCalledTimes(0);
636
+ footerNode.simulate('click');
483
637
  expect(onCustomAction).toHaveBeenCalledTimes(1);
484
638
  expect(props.onCurrencyChange).toHaveBeenCalledTimes(0);
485
639
  });
@@ -548,7 +702,8 @@ describe('Money Input', () => {
548
702
  filteredOptions: [getCurrencyByValue('EUR')],
549
703
  });
550
704
 
551
- currencySelect().prop('onChange')({ value: 'CUSTOM_ACTION' });
705
+ const footerNode = shallow(getFooter()()).find('div');
706
+ footerNode.simulate('click');
552
707
  expect(onCustomAction).toHaveBeenCalledTimes(1);
553
708
  expect(onSearchChange).toHaveBeenLastCalledWith({
554
709
  searchQuery: '',
@@ -557,33 +712,6 @@ describe('Money Input', () => {
557
712
  });
558
713
  });
559
714
 
560
- describe('when typing', () => {
561
- let rtlComponent;
562
- const { formatAmount } = jest.requireActual('./currencyFormatting');
563
- beforeAll(() => {
564
- numberFormatting.formatAmount = formatAmount;
565
- });
566
-
567
- beforeEach(() => {
568
- rtlComponent = render(<MoneyInput {...props} amount={null} />);
569
- jest.clearAllMocks();
570
- });
571
-
572
- it.each([
573
- ['asd', ''],
574
- ['1a2s3d', '123'],
575
- ['±!@#$^*_+?><', ''],
576
- ['1±!@#$^*,_+?><2', '1,2'],
577
- ['12,3', '12,3'],
578
- ['12.3', '12.3'],
579
- ])("ignores the letters when typed '%s' and shows '%s'", (testValue, expectedValue) => {
580
- const { container } = rtlComponent;
581
- const input = container.querySelector('input');
582
- userEvent.type(input, testValue);
583
- expect(input).toHaveValue(expectedValue);
584
- });
585
- });
586
-
587
715
  describe('when passed selectProps', () => {
588
716
  beforeEach(() => {
589
717
  component = shallow(
@@ -599,7 +727,7 @@ describe('Money Input', () => {
599
727
  });
600
728
 
601
729
  it('renders Select component with expected props', () => {
602
- const select = component.find('Select');
730
+ const select = component.find('SelectInput');
603
731
 
604
732
  expect(select.prop('buttonProps')).toStrictEqual({
605
733
  'aria-label': 'mock-button-label',
@@ -1,5 +1,9 @@
1
1
  import { Meta, StoryObj } from '@storybook/react';
2
2
  import { within, userEvent } from '@storybook/testing-library';
3
+ import { Lock } from '@transferwise/icons';
4
+ import React from 'react';
5
+
6
+ import Drawer from '../drawer';
3
7
 
4
8
  import MoneyInput from '.';
5
9
 
@@ -41,6 +45,41 @@ const exampleCurrency = {
41
45
  currency: 'gbp',
42
46
  searchable: 'England, Scotland, Wales',
43
47
  },
48
+ usd: {
49
+ value: 'USD',
50
+ label: 'USD',
51
+ note: 'United States dollar',
52
+ currency: 'usd',
53
+ searchable: 'Hong Kong, Saudi Arabia',
54
+ },
55
+ hkd: {
56
+ value: 'HKD',
57
+ label: 'HKD',
58
+ note: 'Hong Kong',
59
+ currency: 'hkd',
60
+ searchable: 'Hong Kong, Saudi Arabia',
61
+ },
62
+ aud: {
63
+ value: 'AUD',
64
+ label: 'AUD',
65
+ note: 'Australia',
66
+ currency: 'aud',
67
+ searchable: 'Kenguru',
68
+ },
69
+ cny: {
70
+ value: 'CNY',
71
+ label: 'CNY',
72
+ note: 'China',
73
+ currency: 'cny',
74
+ searchable: 'China',
75
+ },
76
+ jpy: {
77
+ value: 'JPY',
78
+ label: 'JPY',
79
+ note: 'Japan',
80
+ currency: 'jpy',
81
+ searchable: 'Japan',
82
+ },
44
83
  } as const;
45
84
 
46
85
  export const SingleCurrency: Story = {
@@ -53,14 +92,52 @@ export const SingleCurrency: Story = {
53
92
 
54
93
  export const MultipleCurrencies: Story = {
55
94
  args: {
95
+ addon: <Lock />,
56
96
  currencies: [
57
97
  {
58
98
  header: 'Popular currencies',
59
99
  },
60
100
  exampleCurrency.eur,
61
101
  exampleCurrency.gbp,
102
+ exampleCurrency.usd,
103
+ exampleCurrency.hkd,
104
+ { header: 'All currencies' },
105
+ exampleCurrency.eur,
106
+ exampleCurrency.gbp,
107
+ exampleCurrency.usd,
108
+ exampleCurrency.aud,
109
+ exampleCurrency.jpy,
62
110
  ],
63
- selectedCurrency: exampleCurrency.eur,
111
+ customActionLabel: 'Custom message with custom action',
112
+ onCustomAction: () => {
113
+ console.log('Custom action');
114
+ },
115
+ selectedCurrency: exampleCurrency.usd,
116
+ searchPlaceholder: 'Type a currency / country',
117
+ },
118
+ };
119
+
120
+ export const Convert: Story = {
121
+ render: (args) => {
122
+ // eslint-disable-next-line react-hooks/rules-of-hooks
123
+ const [drawerState, setDrawerState] = React.useState(true);
124
+ return (
125
+ <>
126
+ <div className="row">
127
+ <div className="col-md-6 col-md-offset-3">
128
+ <label htmlFor={args.id as string}>Money inputs</label>
129
+ <MoneyInput {...args} {...MultipleCurrencies.args} disabled={false} />
130
+ </div>
131
+ <Drawer
132
+ open={drawerState}
133
+ headerTitle="This is the title of the drawer"
134
+ onClose={() => setDrawerState(!drawerState)}
135
+ >
136
+ <MoneyInput {...args} {...MultipleCurrencies.args} disabled={false} />
137
+ </Drawer>
138
+ </div>
139
+ </>
140
+ );
64
141
  },
65
142
  };
66
143
 
package/src/ssr.spec.js CHANGED
@@ -12,7 +12,6 @@ const excluded = new Set([
12
12
  'useSnackbar',
13
13
  'useDirection',
14
14
  'useLayout',
15
- 'useScreenSize',
16
15
 
17
16
  // specific components
18
17
  'Provider',
@@ -2,7 +2,7 @@ import { within } from '@testing-library/react';
2
2
  import userEvent from '@testing-library/user-event';
3
3
 
4
4
  import { Status } from '../common';
5
- import { mockMatchMedia, render, screen, waitFor, waitForElementToBeRemoved } from '../test-utils';
5
+ import { render, screen, waitFor, waitForElementToBeRemoved } from '../test-utils';
6
6
 
7
7
  import UploadInput, { UploadInputProps } from './UploadInput';
8
8
  import { TEST_IDS as UPLOAD_BUTTON_TEST_IDS } from './uploadButton/UploadButton';
@@ -10,8 +10,6 @@ import { TEST_IDS as UPLOAD_ITEM_TEST_IDS } from './uploadItem/UploadItem';
10
10
 
11
11
  const spiedDateObject = jest.spyOn(global, 'Date');
12
12
 
13
- mockMatchMedia();
14
-
15
13
  describe('UploadInput', () => {
16
14
  const pngFile = new File(['foo'], 'foo.png', { type: 'image/png' });
17
15
  const jpgFile = new File(['foo'], 'foo.jpg', { type: 'image/jpeg' });