Skip to content

Commit

Permalink
Merge branch 'master' into alerting/restructure-docs-3
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Jun 9, 2021
2 parents 493ae59 + d3ce128 commit cee6d04
Show file tree
Hide file tree
Showing 382 changed files with 3,010 additions and 1,749 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ module.exports = {
{
// Source files only - allow `any` in test/mock files
files: ['x-pack/plugins/enterprise_search/**/*.{ts,tsx}'],
excludedFiles: ['x-pack/plugins/enterprise_search/**/*.{test,mock}.{ts,tsx}'],
excludedFiles: ['x-pack/plugins/enterprise_search/**/*.{test,mock,test_helper}.{ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
},
Expand Down
109 changes: 54 additions & 55 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { i18n } from '@kbn/i18n';
import { of } from 'rxjs';
import { from } from 'rxjs';
import { map } from 'rxjs/operators';
import type { ConfigSchema } from '.';
import {
AppMountParameters,
Expand Down Expand Up @@ -86,19 +87,56 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
pluginSetupDeps.home.featureCatalogue.register(featureCatalogueEntry);
}

// register observability nav
const servicesTitle = i18n.translate('xpack.apm.navigation.servicesTitle', {
defaultMessage: 'Services',
});
const tracesTitle = i18n.translate('xpack.apm.navigation.tracesTitle', {
defaultMessage: 'Traces',
});
const serviceMapTitle = i18n.translate(
'xpack.apm.navigation.serviceMapTitle',
{ defaultMessage: 'Service Map' }
);

// register observability nav if user has access to plugin
plugins.observability.navigation.registerSections(
of([
{
label: 'APM',
sortKey: 200,
entries: [
{ label: 'Services', app: 'apm', path: '/services' },
{ label: 'Traces', app: 'apm', path: '/traces' },
{ label: 'Service Map', app: 'apm', path: '/service-map' },
],
},
])
from(core.getStartServices()).pipe(
map(([coreStart]) => {
if (coreStart.application.capabilities.apm.show) {
return [
// APM navigation
{
label: 'APM',
sortKey: 200,
entries: [
{ label: servicesTitle, app: 'apm', path: '/services' },
{ label: tracesTitle, app: 'apm', path: '/traces' },
{ label: serviceMapTitle, app: 'apm', path: '/service-map' },
],
},

// UX navigation
{
label: 'User Experience',
sortKey: 201,
entries: [
{
label: i18n.translate('xpack.apm.ux.overview.heading', {
defaultMessage: 'Overview',
}),
app: 'ux',
path: '/',
matchFullPath: true,
ignoreTrailingSlash: true,
},
],
},
];
}

return [];
})
)
);

const getApmDataHelper = async () => {
Expand Down Expand Up @@ -150,26 +188,6 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
},
});

plugins.observability.navigation.registerSections(
of([
{
label: 'User Experience',
sortKey: 201,
entries: [
{
label: i18n.translate('xpack.apm.ux.overview.heading', {
defaultMessage: 'Overview',
}),
app: 'ux',
path: '/',
matchFullPath: true,
ignoreTrailingSlash: true,
},
],
},
])
);

core.application.register({
id: 'apm',
title: 'APM',
Expand All @@ -178,29 +196,10 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
appRoute: '/app/apm',
icon: 'plugins/apm/public/icon.svg',
category: DEFAULT_APP_CATEGORIES.observability,
// !! Need to be kept in sync with the routes in x-pack/plugins/apm/public/components/app/Main/route_config/index.tsx
deepLinks: [
{
id: 'services',
title: i18n.translate('xpack.apm.breadcrumb.servicesTitle', {
defaultMessage: 'Services',
}),
path: '/services',
},
{
id: 'traces',
title: i18n.translate('xpack.apm.breadcrumb.tracesTitle', {
defaultMessage: 'Traces',
}),
path: '/traces',
},
{
id: 'service-map',
title: i18n.translate('xpack.apm.breadcrumb.serviceMapTitle', {
defaultMessage: 'Service Map',
}),
path: '/service-map',
},
{ id: 'services', title: servicesTitle, path: '/services' },
{ id: 'traces', title: tracesTitle, path: '/traces' },
{ id: 'service-map', title: serviceMapTitle, path: '/service-map' },
],

async mount(appMountParameters: AppMountParameters<unknown>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const mockFlashMessageHelpers = {
flashErrorToast: jest.fn(),
};

jest.mock('../shared/flash_messages', () => ({
...(jest.requireActual('../shared/flash_messages') as object),
jest.mock('../../shared/flash_messages', () => ({
...(jest.requireActual('../../shared/flash_messages') as object),
...mockFlashMessageHelpers,
FlashMessagesLogic: {
values: mockFlashMessagesValues,
Expand Down
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 }));
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export const mockHttpValues = {
readOnlyMode: false,
};

jest.mock('../shared/http', () => ({
jest.mock('../../shared/http', () => ({
HttpLogic: { values: mockHttpValues },
}));
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

export { mockHistory, mockLocation } from './react_router_history.mock';
export { mockKibanaValues } from './kibana_logic.mock';
export { mockLicensingValues } from './licensing_logic.mock';
export { mockHttpValues } from './http_logic.mock';
Expand All @@ -15,18 +14,6 @@ export {
mockFlashMessagesActions,
mockFlashMessageHelpers,
} from './flash_messages_logic.mock';
export {
mockAllValues,
mockAllActions,
setMockValues,
setMockActions,
LogicMounter,
} from './kea.mock';

export { mountAsync } from './mount_async.mock';
export { mountWithIntl } from './mount_with_i18n.mock';
export { shallowWithIntl } from './shallow_with_i18n.mock';
export { rerender } from './enzyme_rerender.mock';
// Note: shallow_useeffect must be imported directly as a file
export { mockAllValues, mockAllActions, setMockValues, setMockActions } from './hooks.mock';

export { expectedAsyncError } from './expected_async_error';
export { LogicMounter } from './logic_mounter.test_helper';
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { mockHistory } from './react_router_history.mock';
import { chartPluginMock } from '../../../../../../../src/plugins/charts/public/mocks';

import { chartPluginMock } from '../../../../../../src/plugins/charts/public/mocks';
import { mockHistory } from '../react_router/state.mock';

export const mockKibanaValues = {
config: { host: 'http://localhost:3002' },
Expand All @@ -24,6 +24,6 @@ export const mockKibanaValues = {
renderHeaderActions: jest.fn(),
};

jest.mock('../shared/kibana', () => ({
jest.mock('../../shared/kibana', () => ({
KibanaLogic: { values: mockKibanaValues },
}));
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* 2.0.
*/

import { licensingMock } from '../../../../licensing/public/mocks';
import { licensingMock } from '../../../../../licensing/public/mocks';

export const mockLicensingValues = {
license: licensingMock.createLicense(),
hasPlatinumLicense: false,
hasGoldLicense: false,
};

jest.mock('../shared/licensing', () => ({
jest.mock('../../shared/licensing', () => ({
LicensingLogic: { values: mockLicensingValues },
}));
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,14 @@
*/

/**
* 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'; // 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.mock';
* 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 }));
};

/**
* Kea logic helpers
*
* Call this function to mount a logic file and optionally override default values.
* Automatically DRYs out a lot of cruft for us, such as resetting context, creating the
* nested defaults path obj (see https://kea.js.org/docs/api/context#resetcontext), and
* returning an unmount function
*
* Example usage:
*
* import { LogicMounter } from '../../../__mocks__/kea.mock';
* import { LogicMounter } from '../../../__mocks__/kea_logic';
* import { SomeLogic } from './';
*
* const { mount, unmount } = new LogicMounter(SomeLogic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const mockTelemetryActions = {
sendWorkplaceSearchTelemetry: jest.fn(),
};

jest.mock('../shared/telemetry', () => ({
...(jest.requireActual('../shared/telemetry') as object),
jest.mock('../../shared/telemetry', () => ({
...(jest.requireActual('../../shared/telemetry') as object),
TelemetryLogic: { actions: mockTelemetryActions },
}));
Loading

0 comments on commit cee6d04

Please sign in to comment.