-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Kea & logic mocks/helpers into kea_logic subfolder
- for organization NOTE: It can't be a plain kea/ folder because then Jest automatically mocks the `kea` module itself kea 🤦
- Loading branch information
Showing
252 changed files
with
418 additions
and
336 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
65 changes: 65 additions & 0 deletions
65
x-pack/plugins/enterprise_search/public/applications/__mocks__/kea_logic/hooks.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,65 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
/** | ||
* Combine all shared mock values/actions into a single obj | ||
* | ||
* NOTE: These variable names MUST start with 'mock*' in order for | ||
* Jest to accept its use within a jest.mock() | ||
*/ | ||
import { mockFlashMessagesValues, mockFlashMessagesActions } from './flash_messages_logic.mock'; | ||
import { mockHttpValues } from './http_logic.mock'; | ||
import { mockKibanaValues } from './kibana_logic.mock'; | ||
import { mockLicensingValues } from './licensing_logic.mock'; | ||
import { mockTelemetryActions } from './telemetry_logic.mock'; | ||
|
||
export const mockAllValues = { | ||
...mockKibanaValues, | ||
...mockLicensingValues, | ||
...mockHttpValues, | ||
...mockFlashMessagesValues, | ||
}; | ||
export const mockAllActions = { | ||
...mockTelemetryActions, | ||
...mockFlashMessagesActions, | ||
}; | ||
|
||
/** | ||
* Import this file directly to mock useValues with a set of default values for all shared logic files. | ||
* Example usage: | ||
* | ||
* import '../../../__mocks__/kea_logic'; // Must come before kea's import, adjust relative path as needed | ||
*/ | ||
jest.mock('kea', () => ({ | ||
...(jest.requireActual('kea') as object), | ||
useValues: jest.fn(() => ({ ...mockAllValues })), | ||
useActions: jest.fn(() => ({ ...mockAllActions })), | ||
})); | ||
|
||
/** | ||
* React component helpers | ||
* | ||
* Call this function to override a specific set of Kea values while retaining all other defaults | ||
* | ||
* Example usage: | ||
* | ||
* import { setMockValues } from '../../../__mocks__/kea_logic'; | ||
* import { SomeComponent } from './'; | ||
* | ||
* it('some test', () => { | ||
* setMockValues({ someValue: 'hello' }); | ||
* shallow(<SomeComponent />); | ||
* }); | ||
*/ | ||
import { useValues, useActions } from 'kea'; | ||
|
||
export const setMockValues = (values: object) => { | ||
(useValues as jest.Mock).mockImplementation(() => ({ ...mockAllValues, ...values })); | ||
}; | ||
export const setMockActions = (actions: object) => { | ||
(useActions as jest.Mock).mockImplementation(() => ({ ...mockAllActions, ...actions })); | ||
}; |
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
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
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
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
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
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
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
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
Oops, something went wrong.