-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Enterprise Search] Add parseQueryParams helper #83750
[Enterprise Search] Add parseQueryParams helper #83750
Conversation
This PR migrates part of the ent-search queryParams util, `parseQueryParams` for use in Workplace Search. `setQueryParams` was no a part of this PR because it is only used one time in App Search and a better alternative might be available for that use-case
describe('parseQueryParams', () => { | ||
it('should call queryString parse method', () => { | ||
const parseMock = jest.fn(); | ||
jest.spyOn(queryString, 'parse').mockImplementation(parseMock); |
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.
you shouldn't need both jest.spyOn
and jest.mock
+import up above.
I'm a little confused also, why mock queryString? Does it not return an expected { foo: 'bar' }
obj when calling parseQueryParams('?foo=bar')
?
Unless there's a strange issue with calling the lib directly, I'd prefer to leave it unmocked here if possible
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.
When I don't mock it I get this error:
expect(received).toHaveBeenCalledWith(...expected)
Matcher error: received value must be a mock or spy function
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.
Right, but I'm saying don't bother spying on it or checking toHaveBeenCalledWith
, just evaluate the outcome since it's fairly straightforward.
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.
Got it! Thanks for the help. TIL actually testing the output of a library in a test 😂
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.
Haha, it doesn't always work out with the more complicated libraries but in the case it's definitely worth doing. Also you totally beat my other comment, jinx :D
This is a placeholder until elastic#83750 lands
x-pack/plugins/enterprise_search/public/applications/shared/query_params/query_params.test.ts
Outdated
Show resolved
Hide resolved
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.
Awesome!!
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
* [Enterprise Search] Add parseQueryParams helper This PR migrates part of the ent-search queryParams util, `parseQueryParams` for use in Workplace Search. `setQueryParams` was no a part of this PR because it is only used one time in App Search and a better alternative might be available for that use-case * Remove mock * Actually test functionality of query-string * Add test for array * Better test name
* Initial copy/paste of components Changes for pre-commit hooks were: - Linting - Lodash imports - changed enum names in add_source because there were collistions with component names. So SaveConfig becomes SaveConfigStep because there is a component by the same name - replaced apostrophe’s with ‘'’ per lint rule Finally, the linter didn’t like this expression: asOauthRedirect ? onOauthFormSubmit() : onCredentialsFormSubmit(); … so I changed it to: const onSubmit = hasOauthRedirect ? onOauthFormSubmit : onCredentialsFormSubmit; onSubmit(); * Add route helper * Remove AppView, Sidebar navigation and FlashMessages Sidebar copy and breadcrumbs will be recreated at the top level in a separate PR * Update component paths * Use Kibana’s hasPlatinumLicense over minimumPlatinumLicense * Various TypeScript lint fixes * Fix index paths * Remove in-page breadcrumbs and move sidebar copy In Kibana, breadcrumbs will be at the top-level and not in the view Also, we have no sidebar with contextual copy. The Figma designs call for this copy to be above the main content. For now I am placing this in the existing ViewContentHeader component. This will be slightly broken because of the structure of ViewContentHeader but that is expected for now since it cannot be rendered in the browser yet to fix * Temporarily add parseQueryParams This is a placeholder until #83750 lands * Remove optional from isOrganization Looks like the value is always passed * Remove ‘!!’
* [Enterprise Search] Add parseQueryParams helper This PR migrates part of the ent-search queryParams util, `parseQueryParams` for use in Workplace Search. `setQueryParams` was no a part of this PR because it is only used one time in App Search and a better alternative might be available for that use-case * Remove mock * Actually test functionality of query-string * Add test for array * Better test name
Summary
This PR migrates part of the ent-search queryParams util,
parseQueryParams
for use in Workplace Search.setQueryParams
was no a part of this PR because it is only used in one component in App Search and a better alternative might be available for that use-caseChecklist