Skip to content

Commit

Permalink
[APM] metadata.branch shim (#51770)
Browse files Browse the repository at this point in the history
Set up the APM public NP plugin to expose the stack version

Since we're not yet running as an NP plugin, we don't get passed a pluginInitializerContext,
so we use a shim in the plugin setup that gets the branch values from ui/metadata for the time being.

Fixes #49327.
  • Loading branch information
smith authored Dec 3, 2019
1 parent be088a1 commit 609a7f5
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 159 deletions.
24 changes: 15 additions & 9 deletions x-pack/legacy/plugins/apm/public/components/app/Home/Home.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
import { shallow } from 'enzyme';
import React from 'react';
import { Home } from '../Home';
import * as plugin from '../../../new-platform/plugin';

jest.spyOn(plugin, 'usePlugins').mockReturnValue(({
apm: { config: {} as plugin.ConfigSchema }
} as unknown) as plugin.ApmPluginStartDeps & {
apm: { config: plugin.ConfigSchema };
});
import { MockPluginContextWrapper } from '../../../utils/testHelpers';

describe('Home component', () => {
it('should render services', () => {
expect(shallow(<Home tab="services" />)).toMatchSnapshot();
expect(
shallow(
<MockPluginContextWrapper>
<Home tab="services" />
</MockPluginContextWrapper>
)
).toMatchSnapshot();
});

it('should render traces', () => {
expect(shallow(<Home tab="traces" />)).toMatchSnapshot();
expect(
shallow(
<MockPluginContextWrapper>
<Home tab="traces" />
</MockPluginContextWrapper>
)
).toMatchSnapshot();
});
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { UpdateBreadcrumbs } from '../UpdateBreadcrumbs';
import * as kibanaCore from '../../../../../../observability/public/context/kibana_core';
import { getRoutes } from '../route_config';

jest.mock('ui/index_patterns');

const coreMock = {
chrome: {
setBreadcrumbs: jest.fn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

import React from 'react';
import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui';
import { metadata } from 'ui/metadata';

// TODO: metadata should be read from a useContext hook in new platform
const STACK_VERSION = metadata.branch;
import { usePlugins } from '../../../new-platform/plugin';

// union type constisting of valid guide sections that we link to
type DocsSection = '/apm/get-started' | '/x-pack' | '/apm/server';
Expand All @@ -20,6 +17,8 @@ interface Props extends EuiLinkAnchorProps {
}

export function ElasticDocsLink({ section, path, ...rest }: Props) {
const href = `https://www.elastic.co/guide/en${section}/${STACK_VERSION}${path}`;
const { apm } = usePlugins();
const { stackVersion } = apm;
const href = `https://www.elastic.co/guide/en${section}/${stackVersion}${path}`;
return <EuiLink href={href} {...rest} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import { render } from '@testing-library/react';
import { APMError } from '../../../../../../typings/es_schemas/ui/APMError';
import {
expectTextsInDocument,
expectTextsNotInDocument
expectTextsNotInDocument,
MockPluginContextWrapper
} from '../../../../../utils/testHelpers';

const renderOptions = {
wrapper: MockPluginContextWrapper
};

function getError() {
return ({
labels: { someKey: 'labels value' },
Expand All @@ -38,7 +43,7 @@ function getError() {
describe('ErrorMetadata', () => {
it('should render a error with all sections', () => {
const error = getError();
const output = render(<ErrorMetadata error={error} />);
const output = render(<ErrorMetadata error={error} />, renderOptions);

// sections
expectTextsInDocument(output, [
Expand All @@ -57,7 +62,7 @@ describe('ErrorMetadata', () => {

it('should render a error with all included dot notation keys', () => {
const error = getError();
const output = render(<ErrorMetadata error={error} />);
const output = render(<ErrorMetadata error={error} />, renderOptions);

// included keys
expectTextsInDocument(output, [
Expand All @@ -79,7 +84,7 @@ describe('ErrorMetadata', () => {

it('should render a error with all included values', () => {
const error = getError();
const output = render(<ErrorMetadata error={error} />);
const output = render(<ErrorMetadata error={error} />, renderOptions);

// included values
expectTextsInDocument(output, [
Expand All @@ -104,7 +109,7 @@ describe('ErrorMetadata', () => {

it('should render a error with only the required sections', () => {
const error = {} as APMError;
const output = render(<ErrorMetadata error={error} />);
const output = render(<ErrorMetadata error={error} />, renderOptions);

// required sections should be found
expectTextsInDocument(output, ['Labels', 'User']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import { SpanMetadata } from '..';
import { Span } from '../../../../../../typings/es_schemas/ui/Span';
import {
expectTextsInDocument,
expectTextsNotInDocument
expectTextsNotInDocument,
MockPluginContextWrapper
} from '../../../../../utils/testHelpers';

const renderOptions = {
wrapper: MockPluginContextWrapper
};

describe('SpanMetadata', () => {
describe('render', () => {
it('renders', () => {
Expand All @@ -29,7 +34,7 @@ describe('SpanMetadata', () => {
id: '7efbc7056b746fcb'
}
} as unknown) as Span;
const output = render(<SpanMetadata span={span} />);
const output = render(<SpanMetadata span={span} />, renderOptions);
expectTextsInDocument(output, ['Service', 'Agent']);
});
});
Expand All @@ -53,7 +58,7 @@ describe('SpanMetadata', () => {
type: 'external'
}
} as unknown) as Span;
const output = render(<SpanMetadata span={span} />);
const output = render(<SpanMetadata span={span} />, renderOptions);
expectTextsInDocument(output, ['Service', 'Agent', 'Span']);
});
});
Expand All @@ -76,7 +81,7 @@ describe('SpanMetadata', () => {
type: 'external'
}
} as unknown) as Span;
const output = render(<SpanMetadata span={span} />);
const output = render(<SpanMetadata span={span} />, renderOptions);
expectTextsInDocument(output, ['Service', 'Agent']);
expectTextsNotInDocument(output, ['Span']);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import { render } from '@testing-library/react';
import { Transaction } from '../../../../../../typings/es_schemas/ui/Transaction';
import {
expectTextsInDocument,
expectTextsNotInDocument
expectTextsNotInDocument,
MockPluginContextWrapper
} from '../../../../../utils/testHelpers';

const renderOptions = {
wrapper: MockPluginContextWrapper
};

function getTransaction() {
return ({
labels: { someKey: 'labels value' },
Expand All @@ -38,7 +43,10 @@ function getTransaction() {
describe('TransactionMetadata', () => {
it('should render a transaction with all sections', () => {
const transaction = getTransaction();
const output = render(<TransactionMetadata transaction={transaction} />);
const output = render(
<TransactionMetadata transaction={transaction} />,
renderOptions
);

// sections
expectTextsInDocument(output, [
Expand All @@ -57,7 +65,10 @@ describe('TransactionMetadata', () => {

it('should render a transaction with all included dot notation keys', () => {
const transaction = getTransaction();
const output = render(<TransactionMetadata transaction={transaction} />);
const output = render(
<TransactionMetadata transaction={transaction} />,
renderOptions
);

// included keys
expectTextsInDocument(output, [
Expand All @@ -82,7 +93,10 @@ describe('TransactionMetadata', () => {

it('should render a transaction with all included values', () => {
const transaction = getTransaction();
const output = render(<TransactionMetadata transaction={transaction} />);
const output = render(
<TransactionMetadata transaction={transaction} />,
renderOptions
);

// included values
expectTextsInDocument(output, [
Expand All @@ -107,7 +121,10 @@ describe('TransactionMetadata', () => {

it('should render a transaction with only the required sections', () => {
const transaction = {} as Transaction;
const output = render(<TransactionMetadata transaction={transaction} />);
const output = render(
<TransactionMetadata transaction={transaction} />,
renderOptions
);

// required sections should be found
expectTextsInDocument(output, ['Labels', 'User']);
Expand Down
Loading

0 comments on commit 609a7f5

Please sign in to comment.