-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Hosting Command Palette: Add test cases for filtering logic #85838
Merged
katinthehatsite
merged 5 commits into
trunk
from
add/tests-for-command-palette-filtering
Jan 10, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
client/components/command-palette/test/use-command-filter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { COMMAND_SEPARATOR, useCommandFilter } from '../use-command-filter'; | ||
|
||
describe( 'useCommandFilter', () => { | ||
const commandFilter = useCommandFilter(); | ||
|
||
test( 'should return 1 for the exact match before separator', () => { | ||
const search = 'Manage'; | ||
const beforeSeparator = 'Manage posts'; | ||
const afterSeparator = 'your blog posts'; | ||
const value = beforeSeparator + COMMAND_SEPARATOR + afterSeparator; | ||
expect( commandFilter( value, search ) ).toBe( 1 ); | ||
} ); | ||
|
||
test( 'should return 1 for the exact match despite the case (lower or upper) before separator', () => { | ||
const search = 'MANAGE'; | ||
const beforeSeparator = 'Manage posts'; | ||
const afterSeparator = 'your blog posts'; | ||
const value = beforeSeparator + COMMAND_SEPARATOR + afterSeparator; | ||
expect( commandFilter( value, search ) ).toBe( 1 ); | ||
} ); | ||
|
||
test( 'should return 1 for the exact match with multiple words before separator', () => { | ||
const search = 'manage posts'; | ||
const beforeSeparator = 'Manage posts'; | ||
const afterSeparator = 'your blog posts'; | ||
const value = beforeSeparator + COMMAND_SEPARATOR + afterSeparator; | ||
expect( commandFilter( value, search ) ).toBe( 1 ); | ||
} ); | ||
|
||
test( 'should return 0.5 for the exact match after separator', () => { | ||
const search = 'cache'; | ||
const beforeSeparator = 'Open hosting configuration'; | ||
const afterSeparator = 'cache hosting manage'; | ||
const value = beforeSeparator + COMMAND_SEPARATOR + afterSeparator; | ||
expect( commandFilter( value, search ) ).toBe( 0.5 ); | ||
} ); | ||
|
||
test( 'should return 0.5 for the exact match after separator despite upper or lower case', () => { | ||
const search = 'CACHE'; | ||
const beforeSeparator = 'Open hosting configuration'; | ||
const afterSeparator = 'cache hosting manage'; | ||
const value = beforeSeparator + COMMAND_SEPARATOR + afterSeparator; | ||
expect( commandFilter( value, search ) ).toBe( 0.5 ); | ||
} ); | ||
|
||
test( 'should return 0 where there is no match either for label or searchLabel', () => { | ||
const search = 'CACHE'; | ||
const beforeSeparator = 'Open hosting configuration'; | ||
const afterSeparator = 'hosting manage'; | ||
const value = beforeSeparator + COMMAND_SEPARATOR + afterSeparator; | ||
expect( commandFilter( value, search ) ).toBe( 0 ); | ||
} ); | ||
} ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sejas I added test for this and the function for the
filter
does return0.5
as expected so technically it does what the prop describes (return the number between0
and1
) but it does not change the ranking. I think this indicates that there must be an issue withcmdk
. What are your thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to add, I think we should also some tests to check the rendering of the commands when you are rending an actual array since these are fairly simple and only check if the matching works as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should report the issue to
cmdk
to fix it. I think they didn't create a release almost a year ago, so it could be they implemented it and didn't release it yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! That would be fantastic. If it's not too complicated, we could create a fake array of commands, and then search for something and check if it's in the array or/and if it's a first result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I will report the issue to them and work on the tests today! Thanks for the review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sejas I search the
cmdk
repo and found the issue with filtering was reported here: pacocoursey/cmdk#118There is current a PR in progress to fix the issue: pacocoursey/cmdk#182