@transferwise/components 0.0.0-experimental-2aa3886 → 0.0.0-experimental-e783ca8
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/build/i18n/en.json +2 -0
- package/build/i18n/en.json.js +2 -0
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +2 -0
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.js +36 -2
- package/build/phoneNumberInput/PhoneNumberInput.js.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.messages.js +6 -0
- package/build/phoneNumberInput/PhoneNumberInput.messages.js.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.messages.mjs +6 -0
- package/build/phoneNumberInput/PhoneNumberInput.messages.mjs.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.mjs +36 -2
- package/build/phoneNumberInput/PhoneNumberInput.mjs.map +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.messages.d.ts +8 -0
- package/build/types/phoneNumberInput/PhoneNumberInput.messages.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +4 -0
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/build/types/uploadInput/UploadInput.d.ts.map +1 -1
- package/build/types/uploadInput/uploadItem/UploadItem.d.ts +1 -1
- package/build/types/uploadInput/uploadItem/UploadItem.d.ts.map +1 -1
- package/build/uploadInput/UploadInput.js +6 -55
- package/build/uploadInput/UploadInput.js.map +1 -1
- package/build/uploadInput/UploadInput.mjs +6 -55
- package/build/uploadInput/UploadInput.mjs.map +1 -1
- package/build/uploadInput/uploadItem/UploadItem.js +6 -12
- package/build/uploadInput/uploadItem/UploadItem.js.map +1 -1
- package/build/uploadInput/uploadItem/UploadItem.mjs +6 -12
- package/build/uploadInput/uploadItem/UploadItem.mjs.map +1 -1
- package/package.json +3 -6
- package/src/i18n/en.json +2 -0
- package/src/phoneNumberInput/PhoneNumberInput.messages.ts +8 -0
- package/src/phoneNumberInput/PhoneNumberInput.spec.tsx +77 -43
- package/src/phoneNumberInput/PhoneNumberInput.tsx +34 -2
- package/src/test-utils/jest.setup.ts +0 -4
- package/src/typeahead/Typeahead.spec.tsx +182 -0
- package/src/typeahead/typeaheadInput/TypeaheadInput.spec.tsx +103 -0
- package/src/typeahead/util/highlight.spec.tsx +43 -0
- package/src/uploadInput/UploadInput.tsx +8 -81
- package/src/uploadInput/uploadItem/UploadItem.tsx +6 -11
- package/src/typeahead/Typeahead.rtl.spec.tsx +0 -54
- package/src/typeahead/Typeahead.spec.js +0 -404
- package/src/typeahead/typeaheadInput/TypeaheadInput.spec.js +0 -74
- package/src/typeahead/typeaheadOption/TypeaheadOption.spec.js +0 -75
- package/src/typeahead/util/highlight.spec.js +0 -34
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
import { mount } from 'enzyme';
|
|
2
|
-
import doTimes from 'lodash.times';
|
|
3
|
-
import { mockMatchMedia } from '../test-utils';
|
|
4
|
-
|
|
5
|
-
import { InlineAlert } from '..';
|
|
6
|
-
import { Sentiment } from '../common';
|
|
7
|
-
import { fakeEvent, fakeKeyDownEventForKey } from '../common/fakeEvents';
|
|
8
|
-
|
|
9
|
-
import Typeahead from './Typeahead';
|
|
10
|
-
|
|
11
|
-
mockMatchMedia();
|
|
12
|
-
|
|
13
|
-
const defaultLocale = 'en-GB';
|
|
14
|
-
jest.mock('react-intl', () => {
|
|
15
|
-
const mockedIntl = {
|
|
16
|
-
locale: defaultLocale,
|
|
17
|
-
formatMessage: (id) => String(id),
|
|
18
|
-
};
|
|
19
|
-
return {
|
|
20
|
-
injectIntl: (Component) => (props) => <Component {...props} intl={mockedIntl} />,
|
|
21
|
-
defineMessages: (translations) => translations,
|
|
22
|
-
useIntl: () => mockedIntl,
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('Typeahead', () => {
|
|
27
|
-
let component;
|
|
28
|
-
let props;
|
|
29
|
-
const closeButton = () => component.find('.input-group-addon button');
|
|
30
|
-
const formGroup = () => component.find('.form-group');
|
|
31
|
-
const input = () => component.find('input');
|
|
32
|
-
const chip = () => component.find('.np-chip');
|
|
33
|
-
const option = () => component.find('.dropdown-item');
|
|
34
|
-
const menu = () => component.find('.dropdown');
|
|
35
|
-
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
props = {
|
|
38
|
-
id: 'test',
|
|
39
|
-
onChange: () => {},
|
|
40
|
-
name: 'test',
|
|
41
|
-
options: [
|
|
42
|
-
{
|
|
43
|
-
label: 'Test',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
label: 'Test1',
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
label: 'Test2',
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
label: 'Test3',
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
component = mount(<Typeahead {...props} />);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('renders addon', () => {
|
|
61
|
-
expect(component.find('#test-addon')).toHaveLength(0);
|
|
62
|
-
component.setProps({ addon: <div id="test-addon" /> });
|
|
63
|
-
expect(component.find('#test-addon')).toHaveLength(1);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('renders clear button', () => {
|
|
67
|
-
component.setProps({
|
|
68
|
-
clearable: true,
|
|
69
|
-
});
|
|
70
|
-
input().simulate('change', { target: { value: 'test' } });
|
|
71
|
-
|
|
72
|
-
expect(closeButton()).toHaveLength(1);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('splits pasted value correctly', () => {
|
|
76
|
-
const chips = ['test', 'test2', 'test3'];
|
|
77
|
-
const event = {
|
|
78
|
-
preventDefault: jest.fn(),
|
|
79
|
-
clipboardData: {
|
|
80
|
-
getData: () => chips.join(', '),
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
component.setProps({
|
|
85
|
-
allowNew: true,
|
|
86
|
-
multiple: true,
|
|
87
|
-
chipSeparators: [',', ' '],
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
input().simulate('paste', event);
|
|
91
|
-
const renderedChips = chip().map((chipNode) => chipNode.text());
|
|
92
|
-
|
|
93
|
-
expect(renderedChips.every((label, idx) => chips[idx] === label)).toBe(true);
|
|
94
|
-
expect(renderedChips).toHaveLength(chips.length);
|
|
95
|
-
expect(event.preventDefault).toHaveBeenCalledTimes(1);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('removes last selected value when backspace clicked on empty input', () => {
|
|
99
|
-
const event = {
|
|
100
|
-
key: 'Backspace',
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
component.setProps({
|
|
104
|
-
multiple: true,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
expect(chip()).toHaveLength(0);
|
|
108
|
-
|
|
109
|
-
input().simulate('change', { target: { value: 'test' } });
|
|
110
|
-
option().at(0).simulate('click', fakeEvent());
|
|
111
|
-
|
|
112
|
-
expect(chip()).toHaveLength(1);
|
|
113
|
-
|
|
114
|
-
input().simulate('keyDown', event);
|
|
115
|
-
|
|
116
|
-
expect(chip()).toHaveLength(0);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('does not remove last selected value when backspace clicked on non-empty input', () => {
|
|
120
|
-
const event = {
|
|
121
|
-
key: 'Backspace',
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
component.setProps({
|
|
125
|
-
multiple: true,
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
expect(chip()).toHaveLength(0);
|
|
129
|
-
|
|
130
|
-
input().simulate('change', { target: { value: 'test' } });
|
|
131
|
-
option().at(0).simulate('click', fakeEvent());
|
|
132
|
-
|
|
133
|
-
expect(chip()).toHaveLength(1);
|
|
134
|
-
|
|
135
|
-
input().simulate('change', { target: { value: 'test' } });
|
|
136
|
-
input().simulate('keyDown', event);
|
|
137
|
-
|
|
138
|
-
expect(chip()).toHaveLength(1);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('adds new value as selected and clears the input when separator is entered', () => {
|
|
142
|
-
const event = {
|
|
143
|
-
key: ',',
|
|
144
|
-
preventDefault: jest.fn(),
|
|
145
|
-
};
|
|
146
|
-
const text = 'test';
|
|
147
|
-
|
|
148
|
-
component.setProps({
|
|
149
|
-
multiple: true,
|
|
150
|
-
allowNew: true,
|
|
151
|
-
showSuggestions: false,
|
|
152
|
-
chipSeparators: [','],
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
input().simulate('change', { target: { value: text } });
|
|
156
|
-
input().simulate('keyDown', event);
|
|
157
|
-
|
|
158
|
-
expect(chip().text()).toStrictEqual(text);
|
|
159
|
-
expect(event.preventDefault).toHaveBeenCalledTimes(1);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('adds new value as selected and clears the input when Enter is pressed', () => {
|
|
163
|
-
const event = {
|
|
164
|
-
key: 'Enter',
|
|
165
|
-
preventDefault: jest.fn(),
|
|
166
|
-
};
|
|
167
|
-
const text = 'test';
|
|
168
|
-
|
|
169
|
-
component.setProps({
|
|
170
|
-
multiple: true,
|
|
171
|
-
allowNew: true,
|
|
172
|
-
showSuggestions: false,
|
|
173
|
-
chipSeparators: [','],
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
input().simulate('change', { target: { value: text } });
|
|
177
|
-
input().simulate('keyDown', event);
|
|
178
|
-
|
|
179
|
-
expect(chip().text()).toStrictEqual(text);
|
|
180
|
-
expect(event.preventDefault).toHaveBeenCalledTimes(1);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('adds new value as selected and clears the input when Tab is pressed', () => {
|
|
184
|
-
const event = {
|
|
185
|
-
key: 'Tab',
|
|
186
|
-
preventDefault: jest.fn(),
|
|
187
|
-
};
|
|
188
|
-
const text = 'test';
|
|
189
|
-
|
|
190
|
-
component.setProps({
|
|
191
|
-
multiple: true,
|
|
192
|
-
allowNew: true,
|
|
193
|
-
showSuggestions: false,
|
|
194
|
-
chipSeparators: [','],
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
input().simulate('change', { target: { value: text } });
|
|
198
|
-
input().simulate('keyDown', event);
|
|
199
|
-
|
|
200
|
-
expect(chip().text()).toStrictEqual(text);
|
|
201
|
-
expect(event.preventDefault).toHaveBeenCalledTimes(1);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('clears typeahead when clear button is clicked', () => {
|
|
205
|
-
const event = {
|
|
206
|
-
key: ',',
|
|
207
|
-
preventDefault: jest.fn(),
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const query = 'test';
|
|
211
|
-
|
|
212
|
-
component.setProps({
|
|
213
|
-
multiple: true,
|
|
214
|
-
allowNew: true,
|
|
215
|
-
showSuggestions: false,
|
|
216
|
-
chipSeparators: [','],
|
|
217
|
-
clearable: true,
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
input().simulate('change', { target: { value: query } });
|
|
221
|
-
input().simulate('keyDown', event);
|
|
222
|
-
input().simulate('change', { target: { value: query } });
|
|
223
|
-
|
|
224
|
-
expect(chip()).toHaveLength(1);
|
|
225
|
-
expect(input().getDOMNode().value).toBe(query);
|
|
226
|
-
|
|
227
|
-
closeButton().simulate('click', fakeEvent());
|
|
228
|
-
expect(chip()).toHaveLength(0);
|
|
229
|
-
expect(input().getDOMNode().value).toBe('');
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('moves selected items when down and up keys pressed', () => {
|
|
233
|
-
doTimes(3, () => input().simulate('keyDown', fakeKeyDownEventForKey('ArrowDown')));
|
|
234
|
-
|
|
235
|
-
expect(option().at(2).parent().is('.tw-dropdown-item--focused')).toBe(true);
|
|
236
|
-
|
|
237
|
-
input().simulate('keyDown', fakeKeyDownEventForKey('ArrowUp'));
|
|
238
|
-
expect(option().at(1).parent().is('.tw-dropdown-item--focused')).toBe(true);
|
|
239
|
-
|
|
240
|
-
doTimes(5, () => input().simulate('keyDown', fakeKeyDownEventForKey('ArrowDown')));
|
|
241
|
-
expect(option().last().parent().is('.tw-dropdown-item--focused')).toBe(true);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('adds new value as selected and clears the input when no option is highlighted and enter is pressed', () => {
|
|
245
|
-
const event = {
|
|
246
|
-
key: 'Enter',
|
|
247
|
-
preventDefault: jest.fn(),
|
|
248
|
-
};
|
|
249
|
-
const text = 'test';
|
|
250
|
-
|
|
251
|
-
component.setProps({
|
|
252
|
-
multiple: true,
|
|
253
|
-
allowNew: true,
|
|
254
|
-
chipSeparators: [','],
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
input().simulate('change', { target: { value: text } });
|
|
258
|
-
input().simulate('keyDown', event);
|
|
259
|
-
|
|
260
|
-
expect(chip().text()).toStrictEqual(text);
|
|
261
|
-
expect(event.preventDefault).toHaveBeenCalledTimes(1);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('sets aria-activedescendant correctly based on focus', () => {
|
|
265
|
-
const inputElement = input().getDOMNode();
|
|
266
|
-
|
|
267
|
-
doTimes(3, () => input().simulate('keyDown', fakeKeyDownEventForKey('ArrowDown')));
|
|
268
|
-
|
|
269
|
-
expect(inputElement).toHaveAttribute('aria-activedescendant', 'menu-test option-Test2');
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it('displays alert when alert is provided and chips are valid or alert type is error', () => {
|
|
273
|
-
const event = {
|
|
274
|
-
key: 'Enter',
|
|
275
|
-
preventDefault: jest.fn(),
|
|
276
|
-
};
|
|
277
|
-
const text = 'test';
|
|
278
|
-
|
|
279
|
-
expect(component.find(InlineAlert)).toHaveLength(0);
|
|
280
|
-
expect(formGroup().hasClass('has-error')).toBe(false);
|
|
281
|
-
component.setProps({
|
|
282
|
-
validateChip: () => {
|
|
283
|
-
return false;
|
|
284
|
-
},
|
|
285
|
-
allowNew: true,
|
|
286
|
-
alert: {
|
|
287
|
-
message: 'test',
|
|
288
|
-
type: Sentiment.ERROR,
|
|
289
|
-
},
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
expect(formGroup().hasClass('has-error')).toBe(true);
|
|
293
|
-
expect(component.find(InlineAlert)).toHaveLength(1);
|
|
294
|
-
|
|
295
|
-
input().simulate('change', { target: { value: text } });
|
|
296
|
-
input().simulate('keyDown', event);
|
|
297
|
-
|
|
298
|
-
expect(formGroup().hasClass('has-error')).toBe(true);
|
|
299
|
-
expect(component.find(InlineAlert)).toHaveLength(1);
|
|
300
|
-
component.setProps({
|
|
301
|
-
alert: {
|
|
302
|
-
message: 'test',
|
|
303
|
-
type: Sentiment.WARNING,
|
|
304
|
-
},
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
expect(formGroup().hasClass('has-error')).toBe(true);
|
|
308
|
-
expect(component.find(InlineAlert)).toHaveLength(0);
|
|
309
|
-
|
|
310
|
-
closeButton().simulate('click', fakeEvent());
|
|
311
|
-
|
|
312
|
-
expect(formGroup().hasClass('has-error')).toBe(false);
|
|
313
|
-
expect(formGroup().hasClass('has-warning')).toBe(true);
|
|
314
|
-
expect(component.find(InlineAlert)).toHaveLength(1);
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it('allows supplying options with arbitrary data that will be included with the onChange callback', () => {
|
|
318
|
-
const text = 'test';
|
|
319
|
-
const options = [
|
|
320
|
-
{
|
|
321
|
-
label: 'label 1',
|
|
322
|
-
note: 'note-1',
|
|
323
|
-
secondary: 'secondary-1',
|
|
324
|
-
value: { id: 123, name: 'Neptune' },
|
|
325
|
-
},
|
|
326
|
-
];
|
|
327
|
-
let selectedOption;
|
|
328
|
-
|
|
329
|
-
component.setProps({
|
|
330
|
-
onChange: (selections) => {
|
|
331
|
-
selectedOption = selections[0];
|
|
332
|
-
},
|
|
333
|
-
options,
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
input().simulate('change', { target: { value: text } });
|
|
337
|
-
option().at(0).simulate('click', fakeEvent());
|
|
338
|
-
expect(selectedOption).toStrictEqual({
|
|
339
|
-
label: 'label 1',
|
|
340
|
-
note: 'note-1',
|
|
341
|
-
secondary: 'secondary-1',
|
|
342
|
-
value: { id: 123, name: 'Neptune' },
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
describe('menu', () => {
|
|
347
|
-
it('should render footer', () => {
|
|
348
|
-
component.setProps({
|
|
349
|
-
footer: <div id="footer">footer</div>,
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
expect(component.find('#footer')).toHaveLength(1);
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
it('renders all options', () => {
|
|
356
|
-
const options = option().map((optNode) => optNode.text());
|
|
357
|
-
expect(options).toHaveLength(props.options.length);
|
|
358
|
-
expect(options.every((label, i) => label === props.options[i].label)).toBe(true);
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
it('renders dropdown-menu if has options', () => {
|
|
362
|
-
expect(component.find('.dropdown-menu')).toHaveLength(1);
|
|
363
|
-
component.setProps({ options: [] });
|
|
364
|
-
expect(component.find('.dropdown-menu')).toHaveLength(0);
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
it('does not render new option if showNewEntry is false', () => {
|
|
368
|
-
component.setProps({
|
|
369
|
-
allowNew: true,
|
|
370
|
-
showNewEntry: false,
|
|
371
|
-
});
|
|
372
|
-
input().simulate('change', { target: { value: 'check' } });
|
|
373
|
-
|
|
374
|
-
const options = option().map((optNode) => optNode.text());
|
|
375
|
-
expect(options).toHaveLength(props.options.length);
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
it('renders new option if showNewEntry is true', () => {
|
|
379
|
-
component.setProps({
|
|
380
|
-
allowNew: true,
|
|
381
|
-
showNewEntry: true,
|
|
382
|
-
});
|
|
383
|
-
input().simulate('change', { target: { value: 'check' } });
|
|
384
|
-
|
|
385
|
-
const options = option().map((optNode) => optNode.text());
|
|
386
|
-
expect(options).toHaveLength(props.options.length + 1);
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
it('does not show options if query is too short', () => {
|
|
390
|
-
expect(menu().is('.open')).toBe(false);
|
|
391
|
-
input().simulate('change', { target: { value: 'test' } });
|
|
392
|
-
expect(menu().is('.open')).toBe(true);
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it('sets aria-expanded to true when options are shown', () => {
|
|
396
|
-
expect(input().prop('aria-expanded')).toBe(false);
|
|
397
|
-
// we don't want aria-expanded to be true on focus or before 3 characters are entered (that's when the menu is shown)
|
|
398
|
-
input().simulate('change', { target: { value: 'aa' } });
|
|
399
|
-
expect(input().prop('aria-expanded')).toBe(false);
|
|
400
|
-
input().simulate('change', { target: { value: 'aaa' } });
|
|
401
|
-
expect(input().prop('aria-expanded')).toBe(true);
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
|
-
|
|
3
|
-
import { Input } from '../../inputs/Input';
|
|
4
|
-
|
|
5
|
-
import TypeaheadInput from './TypeaheadInput';
|
|
6
|
-
|
|
7
|
-
describe('Typeahead input', () => {
|
|
8
|
-
let component;
|
|
9
|
-
let props;
|
|
10
|
-
|
|
11
|
-
const inputWrapper = () => component.find('.typeahead__input-wrapper');
|
|
12
|
-
const input = () => component.find(Input);
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
props = {
|
|
16
|
-
name: 'test',
|
|
17
|
-
typeaheadId: 'test',
|
|
18
|
-
multiple: false,
|
|
19
|
-
value: '',
|
|
20
|
-
renderChip: jest.fn(),
|
|
21
|
-
onKeyDown: jest.fn(),
|
|
22
|
-
onFocus: jest.fn(),
|
|
23
|
-
onPaste: jest.fn(),
|
|
24
|
-
onChange: jest.fn(),
|
|
25
|
-
autoComplete: 'off',
|
|
26
|
-
selected: [],
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
component = shallow(<TypeaheadInput {...props} />);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('renders single input when multiple is false', () => {
|
|
33
|
-
expect(component.children()).toHaveLength(0);
|
|
34
|
-
expect(component.is(Input)).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('renders chips when provided', () => {
|
|
38
|
-
const selected = [{ label: 'test1' }, { label: 'test2' }];
|
|
39
|
-
component.setProps({
|
|
40
|
-
multiple: true,
|
|
41
|
-
selected,
|
|
42
|
-
renderChip: jest.fn(({ label }, idx) => <span key={idx}>{label}</span>),
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
expect(inputWrapper().find('span')).toHaveLength(selected.length);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('adds aria-controls prop if dropdown is open', () => {
|
|
49
|
-
expect(component.prop('aria-controls')).toBeUndefined();
|
|
50
|
-
component.setProps({ dropdownOpen: true });
|
|
51
|
-
expect(component.prop('aria-controls')).toBe('menu-test');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('passes all callbacks to input', () => {
|
|
55
|
-
const event = {};
|
|
56
|
-
const extraProps = {
|
|
57
|
-
multiple: true,
|
|
58
|
-
value: '',
|
|
59
|
-
onKeyDown: jest.fn(),
|
|
60
|
-
onBlur: jest.fn(),
|
|
61
|
-
onFocus: jest.fn(),
|
|
62
|
-
onPaste: jest.fn(),
|
|
63
|
-
};
|
|
64
|
-
component.setProps(extraProps);
|
|
65
|
-
|
|
66
|
-
input().simulate('focus', event);
|
|
67
|
-
input().simulate('paste', event);
|
|
68
|
-
input().simulate('keyDown', event);
|
|
69
|
-
const inputProps = input().props();
|
|
70
|
-
expect(inputProps.onKeyDown).toHaveBeenCalledWith(event);
|
|
71
|
-
expect(inputProps.onFocus).toHaveBeenCalledWith(event);
|
|
72
|
-
expect(inputProps.onPaste).toHaveBeenCalledWith(event);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { shallow, mount } from 'enzyme';
|
|
2
|
-
|
|
3
|
-
import { fakeEvent } from '../../common/fakeEvents';
|
|
4
|
-
|
|
5
|
-
import TypeaheadOption from './TypeaheadOption';
|
|
6
|
-
import Highlight from '../util/highlight';
|
|
7
|
-
|
|
8
|
-
describe('Typeahead Option', () => {
|
|
9
|
-
let props;
|
|
10
|
-
let component;
|
|
11
|
-
|
|
12
|
-
const labelHighlight = () => component.find(Highlight);
|
|
13
|
-
const noteSpan = () => component.find('.np-text-body-default.m-l-1');
|
|
14
|
-
const secondaryTextHighlight = () => component.find('.np-text-body-default.text-ellipsis > span');
|
|
15
|
-
const dropdownItem = () => component.find('.dropdown-item');
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
props = {
|
|
19
|
-
option: {
|
|
20
|
-
label: 'test',
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
component = mount(<TypeaheadOption {...props} />);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('renders a label', () => {
|
|
28
|
-
const label = 'test';
|
|
29
|
-
component.setProps({ option: { label } });
|
|
30
|
-
expect(labelHighlight().text()).toStrictEqual(label);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('renders a note', () => {
|
|
34
|
-
const label = 'test';
|
|
35
|
-
const note = 'test note';
|
|
36
|
-
component.setProps({ option: { label, note } });
|
|
37
|
-
expect(noteSpan().text()).toStrictEqual(note);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('renders a seconday text', () => {
|
|
41
|
-
const label = 'test';
|
|
42
|
-
const secondary = 'test note';
|
|
43
|
-
component.setProps({ option: { label, secondary } });
|
|
44
|
-
expect(secondaryTextHighlight().text()).toStrictEqual(secondary);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('highlights when selected', () => {
|
|
48
|
-
component = shallow(<TypeaheadOption {...props} />);
|
|
49
|
-
component.setProps({
|
|
50
|
-
selected: true,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
expect(component.is('.tw-dropdown-item--focused')).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('expect aria-selected to be true', () => {
|
|
57
|
-
component = shallow(<TypeaheadOption {...props} />);
|
|
58
|
-
component.setProps({
|
|
59
|
-
selected: true,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
expect(component.prop('aria-selected')).toBe('true');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('calls onClick when clicked', () => {
|
|
66
|
-
const onClick = jest.fn();
|
|
67
|
-
component.setProps({
|
|
68
|
-
onClick,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
dropdownItem().simulate('click', fakeEvent);
|
|
72
|
-
|
|
73
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { mount } from 'enzyme';
|
|
2
|
-
|
|
3
|
-
import Highlight from './highlight';
|
|
4
|
-
|
|
5
|
-
describe('Typeahead input', () => {
|
|
6
|
-
const highlighted = (node) => node.find('strong');
|
|
7
|
-
const getTextFromNodes = (nodes) => nodes.reduce((value, node) => value + node.text(), '');
|
|
8
|
-
|
|
9
|
-
it('highlights part of label that matches the query', () => {
|
|
10
|
-
const query = 'test';
|
|
11
|
-
const label = `this is a ${query} label`;
|
|
12
|
-
const result = mount(<Highlight value={label} query={query} />);
|
|
13
|
-
|
|
14
|
-
expect(highlighted(result).text()).toStrictEqual(query);
|
|
15
|
-
|
|
16
|
-
expect(getTextFromNodes(result)).toBe(label);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('does not change text if query is not present in it', () => {
|
|
20
|
-
const query = 'test';
|
|
21
|
-
const label = `this is a label`;
|
|
22
|
-
const result = mount(<Highlight value={label} query={query} />);
|
|
23
|
-
|
|
24
|
-
expect(result.text()).toBe(label);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('highlights whole label that matches the query', () => {
|
|
28
|
-
const query = 'test';
|
|
29
|
-
const label = query;
|
|
30
|
-
const result = mount(<Highlight value={label} query={query} />);
|
|
31
|
-
|
|
32
|
-
expect(highlighted(result).text()).toStrictEqual(query);
|
|
33
|
-
});
|
|
34
|
-
});
|