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

[IM] Remove axios dependency in tests #128171

Merged
merged 14 commits into from
Mar 24, 2022
Merged

Conversation

sabarasaba
Copy link
Member

@sabarasaba sabarasaba commented Mar 21, 2022

Partially addresses #127966

Summary

In order to upgrade the axios dependency in kibana(see: #111655) we need to switch the tests from this app to use HttpSetup mock instead of axios + sinon server mock, which is technically incorrect but axios just happened to have methods signature similar to HttpSetup.

Note: There's a bunch of CIT's for component_templates that live in x-pack/plugins/index_management/public/application/components/component_templates/__jest__, ideally the setup_environment.ts and http_request.ts files could be refactored into just one. I've created an issue for dealing with that #128376

const status = error ? error.status || 400 : 200;
const body = error ? error.body : response;

server.respondWith('GET', `${API_BASE_PATH}/index_templates/:id`, [
Copy link
Member Author

Choose a reason for hiding this comment

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

With sinon fake server we could use wildcards for url params, that is no longer allowed with HttpSetup mock. So we need to directly specify the full url when mocking api endpoints. For this particular case would look something like:

  const setLoadTemplateResponse = (
    templateId: string,
    response?: HttpResponse,
    error?: ResponseError
  ) => mockResponse('GET', `${API_BASE_PATH}/index_templates/${templateId}`, response, error);

@sabarasaba sabarasaba added Feature:Index Management Index and index templates UI Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes v8.2.0 v7.17.2 auto-backport Deprecated - use backport:version if exact versions are needed labels Mar 23, 2022
@sabarasaba sabarasaba marked this pull request as ready for review March 23, 2022 16:05
@sabarasaba sabarasaba requested a review from a team as a code owner March 23, 2022 16:05
@elasticmachine
Copy link
Contributor

Pinging @elastic/platform-deployment-management (Team:Deployment Management)

@alisonelizabeth
Copy link
Contributor

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

expected head sha didn’t match current head ref.

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

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

Great work with this @sabarasaba! That was a lot of tests 😅 . I left a few comments. Let me know what you think.

JSON.stringify(body),
]);
};
const registerHttpRequestMockHelpers = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Starting here to L56 seems to be the same code across the test refactoring PRs. Does it make sense to try to centralize it somewhere so it can be reused?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you agree, I think this can be done as a separate PR

Copy link
Member Author

@sabarasaba sabarasaba Mar 24, 2022

Choose a reason for hiding this comment

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

I've suggested also to put this somewhere in kbn-test (see this thread), but we ended up agreeing on keeping separate implementations per app for now. I'll create a new issue after on our side to update this later on after I finish updating all the tests.

@@ -235,6 +231,7 @@ describe('Index Templates tab', () => {
const { find, exists, actions, component } = testBed;

// Composable templates
httpRequestsMockHelpers.setLoadTemplateResponse(templates[0].name, templates[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain why this wasn't needed previously?

Copy link
Member Author

Choose a reason for hiding this comment

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

When an index flyout is opened a new api request for getting details for that index is called. With the sinon route for mocking the setLoadTemplateResponse we had a wildcard that would load the same payload for any templateId. So the top level mock we have set up at the beginning of the describe was working just fine. But since we now have to directly specify for each templateId, we need to specify each request.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 got it. Makes sense.


component.update();

find('indexTableIndexNameLink').at(0).simulate('click');
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain why this wasn't needed before?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since the testBed instance does't get re-initialized in a top levelbeforeEach, this test was wrongly depending on the testBed instance that is initialized in the previous describe. So we need to specifically declare it in its own describe scope.

@sabarasaba
Copy link
Member Author

Thanks for the review @alisonelizabeth, I know it was a lot of things! I think i've addressed your feedback, let me know what you think :)

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

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

Latest LGTM. Awesome work!

@sabarasaba
Copy link
Member Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

cc @sabarasaba

@sabarasaba sabarasaba merged commit 00f58ad into elastic:main Mar 24, 2022
@sabarasaba sabarasaba removed the auto-backport Deprecated - use backport:version if exact versions are needed label Mar 24, 2022
sabarasaba added a commit to sabarasaba/kibana that referenced this pull request Mar 28, 2022
(cherry picked from commit 00f58ad)

# Conflicts:
#	x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/home/home.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts
#	x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_clone.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_create.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_edit.helpers.ts
#	x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_create.helpers.ts
#	x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_details.helpers.ts
#	x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_edit.helpers.ts
sabarasaba added a commit that referenced this pull request Mar 28, 2022
* [IM] Remove `axios` dependency in tests (#128171)

(cherry picked from commit 00f58ad)

# Conflicts:
#	x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/home/home.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts
#	x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_clone.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_create.helpers.ts
#	x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_edit.helpers.ts
#	x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_create.helpers.ts
#	x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_details.helpers.ts
#	x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_edit.helpers.ts

* Fix linter issues

* Fix broken tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Index Management Index and index templates UI release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.17.2 v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants