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

Hosting Command Palette: Add test cases for filtering logic #85838

Merged
merged 5 commits into from
Jan 10, 2024

Conversation

katinthehatsite
Copy link
Contributor

@katinthehatsite katinthehatsite commented Dec 28, 2023

Related to https://github.com/Automattic/dotcom-forge/issues/4952

Proposed Changes

This PR adds tests for use-command-filter hook to confirm that it returns what is expected:

  • it should return 0, when there is no command match;
  • it should return 0.5, when there is a match in the searchLabel
  • it should return 1, when there is a match in the label

Testing Instructions

  • Pull the changes from this branch locally
  • Run yarn test-client -- client/components/command-palette/test/use-command-filter.tsx

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • https://wpcalypso.wordpress.com/devdocs/docs/testing/index.md for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-ajp-p2)?

@katinthehatsite katinthehatsite self-assigned this Dec 28, 2023
Copy link

github-actions bot commented Dec 28, 2023

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

const beforeSeparator = 'Open hosting configuration';
const afterSeparator = 'cache hosting manage';
const value = beforeSeparator + COMMAND_SEPARATOR + afterSeparator;
expect( commandFilter( value, search ) ).toBe( 0.5 );
Copy link
Contributor Author

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 return 0.5 as expected so technically it does what the prop describes (return the number between 0 and 1) but it does not change the ranking. I think this indicates that there must be an issue with cmdk. What are your thoughts?

Copy link
Contributor Author

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

Copy link
Member

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 return 0.5 as expected so technically it does what the prop describes (return the number between 0 and 1) but it does not change the ranking. I think this indicates that there must be an issue with cmdk. What are your thoughts?

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.

Copy link
Member

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

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.

Copy link
Contributor Author

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!

Copy link
Contributor Author

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#118

There is current a PR in progress to fix the issue: pacocoursey/cmdk#182

Copy link
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

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

The tests look good to me. 👍

@katinthehatsite katinthehatsite merged commit 4fd7b51 into trunk Jan 10, 2024
11 checks passed
@katinthehatsite katinthehatsite deleted the add/tests-for-command-palette-filtering branch January 10, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants