Skip to content
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

Merged
merged 4 commits into from
Jul 23, 2018

Conversation

adrienharnay
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented Jun 1, 2018

Coverage Status

Coverage increased (+0.02%) to 93.364% when pulling 4e0941a on adrienharnay:patch-2 into e368560 on patw0929:master.

@patw0929
Copy link
Owner

Thank you for contribution!
For making sure that the PRs can work successfully (current and in future), could you help to write unit tests of PRs? 🙇

@adrienharnay
Copy link
Contributor Author

Hey, yes I will do so in the upcoming week!

@adrienharnay
Copy link
Contributor Author

Hey, didn't forget the tests, but have been a bit busy. Will get to it soon

@adrienharnay
Copy link
Contributor Author

adrienharnay commented Jul 19, 2018

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!

@superhit0 superhit0 requested a review from patw0929 July 19, 2018 16:25
@patw0929
Copy link
Owner

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 example.js? (To console.log fullNumber and isValid)

@adrienharnay
Copy link
Contributor Author

Thanks for the great help, works like a charm! Seems ready to be merged, tell me if I can do anything else

@patw0929
Copy link
Owner

patw0929 commented Jul 22, 2018

Great! LGTM!
And could you update the selectFlagHandler in example.js? Thanks!

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,
     });

@adrienharnay
Copy link
Contributor Author

Woops sorry I totally forgot about this part... It's done!

@patw0929 patw0929 merged commit 2a50547 into patw0929:master Jul 23, 2018
@adrienharnay adrienharnay deleted the patch-2 branch July 23, 2018 18:22
andrewsantarin pushed a commit to andrewsantarin/react-intl-tel-input that referenced this pull request Feb 2, 2022
Provide fullNumber and isValid when onSelectFlag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants