[Enterprise Search] Miscellaneous test cleanups (#88525)

* Update older tests mocking useValues to setMockValues

* Update older logic tests to use newer LogicMounter helper

- NOTE: shared logic files are still using resetContext however, in order to not accidentally override/mock kea + since they should be testing their own mount helpers

* Merge/DRY kea.mock helpers into a single import

* Remove unnecessary kea.mock file imports

- the automock already happens when you import something from the kea.mock file
- in some cases in WS the mock just wasn't needed

* Newline linting

- Do I need a hobby? yes
- Is this my hobby? ...maybe

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Constance 2021-01-19 07:49:10 -08:00 committed by GitHub
parent fbf600d7fc
commit eb4cb3d1dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 46 additions and 131 deletions

View file

@ -4,15 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { resetContext } from 'kea';
import { LogicMounter } from '../__mocks__';
import { DEFAULT_INITIAL_APP_DATA } from '../../../common/__mocks__';
import { AppLogic } from './app_logic';
describe('AppLogic', () => {
const { mount } = new LogicMounter(AppLogic);
beforeEach(() => {
resetContext({});
AppLogic.mount();
mount();
});
const DEFAULT_VALUES = {

View file

@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { setMockValues, setMockActions } from '../../../../../__mocks__/kea.mock';
import { rerender } from '../../../../../__mocks__';
import { setMockValues, setMockActions, rerender } from '../../../../../__mocks__';
import React from 'react';
import { shallow } from 'enzyme';

View file

@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { setMockValues, setMockActions } from '../../../../__mocks__/kea.mock';
import { rerender } from '../../../../__mocks__';
import { setMockValues, setMockActions, rerender } from '../../../../__mocks__';
import React from 'react';
import { shallow } from 'enzyme';

View file

@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { setMockValues, setMockActions } from '../../../../__mocks__/kea.mock';
import { rerender } from '../../../../__mocks__';
import { setMockValues, setMockActions, rerender } from '../../../../__mocks__';
import React from 'react';
import { shallow } from 'enzyme';

View file

@ -3,8 +3,9 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { setMockValues, setMockActions } from '../../../__mocks__/kea.mock';
import '../../../__mocks__/react_router_history.mock';
import { setMockValues, setMockActions } from '../../../__mocks__/kea.mock';
import { unmountHandler } from '../../../__mocks__/shallow_useeffect.mock';
import React from 'react';

View file

@ -3,6 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { setMockValues } from '../../../__mocks__/kea.mock';
import React from 'react';

View file

@ -3,9 +3,9 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockValues } from '../../../../__mocks__';
import '../../../../__mocks__/enterprise_search_url.mock';
import { setMockValues } from '../../../../__mocks__';
const mockSetFields = jest.fn();

View file

@ -3,6 +3,7 @@
* 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 { shallow } from 'enzyme';

View file

@ -3,6 +3,7 @@
* 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 { shallow } from 'enzyme';

View file

@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { setMockValues } from '../../../__mocks__/kea.mock';
import { rerender } from '../../../__mocks__';
import { setMockValues, rerender } from '../../../__mocks__';
import React from 'react';
import { shallow } from 'enzyme';

View file

@ -5,8 +5,7 @@
*/
import '../../../__mocks__/shallow_useeffect.mock';
import { rerender } from '../../../__mocks__';
import { setMockValues, setMockActions } from '../../../__mocks__/kea.mock';
import { setMockValues, setMockActions, rerender } from '../../../__mocks__';
import React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';

View file

@ -5,7 +5,6 @@
*/
import React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
import { EuiPanel } from '@elastic/eui';

View file

@ -5,7 +5,6 @@
*/
import React from 'react';
import { shallow } from 'enzyme';
import { ResultField } from './result_field';

View file

@ -5,7 +5,6 @@
*/
import React from 'react';
import { shallow } from 'enzyme';
import { ResultHeader } from './result_header';

View file

@ -5,7 +5,6 @@
*/
import React from 'react';
import { mount } from 'enzyme';
import { ResultHeaderItem } from './result_header_item';

View file

@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import React from 'react';

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import '../../../../__mocks__/shallow_useeffect.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import React from 'react';

View file

@ -3,6 +3,7 @@
* 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 { shallow } from 'enzyme';
import { EuiPageContentBody } from '@elastic/eui';

View file

@ -5,7 +5,6 @@
*/
import '../__mocks__/shallow_useeffect.mock';
import '../__mocks__/kea.mock';
import '../__mocks__/enterprise_search_url.mock';
import { setMockValues, setMockActions } from '../__mocks__';

View file

@ -4,11 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../__mocks__/kea.mock';
import { mockTelemetryActions } from '../../../__mocks__';
import { setMockValues, mockTelemetryActions } from '../../../__mocks__';
import React from 'react';
import { useValues } from 'kea';
import { shallow } from 'enzyme';
import { EuiCard } from '@elastic/eui';
@ -59,7 +57,7 @@ describe('ProductCard', () => {
});
it('renders correct button text when host not present', () => {
(useValues as jest.Mock).mockImplementation(() => ({ config: { host: '' } }));
setMockValues({ config: { host: '' } });
const wrapper = shallow(<ProductCard product={WORKPLACE_SEARCH_PLUGIN} image="ws.jpg" />);
const card = wrapper.find(EuiCard).dive().shallow();

View file

@ -7,8 +7,7 @@
import React from 'react';
import { shallow } from 'enzyme';
import { setMockValues } from '../__mocks__/kea.mock';
import { rerender } from '../__mocks__';
import { setMockValues, rerender } from '../__mocks__';
import { EnterpriseSearch } from './';
import { SetupGuide } from './components/setup_guide';

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../__mocks__/kea.mock';
import '../../__mocks__/shallow_useeffect.mock';
import { setMockActions, setMockValues } from '../../__mocks__';
import React from 'react';

View file

@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { setMockValues } from '../../__mocks__/kea.mock';
import { mockKibanaValues, mockHistory } from '../../__mocks__';
import { setMockValues, mockKibanaValues, mockHistory } from '../../__mocks__';
jest.mock('../react_router_helpers', () => ({
letBrowserHandleEvent: jest.fn(() => false),

View file

@ -5,8 +5,7 @@
*/
import '../../__mocks__/shallow_useeffect.mock';
import { setMockValues } from '../../__mocks__/kea.mock';
import { mockKibanaValues, mockHistory } from '../../__mocks__';
import { setMockValues, mockKibanaValues, mockHistory } from '../../__mocks__';
import React from 'react';
import { shallow } from 'enzyme';

View file

@ -4,10 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../__mocks__/kea.mock';
import { setMockValues } from '../../__mocks__/kea.mock';
import React from 'react';
import { useValues } from 'kea';
import { shallow } from 'enzyme';
import { EuiButton as EuiButtonExternal, EuiEmptyPrompt } from '@elastic/eui';
@ -45,7 +44,7 @@ describe('NotFound', () => {
});
it('changes the support URL if the user has a gold+ license', () => {
(useValues as jest.Mock).mockReturnValueOnce({ hasGoldLicense: true });
setMockValues({ hasGoldLicense: true });
const wrapper = shallow(<NotFound product={APP_SEARCH_PLUGIN} />);
const prompt = wrapper.find(EuiEmptyPrompt).dive().shallow();

View file

@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { setMockValues } from '../../__mocks__/kea.mock';
import { rerender } from '../../__mocks__';
import { setMockValues, rerender } from '../../__mocks__';
import React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';

View file

@ -4,15 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { resetContext } from 'kea';
import { LogicMounter } from '../__mocks__';
import { DEFAULT_INITIAL_APP_DATA } from '../../../common/__mocks__';
import { AppLogic } from './app_logic';
describe('AppLogic', () => {
const { mount } = new LogicMounter(AppLogic);
beforeEach(() => {
resetContext({});
AppLogic.mount();
mount();
});
const DEFAULT_VALUES = {

View file

@ -5,7 +5,6 @@
*/
import '../__mocks__/shallow_useeffect.mock';
import '../__mocks__/kea.mock';
import { setMockValues, setMockActions, mockKibanaValues } from '../__mocks__';
import React from 'react';

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../../__mocks__/kea.mock';
import '../../../../../__mocks__/shallow_useeffect.mock';
import { setMockActions, setMockValues } from '../../../../../__mocks__';
import {
contentSources,

View file

@ -4,9 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { resetContext } from 'kea';
import {
LogicMounter,
mockFlashMessageHelpers,
mockHttpValues,
expectedAsyncError,
@ -30,6 +29,7 @@ import {
} from './add_source_logic';
describe('AddSourceLogic', () => {
const { mount } = new LogicMounter(AddSourceLogic);
const { http } = mockHttpValues;
const { clearFlashMessages, flashAPIErrors } = mockFlashMessageHelpers;
@ -71,8 +71,7 @@ describe('AddSourceLogic', () => {
beforeEach(() => {
jest.clearAllMocks();
resetContext({});
AddSourceLogic.mount();
mount();
});
it('has expected default values', () => {

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../../__mocks__/kea.mock';
import '../../../../../__mocks__/shallow_useeffect.mock';
import { setMockValues } from '../../../../../__mocks__';
import { mergedAvailableSources } from '../../../../__mocks__/content_sources.mock';

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../../__mocks__/kea.mock';
import '../../../../../__mocks__/shallow_useeffect.mock';
import { setMockActions, setMockValues } from '../../../../../__mocks__';
import React from 'react';

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../../__mocks__/kea.mock';
import '../../../../../__mocks__/shallow_useeffect.mock';
import { setMockActions, setMockValues } from '../../../../../__mocks__';
import React from 'react';

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../../__mocks__/kea.mock';
import '../../../../../__mocks__/shallow_useeffect.mock';
import { setMockActions, setMockValues } from '../../../../../__mocks__';
import React from 'react';

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../../__mocks__/kea.mock';
import '../../../../../__mocks__/shallow_useeffect.mock';
import { setMockActions, setMockValues } from '../../../../../__mocks__';
import React from 'react';

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../../__mocks__/kea.mock';
import '../../../../../__mocks__/shallow_useeffect.mock';
import { setMockActions, setMockValues } from '../../../../../__mocks__';
import React from 'react';

View file

@ -4,9 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../../__mocks__/kea.mock';
import '../../../../../__mocks__/shallow_useeffect.mock';
import { mountAsync, setMockValues } from '../../../../../__mocks__';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockValues, setMockActions } from '../../../../__mocks__';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions } from '../../../../__mocks__';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { users } from '../../../__mocks__/users.mock';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions } from '../../../../__mocks__';
import { users } from '../../../__mocks__/users.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockValues } from '../../../../__mocks__';
import { groups } from '../../../__mocks__/groups.mock';
import { contentSources } from '../../../__mocks__/content_sources.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import { groups } from '../../../__mocks__/groups.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockValues } from '../../../../__mocks__';
import { groups } from '../../../__mocks__/groups.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { contentSources } from '../../../__mocks__/content_sources.mock';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import { users } from '../../../__mocks__/users.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import { groups } from '../../../__mocks__/groups.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { contentSources } from '../../../__mocks__/content_sources.mock';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockValues } from '../../../../__mocks__';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { users } from '../../../__mocks__/users.mock';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockValues } from '../../../../__mocks__';
import { groups } from '../../../__mocks__/groups.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import { groups } from '../../../__mocks__/groups.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import { users } from '../../../__mocks__/users.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import { groups } from '../../../__mocks__/groups.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { contentSources } from '../../../__mocks__/content_sources.mock';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { contentSources } from '../../../__mocks__/content_sources.mock';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import { contentSources } from '../../../__mocks__/content_sources.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import { users } from '../../../__mocks__/users.mock';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { setMockActions, setMockValues } from '../../../../__mocks__';
import React from 'react';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../../__mocks__/kea.mock';
import { users } from '../../../__mocks__/users.mock';
import React from 'react';

View file

@ -4,9 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { resetContext } from 'kea';
import {
LogicMounter,
mockKibanaValues,
mockFlashMessageHelpers,
mockHttpValues,
@ -20,6 +19,7 @@ import { GroupLogic } from './group_logic';
import { GROUPS_PATH } from '../../routes';
describe('GroupLogic', () => {
const { mount } = new LogicMounter(GroupLogic);
const { http } = mockHttpValues;
const { navigateToUrl } = mockKibanaValues;
const {
@ -37,8 +37,7 @@ describe('GroupLogic', () => {
beforeEach(() => {
jest.clearAllMocks();
resetContext({});
GroupLogic.mount();
mount();
});
it('has expected default values', () => {

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../__mocks__/kea.mock';
import '../../../__mocks__/shallow_useeffect.mock';
import { setMockValues, setMockActions } from '../../../__mocks__';
import React from 'react';

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../__mocks__/kea.mock';
import '../../../__mocks__/shallow_useeffect.mock';
import { setMockActions, setMockValues } from '../../../__mocks__';
import { groups } from '../../__mocks__/groups.mock';

View file

@ -4,9 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { resetContext } from 'kea';
import {
LogicMounter,
mockFlashMessageHelpers,
mockHttpValues,
expectedAsyncError,
} from '../../../__mocks__';
import { mockFlashMessageHelpers, mockHttpValues, expectedAsyncError } from '../../../__mocks__';
import { DEFAULT_META } from '../../../shared/constants';
import { JSON_HEADER as headers } from '../../../../../common/constants';
@ -21,6 +25,7 @@ const TIMEOUT = 400;
const delay = () => new Promise((resolve) => setTimeout(resolve, TIMEOUT));
describe('GroupsLogic', () => {
const { mount } = new LogicMounter(GroupsLogic);
const { http } = mockHttpValues;
const { clearFlashMessages, flashAPIErrors } = mockFlashMessageHelpers;
@ -31,8 +36,7 @@ describe('GroupsLogic', () => {
beforeEach(() => {
jest.clearAllMocks();
resetContext({});
GroupsLogic.mount();
mount();
});
it('has expected default values', () => {

View file

@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../__mocks__/kea.mock';
import '../../../__mocks__/shallow_useeffect.mock';
import { setMockActions } from '../../../__mocks__';
import React from 'react';

View file

@ -4,20 +4,18 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { resetContext } from 'kea';
import { mockHttpValues } from '../../../__mocks__';
import { LogicMounter, mockHttpValues } from '../../../__mocks__';
import { mockOverviewValues } from './__mocks__';
import { OverviewLogic } from './overview_logic';
describe('OverviewLogic', () => {
const { mount } = new LogicMounter(OverviewLogic);
const { http } = mockHttpValues;
beforeEach(() => {
jest.clearAllMocks();
resetContext({});
OverviewLogic.mount();
mount();
});
it('has expected default values', () => {