Skip to content

Conversation

@Dosant
Copy link
Contributor

@Dosant Dosant commented Aug 13, 2021

Summary

Close #78519

This pr cleans up a bit of unit tests code that uses StubIndexPattern exported from the data plugin.

What was done:

  • Refactor old code away from sinon, use jest instead
  • Originally I was thinking to provide an empty mock, but looking at how this was consumed, stub seemed more appropriate. so I left it as stub helpers. Now, this stub is a fully-featured IndexPattern instance.
  • It provides not only the factories to create custom stubs, but also pre-created common ready-to-use stub index patterns. With time field, without, and also fully-featured logstash index pattern that is used in a bunch of Discover's and some other tests. All the /fixtures/logstash_fields.js were moved near the stub and I a bit restructured it for this.
  • The stub factory is available both in common and in public code. The difference is that public code uses a real public field formats registry by default, whereas common use a dummy mock of it.

How to use:

Existing stub

import { stubIndexPattern } from 'src/plugins/data/common/stubs'; 

myApiThatExpectsIndexPattern(stubIndexPattern)

You can use jest.spyOn to track usage and provide mock implementation instead of creating a custom index pattern as a shortcut. Don't forget to reset mocks in your tests.

Custom stub

import { createStubIndexPattern } from 'src/plugins/data/common/stubs'; 

const stubIndexPattern = createStubIndexPattern({
  spec: { id: 'my-index', title: 'my-index', ...all other spec field },
  opts: {...},
  deps: {... can provide custom field formats implementation if needed}
});

myApiThatExpectsIndexPattern(stubIndexPattern)

@Dosant Dosant changed the title Dev/ip mock [IndexPatterns] Clean up StubIndexPattern Aug 19, 2021
@Dosant Dosant added release_note:skip Skip the PR/issue when compiling release notes Team:AppServices v7.16.0 v8.0.0 Feature:Data Views Data Views code and UI - index patterns before 8.0 labels Aug 19, 2021
@Dosant Dosant requested a review from mattkime August 19, 2021 13:50
Copy link
Contributor

@mattkime mattkime left a comment

Choose a reason for hiding this comment

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

Looks great! Huge improvement. 🚀

@Dosant Dosant marked this pull request as ready for review August 20, 2021 08:24
@Dosant Dosant requested a review from a team August 20, 2021 08:24
@Dosant Dosant requested review from a team as code owners August 20, 2021 08:24
@Dosant Dosant requested review from ashokaditya and pzl August 20, 2021 08:24
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

@Dosant
Copy link
Contributor Author

Dosant commented Aug 20, 2021

@elasticmachine merge upstream

@Dosant
Copy link
Contributor Author

Dosant commented Aug 20, 2021

@elasticmachine merge upstream

Copy link
Contributor

@justinkambic justinkambic left a comment

Choose a reason for hiding this comment

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

Exploratory view change LGTM!

@mattkime
Copy link
Contributor

@elasticmachine merge upstream

@Dosant
Copy link
Contributor Author

Dosant commented Aug 23, 2021

@elasticmachine merge upstream

@Dosant
Copy link
Contributor Author

Dosant commented Aug 24, 2021

@elasticmachine merge upstream

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

LGTM, just tests affected so didn't checkout and test, Code review KibanaApp owned code

@Dosant
Copy link
Contributor Author

Dosant commented Aug 25, 2021

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

@Dosant Dosant added the auto-backport Deprecated - use backport:version if exact versions are needed label Aug 25, 2021
@Dosant Dosant merged commit 48d8944 into elastic:master Aug 25, 2021
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Aug 25, 2021
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Aug 25, 2021
Co-authored-by: Anton Dosov <anton.dosov@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Deprecated - use backport:version if exact versions are needed Feature:Data Views Data Views code and UI - index patterns before 8.0 release_note:skip Skip the PR/issue when compiling release notes v7.16.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[data.indexPatterns] Replace StubIndexPattern with a more detailed jest mock

8 participants