Skip to content

Commit

Permalink
[Enterprise Search] Miscellaneous test cleanups (#88525)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Constance and kibanamachine authored Jan 19, 2021
1 parent fbf600d commit eb4cb3d
Show file tree
Hide file tree
Showing 66 changed files with 46 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import React from 'react';

import { shallow, ShallowWrapper } from 'enzyme';
import { EuiPanel } from '@elastic/eui';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import React from 'react';

import { shallow } from 'enzyme';

import { ResultField } from './result_field';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import React from 'react';

import { shallow } from 'enzyme';

import { ResultHeader } from './result_header';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import React from 'react';

import { mount } from 'enzyme';

import { ResultHeaderItem } from './result_header_item';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import '../__mocks__/shallow_useeffect.mock';
import '../__mocks__/kea.mock';
import '../__mocks__/enterprise_search_url.mock';
import { setMockValues, setMockActions } from '../__mocks__';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import '../__mocks__/shallow_useeffect.mock';
import '../__mocks__/kea.mock';
import { setMockValues, setMockActions, mockKibanaValues } from '../__mocks__';

import React from 'react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,6 +29,7 @@ import {
} from './add_source_logic';

describe('AddSourceLogic', () => {
const { mount } = new LogicMounter(AddSourceLogic);
const { http } = mockHttpValues;
const { clearFlashMessages, flashAPIErrors } = mockFlashMessageHelpers;

Expand Down Expand Up @@ -71,8 +71,7 @@ describe('AddSourceLogic', () => {

beforeEach(() => {
jest.clearAllMocks();
resetContext({});
AddSourceLogic.mount();
mount();
});

it('has expected default values', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading

0 comments on commit eb4cb3d

Please sign in to comment.