mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Improve jest mocking infrastructure (#38760)
* Always mock metadata/chrome in OSS * Enable jest env in jest mocks * Exclude jest mocks in karma bundles * Use setupFilesAfterEnv in config * Remove chrome/metadata mock from x-pack * Remove kuery mock * Add missing mock to SIEM test * Fix typo in mock import * Remove top level capabilities x-pack mock * Move kfetch mock to ui/public * Move moment-timezone to mocks file * Unmock kfetch in kfetch specific tests * Make kfetch mock manual * Removed unnecessary jest.mock * Remove kfetch unmocks
This commit is contained in:
parent
c22b706b25
commit
2d37b05a43
64 changed files with 240 additions and 175 deletions
|
@ -3,6 +3,7 @@ module.exports = {
|
|||
{
|
||||
files: [
|
||||
'**/*.{test,test.mocks,mock}.{js,ts,tsx}',
|
||||
'**/__mocks__/**/*.{js,ts,tsx}',
|
||||
],
|
||||
plugins: [
|
||||
'jest',
|
||||
|
|
|
@ -65,6 +65,9 @@ export default {
|
|||
'<rootDir>/src/dev/jest/setup/polyfills.js',
|
||||
'<rootDir>/src/dev/jest/setup/enzyme.js',
|
||||
],
|
||||
setupFilesAfterEnv: [
|
||||
'<rootDir>/src/dev/jest/setup/mocks.js',
|
||||
],
|
||||
coverageDirectory: '<rootDir>/target/jest-coverage',
|
||||
coverageReporters: [
|
||||
'html',
|
||||
|
|
48
src/dev/jest/setup/mocks.js
Normal file
48
src/dev/jest/setup/mocks.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/* eslint-env jest */
|
||||
|
||||
/**
|
||||
* READ THIS BEFORE ADDING NEW MOCKS TO THIS FILE!
|
||||
*
|
||||
* This file should be loaded via `setupFilesAfterEnv` in all jest configs of the project.
|
||||
* It instantiates some of the very basic mocks that should be available in all jest tests.
|
||||
* Most of the mocks should just be instantiated in the test suites that require them.
|
||||
* We only activate a very rare amount of mocks here, that are used somewhere down the dependency
|
||||
* tree in nearly every test and their implementation is never working without mocking in any tests.
|
||||
* Before adding a mock here it should be considered, whether it's not better to instantiate that mock
|
||||
* in the test suites that needs them individually and if it's really needed to have that mock enabled
|
||||
* for all jest tests by default.
|
||||
*
|
||||
* The mocks that are enabled that way live inside the `__mocks__` folders beside their implementation files.
|
||||
*/
|
||||
|
||||
jest.mock('ui/metadata');
|
||||
jest.mock('ui/chrome');
|
||||
|
||||
jest.mock('moment-timezone', () => {
|
||||
// We always want to mock the timezone moment-timezone guesses, since otherwise
|
||||
// test results might be depending on which time zone you are running them.
|
||||
// Using that mock we always make sure moment.tz.guess is always returning the same
|
||||
// timezone in all tests.
|
||||
const moment = jest.requireActual('moment-timezone');
|
||||
moment.tz.guess = () => 'America/New_York';
|
||||
return moment;
|
||||
});
|
|
@ -50,7 +50,7 @@ exports[`LanguageSwitcher should toggle off if language is lucene 1`] = `
|
|||
Object {
|
||||
"docsLink": <EuiLink
|
||||
color="primary"
|
||||
href="https://www.elastic.co/guide/en/kibana/foo/kuery-query.html"
|
||||
href="https://www.elastic.co/guide/en/kibana/jest-metadata-mock-branch/kuery-query.html"
|
||||
target="_blank"
|
||||
type="button"
|
||||
>
|
||||
|
@ -152,7 +152,7 @@ exports[`LanguageSwitcher should toggle on if language is kuery 1`] = `
|
|||
Object {
|
||||
"docsLink": <EuiLink
|
||||
color="primary"
|
||||
href="https://www.elastic.co/guide/en/kibana/foo/kuery-query.html"
|
||||
href="https://www.elastic.co/guide/en/kibana/jest-metadata-mock-branch/kuery-query.html"
|
||||
target="_blank"
|
||||
type="button"
|
||||
>
|
||||
|
|
|
@ -17,12 +17,6 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
jest.mock('ui/metadata', () => ({
|
||||
metadata: {
|
||||
branch: 'foo',
|
||||
},
|
||||
}));
|
||||
|
||||
import { shallow } from 'enzyme';
|
||||
import React from 'react';
|
||||
import { QueryLanguageSwitcher } from './language_switcher';
|
||||
|
|
|
@ -78,11 +78,6 @@ jest.mock('ui/kfetch', () => ({
|
|||
jest.mock('ui/persisted_log', () => ({
|
||||
PersistedLog: mockPersistedLogFactory,
|
||||
}));
|
||||
jest.mock('ui/metadata', () => ({
|
||||
metadata: {
|
||||
branch: 'foo',
|
||||
},
|
||||
}));
|
||||
jest.mock('ui/autocomplete_providers', () => ({
|
||||
getAutocompleteProvider: mockGetAutocompleteProvider,
|
||||
}));
|
||||
|
|
|
@ -47,13 +47,6 @@ jest.doMock('ui/new_platform', () => {
|
|||
};
|
||||
});
|
||||
|
||||
jest.doMock('ui/metadata', () => ({
|
||||
metadata: {
|
||||
branch: 'my-metadata-branch',
|
||||
version: 'my-metadata-version',
|
||||
},
|
||||
}));
|
||||
|
||||
jest.doMock('ui/capabilities', () => ({
|
||||
uiCapabilities: {
|
||||
visualize: {
|
||||
|
|
|
@ -18,12 +18,6 @@
|
|||
*/
|
||||
|
||||
jest.mock('ui/chrome', () => ({ getKibanaVersion: () => '6.0.0' }), { virtual: true });
|
||||
jest.mock('ui/metadata', () => ({
|
||||
metadata: {
|
||||
branch: 'my-metadata-branch',
|
||||
version: 'my-metadata-version',
|
||||
},
|
||||
}));
|
||||
|
||||
import { DEFAULT_PANEL_HEIGHT, DEFAULT_PANEL_WIDTH } from '../dashboard_constants';
|
||||
import { SavedDashboardPanel } from '../types';
|
||||
|
|
|
@ -27,11 +27,3 @@ jest.doMock('ui/new_platform', () => ({
|
|||
}
|
||||
},
|
||||
}));
|
||||
|
||||
// Make importing the ui/notify module work in jest
|
||||
jest.doMock('ui/metadata', () => ({
|
||||
metadata: {
|
||||
branch: 'my-metadata-branch',
|
||||
version: 'my-metadata-version'
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -36,6 +36,7 @@ const findSourceFiles = async (patterns, cwd = fromRoot('.')) => {
|
|||
'**/_*.js',
|
||||
'**/*.test.js',
|
||||
'**/*.test.mocks.js',
|
||||
'**/__mocks__/**/*',
|
||||
],
|
||||
symlinks: findSourceFiles.symlinks,
|
||||
statCache: findSourceFiles.statCache,
|
||||
|
|
25
src/legacy/ui/public/__mocks__/metadata.ts
Normal file
25
src/legacy/ui/public/__mocks__/metadata.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { metadata as metadataImpl } from '../metadata';
|
||||
|
||||
export const metadata: typeof metadataImpl = {
|
||||
branch: 'jest-metadata-mock-branch',
|
||||
version: '42.23.26',
|
||||
};
|
38
src/legacy/ui/public/chrome/__mocks__/index.js
Normal file
38
src/legacy/ui/public/chrome/__mocks__/index.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { uiSettingsServiceMock } from '../../../../../core/public/mocks';
|
||||
|
||||
const uiSettingsClient = {
|
||||
...uiSettingsServiceMock.createSetupContract(),
|
||||
getUpdate$: () => ({
|
||||
subscribe: jest.fn(),
|
||||
}),
|
||||
};
|
||||
|
||||
const chrome = {
|
||||
getBasePath: () => '/test/base/path',
|
||||
addBasePath: path => path,
|
||||
getInjected: jest.fn(),
|
||||
getUiSettingsClient: () => uiSettingsClient,
|
||||
getXsrfToken: () => 'kbn-xsrf-token',
|
||||
};
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default chrome;
|
|
@ -16,3 +16,5 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
export const kfetch = () => Promise.resolve();
|
|
@ -34,6 +34,9 @@ export function createJestConfig({
|
|||
`<rootDir>/dev-tools/jest/setup/polyfills.js`,
|
||||
`<rootDir>/dev-tools/jest/setup/enzyme.js`,
|
||||
],
|
||||
setupFilesAfterEnv: [
|
||||
`${kibanaDirectory}/src/dev/jest/setup/mocks.js`,
|
||||
],
|
||||
testMatch: [
|
||||
'**/*.test.{js,ts,tsx}'
|
||||
],
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
const moment = require('moment-timezone');
|
||||
moment.tz.guess = () => {
|
||||
return 'America/New_York';
|
||||
};
|
||||
module.exports = moment;
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* 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 { UICapabilities } from 'ui/capabilities';
|
||||
|
||||
let internals: UICapabilities = {
|
||||
navLinks: {},
|
||||
management: {},
|
||||
catalogue: {},
|
||||
spaces: {
|
||||
manage: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const capabilities = {
|
||||
get: () =>
|
||||
new Proxy(
|
||||
{},
|
||||
{
|
||||
get: (target, property) => {
|
||||
return internals[String(property)] as any;
|
||||
},
|
||||
}
|
||||
),
|
||||
};
|
||||
|
||||
export function setMockCapabilities(mockCapabilities: UICapabilities) {
|
||||
internals = mockCapabilities;
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* 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 { uiCapabilities } from './capabilities';
|
||||
|
||||
function getUiSettingsClient() {
|
||||
return {
|
||||
get: key => {
|
||||
switch (key) {
|
||||
case 'timepicker:timeDefaults':
|
||||
return { from: 'now-15m', to: 'now', mode: 'quick' };
|
||||
case 'timepicker:refreshIntervalDefaults':
|
||||
return { pause: false, value: 0 };
|
||||
case 'siem:defaultIndex':
|
||||
return ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'];
|
||||
default:
|
||||
throw new Error(`Unexpected config key: ${key}`);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function getBasePath() {
|
||||
return '/some/base/path';
|
||||
}
|
||||
|
||||
function addBasePath(path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
function getInjected(key) {
|
||||
switch (key) {
|
||||
case 'apmIndexPattern':
|
||||
return 'apm*';
|
||||
case 'mlEnabled':
|
||||
return true;
|
||||
case 'uiCapabilities':
|
||||
return uiCapabilities;
|
||||
case 'isCloudEnabled':
|
||||
return false;
|
||||
case 'siem:defaultIndex':
|
||||
return ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'];
|
||||
default:
|
||||
throw new Error(`Unexpected config key: ${key}`);
|
||||
}
|
||||
}
|
||||
|
||||
function getXsrfToken() {
|
||||
return 'kbn';
|
||||
}
|
||||
|
||||
export default {
|
||||
getInjected,
|
||||
addBasePath,
|
||||
getBasePath,
|
||||
getUiSettingsClient,
|
||||
getXsrfToken,
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const kfetch = () => {
|
||||
return Promise.resolve('mock value');
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export function fromKueryExpression() {}
|
||||
export function toElasticsearchQuery() {}
|
||||
export function getSuggestionsProvider() {}
|
|
@ -1,10 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const metadata = {
|
||||
branch: 'my-metadata-branch',
|
||||
version: 'my-metadata-version'
|
||||
};
|
|
@ -10,6 +10,8 @@ import React from 'react';
|
|||
import { mockMoment } from '../../../../utils/testHelpers';
|
||||
import { DetailView } from './index';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('DetailView', () => {
|
||||
beforeEach(() => {
|
||||
// Avoid timezone issues
|
||||
|
|
|
@ -8,6 +8,8 @@ import { shallow } from 'enzyme';
|
|||
import React from 'react';
|
||||
import { Home } from '../Home';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('Home component', () => {
|
||||
it('should render', () => {
|
||||
expect(shallow(<Home />)).toMatchSnapshot();
|
||||
|
|
|
@ -10,6 +10,8 @@ import { MemoryRouter } from 'react-router-dom';
|
|||
import chrome from 'ui/chrome';
|
||||
import { UpdateBreadcrumbs } from '../UpdateBreadcrumbs';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
jest.mock(
|
||||
'ui/chrome',
|
||||
() => ({
|
||||
|
|
|
@ -14,6 +14,8 @@ import * as rest from '../../../../../services/rest/watcher';
|
|||
import { createErrorGroupWatch } from '../createErrorGroupWatch';
|
||||
import { esResponse } from './esResponse';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
// disable html escaping since this is also disabled in watcher\s mustache implementation
|
||||
mustache.escape = value => value;
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ import * as apmRestServices from '../../../../services/rest/apm/services';
|
|||
import { ServiceOverview } from '..';
|
||||
import * as hooks from '../../../../hooks/useUrlParams';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
function renderServiceOverview() {
|
||||
return render(<ServiceOverview />);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import { TransactionOverview } from '..';
|
|||
import * as hooks from '../../../../hooks/useLocation';
|
||||
import { history } from '../../../../utils/history';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
// Suppress warnings about "act" until async/await syntax is supported: https://github.com/facebook/react/issues/14769
|
||||
/* eslint-disable no-console */
|
||||
const originalError = console.error;
|
||||
|
|
|
@ -10,6 +10,8 @@ import React from 'react';
|
|||
import { APMError } from '../../../../../../typings/es_schemas/ui/APMError';
|
||||
import { DiscoverErrorLink } from '../DiscoverErrorLink';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('DiscoverErrorLink without kuery', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -10,6 +10,8 @@ import React from 'react';
|
|||
import { APMError } from '../../../../../../typings/es_schemas/ui/APMError';
|
||||
import { DiscoverErrorLink } from '../DiscoverErrorLink';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('DiscoverErrorLink without kuery', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -15,6 +15,8 @@ import { DiscoverErrorLink } from '../DiscoverErrorLink';
|
|||
import { DiscoverSpanLink } from '../DiscoverSpanLink';
|
||||
import { DiscoverTransactionLink } from '../DiscoverTransactionLink';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
jest
|
||||
.spyOn(savedObjects, 'getAPMIndexPattern')
|
||||
.mockReturnValue(
|
||||
|
|
|
@ -14,6 +14,8 @@ import {
|
|||
} from '../DiscoverTransactionLink';
|
||||
import mockTransaction from './mockTransaction.json';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('DiscoverTransactionLink component', () => {
|
||||
it('should render with data', () => {
|
||||
const transaction: Transaction = mockTransaction;
|
||||
|
|
|
@ -10,6 +10,8 @@ import { Transaction } from '../../../../../../typings/es_schemas/ui/Transaction
|
|||
import configureStore from '../../../../../store/config/configureStore';
|
||||
import { getDiscoverQuery } from '../DiscoverTransactionLink';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
function getMockTransaction() {
|
||||
return {
|
||||
transaction: {
|
||||
|
|
|
@ -11,6 +11,8 @@ import { MLLink } from './MLLink';
|
|||
import chrome from 'ui/chrome';
|
||||
import * as savedObjects from '../../../../services/rest/savedObjects';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
jest
|
||||
.spyOn(chrome, 'addBasePath')
|
||||
.mockImplementation(path => `/basepath${path}`);
|
||||
|
|
|
@ -13,6 +13,8 @@ import * as Transactions from './mockData';
|
|||
import * as hooks from '../../../../hooks/useAPMIndexPattern';
|
||||
import { ISavedObject } from '../../../../services/rest/savedObjects';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
const renderTransaction = async (transaction: Record<string, any>) => {
|
||||
const rendered = render(
|
||||
<TransactionActionMenu transaction={transaction as Transaction} />
|
||||
|
|
|
@ -9,6 +9,8 @@ import { mockNow } from '../../utils/testHelpers';
|
|||
import { _clearCache, callApi } from '../rest/callApi';
|
||||
import { SessionStorageMock } from './SessionStorageMock';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('callApi', () => {
|
||||
let kfetchSpy: jest.Mock;
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ import { AutocompleteSuggestionType } from '../suggestions';
|
|||
import props from './__fixtures__/props.json';
|
||||
import { CodeQueryBar } from './query_bar';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
// Injest a mock random function to fixiate the output for generating component id.
|
||||
const mockMath = Object.create(global.Math);
|
||||
mockMath.random = () => 0.5;
|
||||
|
|
|
@ -12,6 +12,8 @@ import { MemoryRouter } from 'react-router-dom';
|
|||
import props from '../__fixtures__/props.json';
|
||||
import { SuggestionsComponent } from './suggestions_component';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
test('render empty suggestions component', () => {
|
||||
const emptyFn = () => {
|
||||
return;
|
||||
|
|
|
@ -102,7 +102,7 @@ exports[`RuleEditorFlyout renders the flyout after adding a condition to a rule
|
|||
Object {
|
||||
"learnMoreLink": <EuiLink
|
||||
color="primary"
|
||||
href="https://www.elastic.co/guide/en/elastic-stack-overview/my-metadata-branch/ml-rules.html"
|
||||
href="https://www.elastic.co/guide/en/elastic-stack-overview/jest-metadata-mock-branch/ml-rules.html"
|
||||
target="_blank"
|
||||
type="button"
|
||||
>
|
||||
|
@ -376,7 +376,7 @@ exports[`RuleEditorFlyout renders the flyout after setting the rule to edit 1`]
|
|||
Object {
|
||||
"learnMoreLink": <EuiLink
|
||||
color="primary"
|
||||
href="https://www.elastic.co/guide/en/elastic-stack-overview/my-metadata-branch/ml-rules.html"
|
||||
href="https://www.elastic.co/guide/en/elastic-stack-overview/jest-metadata-mock-branch/ml-rules.html"
|
||||
target="_blank"
|
||||
type="button"
|
||||
>
|
||||
|
@ -636,7 +636,7 @@ exports[`RuleEditorFlyout renders the flyout for creating a rule with conditions
|
|||
Object {
|
||||
"learnMoreLink": <EuiLink
|
||||
color="primary"
|
||||
href="https://www.elastic.co/guide/en/elastic-stack-overview/my-metadata-branch/ml-rules.html"
|
||||
href="https://www.elastic.co/guide/en/elastic-stack-overview/jest-metadata-mock-branch/ml-rules.html"
|
||||
target="_blank"
|
||||
type="button"
|
||||
>
|
||||
|
|
|
@ -60,7 +60,7 @@ exports[`ValidateJob renders button and modal with a message 1`] = `
|
|||
Object {
|
||||
"mlJobTipsLink": <EuiLink
|
||||
color="primary"
|
||||
href="https://www.elastic.co/guide/en/kibana/my-metadata-branch/job-tips.html"
|
||||
href="https://www.elastic.co/guide/en/kibana/jest-metadata-mock-branch/job-tips.html"
|
||||
target="_blank"
|
||||
type="button"
|
||||
>
|
||||
|
@ -148,7 +148,7 @@ exports[`ValidateJob renders the button and modal with a success message 1`] = `
|
|||
Object {
|
||||
"mlJobTipsLink": <EuiLink
|
||||
color="primary"
|
||||
href="https://www.elastic.co/guide/en/kibana/my-metadata-branch/job-tips.html"
|
||||
href="https://www.elastic.co/guide/en/kibana/jest-metadata-mock-branch/job-tips.html"
|
||||
target="_blank"
|
||||
type="button"
|
||||
>
|
||||
|
|
|
@ -93,7 +93,7 @@ exports[`CalendarListsHeader renders header 1`] = `
|
|||
"br": <br />,
|
||||
"learnMoreLink": <EuiLink
|
||||
color="primary"
|
||||
href="https://www.elastic.co/guide/en/elastic-stack-overview/my-metadata-branch/ml-calendars.html"
|
||||
href="https://www.elastic.co/guide/en/elastic-stack-overview/jest-metadata-mock-branch/ml-calendars.html"
|
||||
target="_blank"
|
||||
type="button"
|
||||
>
|
||||
|
|
|
@ -94,7 +94,7 @@ You can use the same filter list in multiple jobs.{br}{learnMoreLink}"
|
|||
"br": <br />,
|
||||
"learnMoreLink": <EuiLink
|
||||
color="primary"
|
||||
href="https://www.elastic.co/guide/en/elastic-stack-overview/my-metadata-branch/ml-rules.html"
|
||||
href="https://www.elastic.co/guide/en/elastic-stack-overview/jest-metadata-mock-branch/ml-rules.html"
|
||||
target="_blank"
|
||||
type="button"
|
||||
>
|
||||
|
|
|
@ -23,6 +23,8 @@ function getConfirmPasswordField(wrapper: ReactWrapper<any>) {
|
|||
return wrapper.find(EuiFieldText).filter('[data-test-subj="confirmNewPassword"]');
|
||||
}
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('<ChangePasswordForm>', () => {
|
||||
describe('for the current user', () => {
|
||||
it('shows fields for current and new passwords', () => {
|
||||
|
|
|
@ -9,6 +9,8 @@ import { ConfirmDeleteUsers } from './confirm_delete';
|
|||
import React from 'react';
|
||||
import { UserAPIClient } from '../../../lib/api';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('ConfirmDeleteUsers', () => {
|
||||
it('renders a warning for a single user', () => {
|
||||
const wrapper = mountWithIntl(
|
||||
|
|
|
@ -7,6 +7,8 @@ import React from 'react';
|
|||
import { mountWithIntl } from 'test_utils/enzyme_helpers';
|
||||
import { AccountManagementPage } from './account_management_page';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
interface Options {
|
||||
withFullName?: boolean;
|
||||
withEmail?: boolean;
|
||||
|
|
|
@ -11,6 +11,8 @@ import { UserAPIClient } from '../../../../lib/api';
|
|||
import { User, Role } from '../../../../../common/model';
|
||||
import { ReactWrapper } from 'enzyme';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
const buildClient = () => {
|
||||
const apiClient = new UserAPIClient();
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ import { UsersListPage } from './users_list_page';
|
|||
import React from 'react';
|
||||
import { ReactWrapper } from 'enzyme';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('UsersListPage', () => {
|
||||
it('renders the list of users', async () => {
|
||||
const apiClient = new UserAPIClient();
|
||||
|
|
|
@ -13,6 +13,7 @@ import { LastEventIndexKey } from '../../graphql/types';
|
|||
import { mockLastEventTimeQuery } from '../../containers/events/last_event_time/mock';
|
||||
import { wait } from '../../lib/helpers';
|
||||
import { TestProviders } from '../../mock';
|
||||
import '../../mock/ui_settings';
|
||||
|
||||
import { LastEventTime } from '.';
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import { render } from 'react-testing-library';
|
|||
import { mockFirstLastSeenHostQuery } from '../../../../containers/hosts/first_last_seen/mock';
|
||||
import { wait } from '../../../../lib/helpers';
|
||||
import { TestProviders } from '../../../../mock';
|
||||
import '../../../../mock/ui_settings';
|
||||
|
||||
import { FirstLastSeenHost, FirstLastSeenHostType } from '.';
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import { mockFirstLastSeenDomainQuery } from '../../../../containers/domains/fir
|
|||
import { FlowTarget } from '../../../../graphql/types';
|
||||
import { wait } from '../../../../lib/helpers';
|
||||
import { TestProviders } from '../../../../mock';
|
||||
import '../../../../mock/ui_settings';
|
||||
|
||||
import { FirstLastSeenDomain } from './index';
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ import { MockedProvider } from 'react-apollo/test-utils';
|
|||
|
||||
import { wait } from '../../lib/helpers';
|
||||
|
||||
import '../../mock/ui_settings';
|
||||
|
||||
import { WithSource, indicesExistOrDataTemporarilyUnavailable } from '.';
|
||||
import { mockBrowserFields, mockIndexFields, mocksSource } from './mock';
|
||||
|
||||
|
|
20
x-pack/plugins/siem/public/mock/ui_settings.ts
Normal file
20
x-pack/plugins/siem/public/mock/ui_settings.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* 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 chrome from 'ui/chrome';
|
||||
|
||||
chrome.getUiSettingsClient().get.mockImplementation((key: string) => {
|
||||
switch (key) {
|
||||
case 'timepicker:timeDefaults':
|
||||
return { from: 'now-15m', to: 'now', mode: 'quick' };
|
||||
case 'timepicker:refreshIntervalDefaults':
|
||||
return { pause: false, value: 0 };
|
||||
case 'siem:defaultIndex':
|
||||
return ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'];
|
||||
default:
|
||||
throw new Error(`Unexpected config key: ${key}`);
|
||||
}
|
||||
});
|
|
@ -9,6 +9,7 @@ import * as React from 'react';
|
|||
import { Router } from 'react-router-dom';
|
||||
|
||||
import '../../mock/match_media';
|
||||
import '../../mock/ui_settings';
|
||||
import { Hosts } from './hosts';
|
||||
|
||||
import { mocksSource } from '../../containers/source/mock';
|
||||
|
|
|
@ -11,6 +11,7 @@ import { Router } from 'react-router-dom';
|
|||
import { MockedProvider } from 'react-apollo/test-utils';
|
||||
|
||||
import '../../mock/match_media';
|
||||
import '../../mock/ui_settings';
|
||||
import { apolloClientObservable, mockGlobalState, TestProviders } from '../../mock';
|
||||
import { IPDetailsComponent, IPDetails } from './ip_details';
|
||||
import { FlowTarget } from '../../graphql/types';
|
||||
|
|
|
@ -9,6 +9,7 @@ import * as React from 'react';
|
|||
import { Router } from 'react-router-dom';
|
||||
|
||||
import '../../mock/match_media';
|
||||
import '../../mock/ui_settings';
|
||||
import { Network } from './network';
|
||||
|
||||
import { mocksSource } from '../../containers/source/mock';
|
||||
|
|
|
@ -9,6 +9,7 @@ import * as React from 'react';
|
|||
|
||||
import { Overview } from './index';
|
||||
|
||||
import '../../mock/ui_settings';
|
||||
import { mocksSource } from '../../containers/source/mock';
|
||||
import { TestProviders } from '../../mock';
|
||||
import { MockedProvider } from 'react-apollo/test-utils';
|
||||
|
|
24
x-pack/plugins/spaces/public/__mocks__/ui_capabilities.ts
Normal file
24
x-pack/plugins/spaces/public/__mocks__/ui_capabilities.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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('ui/capabilities', () => ({
|
||||
capabilities: {
|
||||
get: jest.fn().mockReturnValue({
|
||||
navLinks: {},
|
||||
management: {},
|
||||
catalogue: {},
|
||||
spaces: {
|
||||
manage: true,
|
||||
},
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
import { capabilities, UICapabilities } from 'ui/capabilities';
|
||||
|
||||
export function setMockCapabilities(mockCapabilities: UICapabilities) {
|
||||
((capabilities.get as unknown) as jest.Mock).mockReturnValue(mockCapabilities);
|
||||
}
|
|
@ -3,9 +3,10 @@
|
|||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { setMockCapabilities } from '../__mocks__/ui_capabilities';
|
||||
import React from 'react';
|
||||
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
|
||||
import { setMockCapabilities } from '../../../__mocks__/ui/capabilities';
|
||||
import { ManageSpacesButton } from './manage_spaces_button';
|
||||
|
||||
describe('ManageSpacesButton', () => {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
import React from 'react';
|
||||
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
|
||||
import { setMockCapabilities } from '../../../../../../__mocks__/ui/capabilities';
|
||||
import { setMockCapabilities } from '../../../../__mocks__/ui_capabilities';
|
||||
import { SecureSpaceMessage } from './secure_space_message';
|
||||
|
||||
describe('SecureSpaceMessage', () => {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
jest.mock('ui/kfetch', () => ({
|
||||
kfetch: () => Promise.resolve([{ id: 'foo', name: 'foo', app: [], privileges: {} }]),
|
||||
}));
|
||||
import '../../../__mocks__/ui_capabilities';
|
||||
import { EuiButton, EuiLink, EuiSwitch } from '@elastic/eui';
|
||||
import { ReactWrapper } from 'enzyme';
|
||||
import React from 'react';
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
jest.mock('ui/kfetch', () => ({
|
||||
kfetch: () => Promise.resolve([]),
|
||||
}));
|
||||
import '../../../__mocks__/ui_capabilities';
|
||||
import React from 'react';
|
||||
import { mountWithIntl, shallowWithIntl } from 'test_utils/enzyme_helpers';
|
||||
import { SpaceAvatar } from '../../../components';
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
import React from 'react';
|
||||
import { mountWithIntl } from 'test_utils/enzyme_helpers';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
jest.mock('axios', () => ({
|
||||
get: jest.fn(),
|
||||
create: jest.fn(),
|
||||
|
|
|
@ -11,6 +11,8 @@ import { LoadingState } from '../../types';
|
|||
import AssistanceData from '../__fixtures__/checkup_api_response.json';
|
||||
import { CheckupTab } from './checkup_tab';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
const defaultProps = {
|
||||
checkupLabel: 'index',
|
||||
deprecations: AssistanceData.indices,
|
||||
|
|
|
@ -15,6 +15,8 @@ import { EnrichedDeprecationInfo } from '../../../../../server/lib/es_migration_
|
|||
import { GroupByOption, LevelFilterOption } from '../../../types';
|
||||
import { DeprecationAccordion, filterDeps, GroupedDeprecations } from './grouped';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('filterDeps', () => {
|
||||
test('filters on levels', () => {
|
||||
const fd = filterDeps(LevelFilterOption.critical);
|
||||
|
|
|
@ -9,6 +9,8 @@ import { shallowWithIntl } from 'test_utils/enzyme_helpers';
|
|||
|
||||
import { IndexDeprecationTableProps, IndexDeprecationTableUI } from './index_table';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('IndexDeprecationTable', () => {
|
||||
const defaultProps = {
|
||||
indices: [
|
||||
|
|
|
@ -11,6 +11,8 @@ import { EnrichedDeprecationInfo } from '../../../../../server/lib/es_migration_
|
|||
import { GroupByOption } from '../../../types';
|
||||
import { DeprecationList } from './list';
|
||||
|
||||
jest.mock('ui/kfetch');
|
||||
|
||||
describe('DeprecationList', () => {
|
||||
describe('group by message', () => {
|
||||
const defaultProps = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue