forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Remove all instances of KibanaContext to Kea store (
elastic#78513) * Add KibanaLogic store/mount * Update usage of setBreadcrumbs/setDocTitle to KibanaLogic * Update usage of Kibana config context to KibanaLogic * Update usage of navigateToUrl context to KibanaLogic * 🔥 Remove unused shallow_usecontext mocks, repurpose file to shallow_useeffect - The file is now no longer used to mock useContext, only unseEffect, hence the rename * 🔥 Delete/repurpose mount with context helpers - Remove mountWithKibanaContext completely - Change mountWithContext to mountWithIntl, since that's the only context remaining, and move it to its own file - Change mountWithAsyncContext to just mountAsync and move it to its own file + add an option to pair it w/ mountWithIntl for formatted date/number support * 🔥 Delete KibanaContext and mockKibanaContext + minor newline linting/grouping tweaks Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
0c0e4f6
commit 10e1415
Showing
41 changed files
with
300 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_async.mock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { mount, ReactWrapper } from 'enzyme'; | ||
|
||
import { mountWithIntl } from './'; | ||
|
||
/** | ||
* This helper is intended for components that have async effects | ||
* (e.g. http fetches) on mount. It mostly adds act/update boilerplate | ||
* that's needed for the wrapper to play nice with Enzyme/Jest | ||
* | ||
* Example usage: | ||
* | ||
* const wrapper = mountAsync(<Component />); | ||
*/ | ||
|
||
interface IOptions { | ||
i18n?: boolean; | ||
} | ||
|
||
export const mountAsync = async ( | ||
children: React.ReactElement, | ||
options: IOptions | ||
): Promise<ReactWrapper> => { | ||
let wrapper: ReactWrapper | undefined; | ||
|
||
// We get a lot of act() warning/errors in the terminal without this. | ||
// TBH, I don't fully understand why since Enzyme's mount is supposed to | ||
// have act() baked in - could be because of the wrapping context provider? | ||
await act(async () => { | ||
wrapper = options.i18n ? mountWithIntl(children) : mount(children); | ||
}); | ||
if (wrapper) { | ||
wrapper.update(); // This seems to be required for the DOM to actually update | ||
|
||
return wrapper; | ||
} else { | ||
throw new Error('Could not mount wrapper'); | ||
} | ||
}; |
83 changes: 0 additions & 83 deletions
83
x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_with_context.mock.tsx
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_with_i18n.mock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { I18nProvider } from '@kbn/i18n/react'; | ||
|
||
/** | ||
* This helper wraps a component with react-intl's <I18nProvider> which | ||
* fixes "Could not find required `intl` object" console errors when running tests | ||
* | ||
* Example usage (should be the same as mount()): | ||
* | ||
* const wrapper = mountWithI18n(<Component />); | ||
*/ | ||
export const mountWithIntl = (children: React.ReactElement) => { | ||
return mount(<I18nProvider>{children}</I18nProvider>); | ||
}; |
40 changes: 0 additions & 40 deletions
40
x-pack/plugins/enterprise_search/public/applications/__mocks__/shallow_usecontext.mock.ts
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/enterprise_search/public/applications/__mocks__/shallow_useeffect.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
jest.mock('react', () => ({ | ||
...(jest.requireActual('react') as object), | ||
useEffect: jest.fn((fn) => fn()), // Calls on mount/every update - use mount for more complex behavior | ||
})); | ||
|
||
/** | ||
* Example usage within a component test using shallow(): | ||
* | ||
* import '../../../__mocks__/shallow_useeffect.mock'; // Must come before React's import, adjust relative path as needed | ||
* | ||
* import React from 'react'; | ||
* import { shallow } from 'enzyme'; | ||
* | ||
* // ... etc. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.