-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide fullNumber and isValid when onSelectFlag #214
Conversation
Thank you for contribution! |
Hey, yes I will do so in the upcoming week! |
Hey, didn't forget the tests, but have been a bit busy. Will get to it soon |
Hey, I've finally found time to write tests! Here's what I have: it('onSelectFlag', () => {
let expected = '';
const onSelectFlag = (newNumber, countryData, fullNumber, isValid) => {
expected = `${isValid},${newNumber},${countryData.iso2},${fullNumber}`;
};
this.params.onSelectFlag = onSelectFlag;
const subject = this.makeSubject();
const inputComponent = subject.find(TelInput);
requests[0].respond(200,
{ 'Content-Type': 'text/javascript' },
libphonenumberUtils);
window.eval(getScript().text);
inputComponent.simulate('change', { target: { value: '+886911222333' } });
// need to simulate flag change
// inputComponent.simulate('???', { ??? });
expect(expected).toBe('true,+886911222333,tw,+886 911 222 333');
}); Could you please help me figure out how to simulate a flag change? Thanks! |
How about this? diff --git a/__tests__/FlagDropDown.test.js b/__tests__/FlagDropDown.test.js
index c10e3ba..60bf008 100644
--- a/__tests__/FlagDropDown.test.js
+++ b/__tests__/FlagDropDown.test.js
@@ -8,6 +8,7 @@ import fs from 'fs';
import IntlTelInput from '../src/components/IntlTelInputApp';
import FlagDropDown from '../src/components/FlagDropDown';
import CountryList from '../src/components/CountryList';
+import TelInput from '../src/components/TelInput';
describe('FlagDropDown', function () { // eslint-disable-line func-names
let libphonenumberUtils;
@@ -440,26 +441,33 @@ describe('FlagDropDown', function () { // eslint-disable-line func-names
it('onSelectFlag', () => {
let expected = '';
- const onSelectFlag = (currentNumber, countryData) => {
- expected = Object.assign({}, { currentNumber, ...countryData });
+ const onSelectFlag = (currentNumber, countryData, fullNumber, isValid) => {
+ expected = Object.assign({}, { currentNumber, fullNumber, isValid, ...countryData });
};
this.params.onSelectFlag = onSelectFlag;
const subject = this.makeSubject();
const flagComponent = subject.find(FlagDropDown);
+ const inputComponent = subject.find(TelInput);
const countryListComponent = subject.find(CountryList);
requests[0].respond(200,
{ 'Content-Type': 'text/javascript' },
libphonenumberUtils);
+ window.eval(getScript().text);
+ inputComponent.simulate('change', { target: { value: '+8109012345678' } });
flagComponent.simulate('click');
const japanOption = countryListComponent.find('[data-country-code="jp"]');
japanOption.simulate('click');
+
expect(expected).toEqual({
- currentNumber: '',
+ currentNumber: '+8109012345678',
+ fullNumber: '+81 90-1234-5678',
+ isValid: true,
name: 'Japan (日本)',
iso2: 'jp',
dialCode: '81', And can we update selectFlagHandler in |
Thanks for the great help, works like a charm! Seems ready to be merged, tell me if I can do anything else |
Great! LGTM! diff --git a/src/example.js b/src/example.js
index e8ff260..884b7c4 100644
--- a/src/example.js
+++ b/src/example.js
@@ -58,8 +58,8 @@ class DemoComponent extends Component {
});
}
- selectFlagHandler(name, currentNumber, selectedCountryData) {
- log(currentNumber, selectedCountryData);
+ selectFlagHandler(name, currentNumber, selectedCountryData, fullNumber, isValid) {
+ log(currentNumber, selectedCountryData, fullNumber, isValid);
this.setState({
[name]: currentNumber,
}); |
Woops sorry I totally forgot about this part... It's done! |
Provide fullNumber and isValid when onSelectFlag
No description provided.