Skip to content

Commit 1b325a6

Browse files
committed
Merge branch 'master' into patch-2
2 parents 5a18a2a + e368560 commit 1b325a6

17 files changed

+1024
-849
lines changed

__tests__/FlagDropDown.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ describe('FlagDropDown', function () { // eslint-disable-line func-names
6565
};
6666
const subject = await this.makeSubject();
6767

68-
expect(subject.state().countryCode).toBe('jp');
69-
window.localStorage.clear();
68+
subject.instance().utilsScriptDeferred.then(() => {
69+
expect(subject.state().countryCode).toBe('jp');
70+
window.localStorage.clear();
71+
});
7072
});
7173

7274
it('should has .separate-dial-code class when with separateDialCode = true', () => {
@@ -160,7 +162,9 @@ describe('FlagDropDown', function () { // eslint-disable-line func-names
160162
};
161163
const subject = await this.makeSubject();
162164

163-
expect(subject.state().countryCode).toBe('jp');
165+
subject.instance().utilsScriptDeferred.then(() => {
166+
expect(subject.state().countryCode).toBe('jp');
167+
});
164168
});
165169

166170
describe('with original ReactTestUtils', () => {

__tests__/TelInput.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,19 @@ describe('TelInput', function () { // eslint-disable-line func-names
497497

498498
expect(subject.find(TelInput).props().placeholder).toBe('Your phone');
499499
});
500+
501+
it('should set "expanded" class to wrapper only when flags are open', () => {
502+
const subject = this.makeSubject();
503+
const flagComponent = subject.find(FlagDropDown).find('.selected-flag');
504+
505+
flagComponent.simulate('click');
506+
expect(subject.instance().wrapperClass.expanded).toBe(true);
507+
508+
const taiwanOption = subject.find(FlagDropDown).find('[data-country-code="tw"]');
509+
510+
taiwanOption.simulate('click');
511+
expect(subject.instance().wrapperClass.expanded).toBe(false);
512+
});
500513
});
501514

502515
describe('uncontrolled', () => {

__tests__/utils.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ describe('utils', () => {
6161
expect(utils.trim(undefined)).toBe('');
6262

6363
const str = ' Hello World ';
64+
6465
expect(utils.trim(str)).toBe('Hello World');
6566
});
6667

@@ -83,6 +84,7 @@ describe('utils', () => {
8384
expect(utils.retrieveLiIndex(bListItem)).toBe(1);
8485

8586
const otherListItem = doc.querySelector('.z');
87+
8688
expect(utils.retrieveLiIndex(otherListItem)).toBe(-1);
8789
});
8890

@@ -154,4 +156,47 @@ describe('utils', () => {
154156

155157
expect(element.classList.contains('abc')).toBeFalsy();
156158
});
159+
160+
it('findIndex', () => {
161+
let array = [];
162+
let predicate = () => true;
163+
164+
expect(utils.findIndex(array, predicate)).toEqual(-1);
165+
166+
array = [1, 2, 3];
167+
predicate = (item) => item === 2;
168+
169+
expect(utils.findIndex(array, predicate)).toEqual(1);
170+
171+
array = [1, 2, 3];
172+
predicate = (item) => item === 4;
173+
174+
expect(utils.findIndex(array, predicate)).toEqual(-1);
175+
});
176+
177+
it('getCursorPositionAfterFormating', () => {
178+
let previousStringBeforeCursor = '9123';
179+
let previousString = '912345';
180+
let nextString = '912345';
181+
182+
expect(utils.getCursorPositionAfterFormating(previousStringBeforeCursor, previousString, nextString)).toEqual(4);
183+
184+
previousStringBeforeCursor = '0912 345';
185+
previousString = '0912 345 678';
186+
nextString = '91234678';
187+
188+
expect(utils.getCursorPositionAfterFormating(previousStringBeforeCursor, previousString, nextString)).toEqual(5);
189+
190+
previousStringBeforeCursor = '91234';
191+
previousString = '91234678';
192+
nextString = '0912 345 678';
193+
194+
expect(utils.getCursorPositionAfterFormating(previousStringBeforeCursor, previousString, nextString)).toEqual(7);
195+
196+
previousStringBeforeCursor = '(201) 5';
197+
previousString = '(201) 55-01';
198+
nextString = '201-5501';
199+
200+
expect(utils.getCursorPositionAfterFormating(previousStringBeforeCursor, previousString, nextString)).toEqual(5);
201+
});
157202
});

config/babel.dev.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ module.exports = {
66
// This is a feature of `babel-loader` for webpack (not Babel itself).
77
// It enables caching results in OS temporary directory for faster rebuilds.
88
cacheDirectory: true,
9+
env: {
10+
test: {
11+
plugins: [
12+
// to enable dynamic import in tests
13+
require.resolve('babel-plugin-dynamic-import-node')
14+
]
15+
}
16+
},
917
presets: [
1018
// Latest stable ECMAScript features
11-
['latest'],
19+
['env'],
1220
// JSX, Flow
1321
require.resolve('babel-preset-react'),
1422
],
@@ -17,6 +25,8 @@ module.exports = {
1725
require.resolve('babel-plugin-transform-class-properties'),
1826
// { ...todo, completed: true }
1927
require.resolve('babel-plugin-transform-object-rest-spread'),
28+
// to enable import() [dynamic import]
29+
require.resolve('babel-plugin-syntax-dynamic-import'),
2030
// function* () { yield 42; yield 43; }
2131
[require.resolve('babel-plugin-transform-regenerator'), {
2232
// Async functions are converted to generators by babel-preset-latest

config/babel.prod.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
babelrc: false,
66
presets: [
77
// Latest stable ECMAScript features
8-
['latest', { es2015: { 'modules': false } }],
8+
['env', { es2015: { 'modules': false } }],
99
// JSX, Flow
1010
require.resolve('babel-preset-react')
1111
],
@@ -36,5 +36,7 @@ module.exports = {
3636
// * https://phabricator.babeljs.io/search/query/pCNlnC2xzwzx/
3737
// TODO: Enable again when these issues are resolved.
3838
// require.resolve('babel-plugin-transform-react-constant-elements')
39+
// to enable import() [dynamic import]
40+
require.resolve('babel-plugin-syntax-dynamic-import'),
3941
]
4042
};

example/0.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)