elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.6k stars 8.21k forks source link

[Discuss] Reusable mocks for EUI components #99322

Closed yuliacech closed 1 month ago

yuliacech commented 3 years ago

While working on PR#97472 we started a discussion on how to handle mocking EUI components like EuiCombobox or EuiSearchBox in our jest client integration tests. We need to mock some EUI components to have an easy way of interacting with them in tests. There are helper functions available in packages/kbn-test/src/jest/utils/testbed/testbed.ts (i.e. setComboboxValue) and mocks for EUI components in individual tests (x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/global_mocks.tsx). A quick search through Kibana code base shows that mocks are used and repeated in tests in several plugins.

I'd like to start a discussion if we need a central place for mocks:

  1. should it be in Kibana or an import from EUI?
  2. which components are being consistently mocked in tests? (htmlIdGenerator, EuiComboBox, EuiCodeEditor what else?)
  3. are testbed helpers still needed if we use mocks anyways?

cc @elastic/es-ui

cjcenizal commented 3 years ago

should it be in Kibana or an import from EUI

I think this is worth suggesting to the EUI team. It'd be a great opportunity to start aligning EUI consumers on some testing best practices.

yuliacech commented 3 years ago

After a discussion with ES UI team, we would like to add a folder test to es_ui_shared plugin to keep EUI component mocks used in ES UI plugin tests. New tests will then import existing mocks, so no need to always copy paste mocks for every plugin.

alisonelizabeth commented 1 month ago

Closing as not planned, will revisit as needed when working on tests