Skip to content

Handle Searching for Numbers#41

Merged
selvagsz merged 1 commit intoselvagsz:bugfix/search_numbersfrom
SCasarotto:patch-1
Apr 10, 2018
Merged

Handle Searching for Numbers#41
selvagsz merged 1 commit intoselvagsz:bugfix/search_numbersfrom
SCasarotto:patch-1

Conversation

@SCasarotto
Copy link
Copy Markdown
Contributor

A quick fix for #40. Feel free to adjust if this is suboptimal.

In my quick testing, this seems to resolve the issue.

A quick fix for issue 40 (selvagsz#40). Feel free to adjust if this is suboptimal.
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.6%) to 79.53% when pulling 0d61911 on SCasarotto:patch-1 into 9d0e60e on selvagsz:master.

if (typeof (option[index] || '') === 'string') {
return (option[index] || '').toLowerCase().indexOf(searchTerm) !== -1;
}
return (String(option[index]) || '').toLowerCase().indexOf(searchTerm) !== -1;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String(1) => "1"
String(null) => "null"
String(undefined) => "undefined"

@SCasarotto While stringifying the number is fine; null & undefined values shouldn't be part of search. We can exclude them. Something like

//...
    return makeArray(searchIndices).some(index => {
      let value = option[index];
      return !isNone(value) && String(value).toLowerCase().indexOf(searchTerm) !== -1;
    });
//...

export const isNone = value => value === null || value === undefined;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SCasarotto It would be great if you could also add unit tests for the matcher func under src/__tests__/utils-test.js. Possible ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy to try to add some tests and update the code as you suggested. I am not sure when I will be able to fit this in though.

Repository owner deleted a comment from coveralls Apr 9, 2018
@selvagsz selvagsz changed the base branch from master to bugfix/search_numbers April 10, 2018 18:38
@selvagsz
Copy link
Copy Markdown
Owner

@SCasarotto No worries, I'll try merging on a bugfix branch & take it over

@selvagsz selvagsz merged commit ea5666d into selvagsz:bugfix/search_numbers Apr 10, 2018
@SCasarotto
Copy link
Copy Markdown
Contributor Author

Thanks. I started trying to write some tests but seemed to have issues getting jest to notice my tests and then had to run to meetings. If I can assist I really will try. I want to try to give back to something I use if I can.

@selvagsz
Copy link
Copy Markdown
Owner

selvagsz commented Apr 10, 2018

@SCasarotto Cool then. Tests are been ignored because of these lines https://github.com/selvagsz/react-power-select/blob/master/package.json#L37-L39

You can proceed doing the following steps,

  1. Rename src/__tests__/utils folder to src/__tests__/test-utils & fix the imports in the existing tests
  2. Change the testPathIgnorePatterns in package.json to ignore the src/__tests__/test-utils
  3. Create src/__tests__/utils/matcher-test.js for unit testing matcher func

@SCasarotto
Copy link
Copy Markdown
Contributor Author

Ah, thank you. I started looking around but didn't see that line. Awesome! I will keep you posted and thanks for bearing with me.

@SCasarotto
Copy link
Copy Markdown
Contributor Author

@selvagsz I have written tests and improved the matcher. I have been working in my local version of origin/bugfix/search_numbers. When I try to push to it I get a 403. Whats the right procedure here?

@selvagsz
Copy link
Copy Markdown
Owner

@SCasarotto You don't have push access to this repo. Can you please raise another PR from your fork ?

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