Skip to content

[Enterprise Search] Kea mount test helper#87247

Merged
cee-chen merged 3 commits intoelastic:masterfrom
cee-chen:kea-mount-helper
Jan 6, 2021
Merged

[Enterprise Search] Kea mount test helper#87247
cee-chen merged 3 commits intoelastic:masterfrom
cee-chen:kea-mount-helper

Conversation

@cee-chen
Copy link
Contributor

@cee-chen cee-chen commented Jan 4, 2021

Summary

After discussing this in a previous PR (#86822 (review)), I went ahead and created a test helper that DRY's out our repeated mount helpers across several tests. Super huge thanks to Jason for giving an example API!

Usage:

import { LogicMounter } from '../../../__mocks__/kea.mock';

const { mount, unmount } = new LogicMounter(SomeLogic);

it('mounts with context automatically reset between tests', () => {
  mount();
});

it('mounts and overrides default values', () => {
  mount({ foo: 'bar' });
  expect(SomeLogic.values.foo).toEqual('bar');
});

it('unmounts', () => {
  mount();
  unmount();
});

Checklist

@cee-chen cee-chen requested review from a team and JasonStoltz January 4, 2021 22:01
@cee-chen cee-chen added release_note:skip Skip the PR/issue when compiling release notes v7.12.0 labels Jan 4, 2021
@cee-chen
Copy link
Contributor Author

cee-chen commented Jan 4, 2021

@scottybollinger FYI - you may find this helper useful in your Workplace Search logic tests as well. You can use it in logic file tests to pass default values without having to manually set them. It also handles resetContext() behind the scenes for you.

Copy link
Contributor

@scottybollinger scottybollinger left a comment

Choose a reason for hiding this comment

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

This is awesome! Can't wait to use it. Thanks Constance!

Comment on lines 105 to 106
Copy link
Contributor Author

@cee-chen cee-chen Jan 4, 2021

Choose a reason for hiding this comment

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

Example path:

['enterprise_search', 'app_search', 'engine_overview_logic']

Example defaults:

{
  defaults: {
    enterprise_search: {
      app_search: {
        engine_overview_logic: {
           ...values
        }
      }
    }
  }
}

I've never actually seen/used .reduceRight before this but was super surprised at how easy it was to find a one-liner that did exactly what we wanted 🤯

Copy link
Member

Choose a reason for hiding this comment

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

I love me some reduce 👍

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Distributable file count

id before after diff
default 47247 48007 +760

History

  • 💚 Build #96801 succeeded eb322d959e2bc5068df9c63efc45f7f67f616e69

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

Copy link
Member

@JasonStoltz JasonStoltz left a comment

Choose a reason for hiding this comment

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

Thanks for doing this Constance!

@cee-chen cee-chen merged commit b4f3a15 into elastic:master Jan 6, 2021
@cee-chen cee-chen deleted the kea-mount-helper branch January 6, 2021 18:14
cee-chen pushed a commit that referenced this pull request Jan 6, 2021
* Add Kea logic mount helper

* Update existing mount() helpers to use new DRY helper

* Add additional unmount helper + example test update

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes v7.12.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants