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

[Enterprise Search] Add parseQueryParams helper #83750

Merged

Conversation

scottybollinger
Copy link
Contributor

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-case

Checklist

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
@scottybollinger scottybollinger requested a review from a team November 19, 2020 00:23
@scottybollinger scottybollinger added Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.11.0 labels Nov 19, 2020
describe('parseQueryParams', () => {
it('should call queryString parse method', () => {
const parseMock = jest.fn();
jest.spyOn(queryString, 'parse').mockImplementation(parseMock);
Copy link
Member

@cee-chen cee-chen Nov 19, 2020

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

Copy link
Contributor Author

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

Copy link
Member

@cee-chen cee-chen Nov 19, 2020

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.

Copy link
Contributor Author

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 😂

Copy link
Member

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

scottybollinger added a commit to scottybollinger/kibana that referenced this pull request Nov 19, 2020
This is a placeholder until elastic#83750 lands
Copy link
Member

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

Awesome!!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@scottybollinger scottybollinger merged commit 40d4787 into elastic:master Nov 19, 2020
@scottybollinger scottybollinger deleted the scottybollinger/query-params branch November 19, 2020 18:47
scottybollinger added a commit to scottybollinger/kibana that referenced this pull request Nov 19, 2020
* [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
scottybollinger added a commit that referenced this pull request Nov 19, 2020
* 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 ‘!!’
scottybollinger added a commit that referenced this pull request Nov 19, 2020
* [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants