Skip to content

Commit

Permalink
start things
Browse files Browse the repository at this point in the history
  • Loading branch information
smith committed Oct 21, 2021
1 parent 26a8d86 commit ad64f06
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 67 deletions.
5 changes: 4 additions & 1 deletion x-pack/plugins/apm/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ module.exports = {
preset: '@kbn/test',
rootDir: path.resolve(__dirname, '../../..'),
roots: ['<rootDir>/x-pack/plugins/apm'],
setupFiles: ['<rootDir>/x-pack/plugins/apm/.storybook/jest_setup.js'],
setupFiles: [
'<rootDir>/x-pack/plugins/apm/jest_setup.js',
'<rootDir>/x-pack/plugins/apm/.storybook/jest_setup.js',
],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/x-pack/plugins/apm',
coverageReporters: ['text', 'html'],
collectCoverageFrom: [
Expand Down
14 changes: 14 additions & 0 deletions x-pack/plugins/apm/jest_setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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.
*/

/* global jest */

// When a `console.error` is encountered, throw the error to make the test fail.
// This effectively treats logged errors during the test run as failures.
jest.spyOn(console, 'error').mockImplementation((message) => {
throw new Error(message);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { __IntlProvider as IntlProvider } from '@kbn/i18n/react';
import { render, screen, waitFor } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import React, { ReactNode } from 'react';
Expand Down Expand Up @@ -49,25 +50,27 @@ function Wrapper({ children }: { children?: ReactNode }) {
}) as unknown as ApmPluginContextValue;

return (
<EuiThemeProvider darkMode={false}>
<KibanaReactContext.Provider>
<MockApmPluginContextWrapper
history={history}
value={mockPluginContext}
>
<MockUrlParamsContextProvider
params={{
rangeFrom: 'now-15m',
rangeTo: 'now',
start: 'mystart',
end: 'myend',
}}
<IntlProvider locale="en">
<EuiThemeProvider darkMode={false}>
<KibanaReactContext.Provider>
<MockApmPluginContextWrapper
history={history}
value={mockPluginContext}
>
{children}
</MockUrlParamsContextProvider>
</MockApmPluginContextWrapper>
</KibanaReactContext.Provider>
</EuiThemeProvider>
<MockUrlParamsContextProvider
params={{
rangeFrom: 'now-15m',
rangeTo: 'now',
start: 'mystart',
end: 'myend',
}}
>
{children}
</MockUrlParamsContextProvider>
</MockApmPluginContextWrapper>
</KibanaReactContext.Provider>
</EuiThemeProvider>
</IntlProvider>
);
}

Expand All @@ -93,13 +96,13 @@ describe('transaction_details/distribution', () => {
}));

render(
<Wrapper>
<TransactionDistribution
onChartSelection={jest.fn()}
onClearSelection={jest.fn()}
traceSamples={[]}
/>
</Wrapper>
<TransactionDistribution
onChartSelection={jest.fn()}
onClearSelection={jest.fn()}
traceSamples={[]}
/>,

{ wrapper: Wrapper }
);

await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const Example: Story<Args> = (args) => {
};
Example.args = {
backendName: 'postgres',
query: {
environment: 'ENVIRONMENT_ALL',
kuery: '',
rangeFrom: 'now-15m',
rangeTo: 'now',
},
type: 'db',
subtype: 'postgresql',
};
19 changes: 19 additions & 0 deletions x-pack/plugins/apm/public/components/shared/backend_link.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/

import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import React from 'react';
import * as stories from './backend_link.stories';

const { Example } = composeStories(stories);

describe('BackendLink', () => {
it('renders', () => {
expect(() => render(<Example />)).not.toThrowError();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import {
ALERT_RULE_UUID,
ALERT_RULE_NAME,
ALERT_RULE_CATEGORY,
ALERT_RULE_CONSUMER,
ALERT_RULE_PRODUCER,
SPACE_IDS,
} from '@kbn/rule-data-utils';
import { StoryContext } from '@storybook/react';
import React, { ComponentType } from 'react';
import { MemoryRouter, Route } from 'react-router-dom';
import { Meta, Story } from '@storybook/react';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public';
import { ENVIRONMENT_ALL } from '../../../../../common/environment_filter_values';
import { LatencyAggregationType } from '../../../../../common/latency_aggregation_types';
import {
ApmPluginContext,
ApmPluginContextValue,
} from '../../../../context/apm_plugin/apm_plugin_context';
import type { ApmPluginContextValue } from '../../../../context/apm_plugin/apm_plugin_context';
import { MockApmPluginContextWrapper } from '../../../../context/apm_plugin/mock_apm_plugin_context';
import { APMServiceContext } from '../../../../context/apm_service/apm_service_context';
import { ChartPointerEventContextProvider } from '../../../../context/chart_pointer_event/chart_pointer_event_context';
import { MockUrlParamsContextProvider } from '../../../../context/url_params_context/mock_url_params_context_provider';
Expand All @@ -46,7 +46,7 @@ interface Args {
latencyChartResponse: APIReturnType<'GET /internal/apm/services/{serviceName}/transactions/charts/latency'>;
}

export default {
const stories: Meta<Args> = {
title: 'shared/charts/LatencyChart',
component: LatencyChart,
argTypes: {
Expand All @@ -57,7 +57,7 @@ export default {
},
},
decorators: [
(Story: ComponentType, { args }: StoryContext) => {
(StoryComponent, { args }) => {
const { alertsResponse, latencyChartResponse } = args as Args;
const serviceName = 'testService';

Expand Down Expand Up @@ -88,44 +88,46 @@ export default {
const transactionType = `${Math.random()}`; // So we don't memoize

return (
<ApmPluginContext.Provider value={apmPluginContextMock}>
<MemoryRouter initialEntries={[`/services/${serviceName}`]}>
<Route path="/services/{serviceName}">
<KibanaContextProvider
services={{ ...apmPluginContextMock.core }}
<MemoryRouter
initialEntries={[
`/services/${serviceName}/overview?environment=ENVIRONMENT_ALL&kuery=&rangeFrom=now-15m&rangeTo=now&transactionType=request&comparisonEnabled=true&comparisonType=day`,
]}
>
<MockApmPluginContextWrapper value={apmPluginContextMock}>
<KibanaContextProvider services={{ ...apmPluginContextMock.core }}>
<MockUrlParamsContextProvider
params={{
latencyAggregationType: LatencyAggregationType.avg,
}}
>
<MockUrlParamsContextProvider
params={{
latencyAggregationType: LatencyAggregationType.avg,
<APMServiceContext.Provider
value={{
alerts: alertsResponse.alerts,
serviceName,
transactionType,
transactionTypes: [],
}}
>
<APMServiceContext.Provider
value={{
alerts: alertsResponse.alerts,
serviceName,
transactionType,
transactionTypes: [],
}}
>
<ChartPointerEventContextProvider>
<Story />
</ChartPointerEventContextProvider>
</APMServiceContext.Provider>
</MockUrlParamsContextProvider>
</KibanaContextProvider>
</Route>
</MemoryRouter>
</ApmPluginContext.Provider>
<ChartPointerEventContextProvider>
<StoryComponent />
</ChartPointerEventContextProvider>
</APMServiceContext.Provider>
</MockUrlParamsContextProvider>
</KibanaContextProvider>
</MockApmPluginContextWrapper>
</MemoryRouter>
);
},
],
};

export function Example(_args: Args) {
export default stories;

export const Example: Story<Args> = () => {
return (
<LatencyChart height={300} environment={ENVIRONMENT_ALL.value} kuery="" />
);
}
};
Example.args = {
alertsResponse: {
alerts: [
Expand All @@ -139,6 +141,7 @@ Example.args = {
tags: ['apm', 'service.name:frontend-rum'],
'transaction.type': ['page-load'],
[ALERT_RULE_PRODUCER]: ['apm'],
[ALERT_RULE_CONSUMER]: ['apm'],
[ALERT_UUID]: ['af2ae371-df79-4fca-b0eb-a2dbd9478180'],
[ALERT_RULE_UUID]: ['82e0ee40-c2f4-11eb-9a42-a9da66a1722f'],
'event.action': ['active'],
Expand All @@ -149,9 +152,11 @@ Example.args = {
[ALERT_START]: ['2021-06-02T04:00:00.000Z'],
'event.kind': ['state'],
[ALERT_RULE_CATEGORY]: ['Latency threshold'],
[SPACE_IDS]: [],
},
{
[ALERT_RULE_TYPE_ID]: ['apm.transaction_duration'],

[ALERT_EVALUATION_VALUE]: [2001708.19],
'service.name': ['frontend-rum'],
[ALERT_RULE_NAME]: ['Latency threshold | frontend-rum'],
Expand All @@ -160,6 +165,7 @@ Example.args = {
tags: ['apm', 'service.name:frontend-rum'],
'transaction.type': ['page-load'],
[ALERT_RULE_PRODUCER]: ['apm'],
[ALERT_RULE_CONSUMER]: ['apm'],
[ALERT_SEVERITY]: ['warning'],
[ALERT_UUID]: ['af2ae371-df79-4fca-b0eb-a2dbd9478181'],
[ALERT_RULE_UUID]: ['82e0ee40-c2f4-11eb-9a42-a9da66a1722f'],
Expand All @@ -171,9 +177,11 @@ Example.args = {
[ALERT_START]: ['2021-06-02T10:45:00.000Z'],
'event.kind': ['state'],
[ALERT_RULE_CATEGORY]: ['Latency threshold'],
[SPACE_IDS]: [],
},
{
[ALERT_RULE_TYPE_ID]: ['apm.transaction_duration'],

[ALERT_EVALUATION_VALUE]: [2001708.19],
'service.name': ['frontend-rum'],
[ALERT_RULE_NAME]: ['Latency threshold | frontend-rum'],
Expand All @@ -182,6 +190,7 @@ Example.args = {
tags: ['apm', 'service.name:frontend-rum'],
'transaction.type': ['page-load'],
[ALERT_RULE_PRODUCER]: ['apm'],
[ALERT_RULE_CONSUMER]: ['apm'],
[ALERT_SEVERITY]: ['critical'],
[ALERT_UUID]: ['af2ae371-df79-4fca-b0eb-a2dbd9478182'],
[ALERT_RULE_UUID]: ['82e0ee40-c2f4-11eb-9a42-a9da66a1722f'],
Expand All @@ -193,6 +202,7 @@ Example.args = {
[ALERT_START]: ['2021-06-02T16:50:00.000Z'],
'event.kind': ['state'],
[ALERT_RULE_CATEGORY]: ['Latency threshold'],
[SPACE_IDS]: [],
},
],
},
Expand Down Expand Up @@ -801,19 +811,24 @@ Example.args = {
},
],
},
previousPeriod: { latencyTimeseries: [] },
previousPeriod: { latencyTimeseries: [], overallAvgDuration: null },
},
};

export function NoData(_args: Args) {
export const NoData: Story<Args> = () => {
return (
<LatencyChart height={300} environment={ENVIRONMENT_ALL.value} kuery="" />
);
}
};
NoData.args = {
alertsResponse: { alerts: [] },
latencyChartResponse: {
currentPeriod: { latencyTimeseries: [] },
previousPeriod: { latencyTimeseries: [] },
anomalyTimeseries: {
jobId: 'apm-production-00aa-high_mean_transaction_duration',
anomalyScore: [],
anomalyBoundaries: [],
},
currentPeriod: { latencyTimeseries: [], overallAvgDuration: null },
previousPeriod: { latencyTimeseries: [], overallAvgDuration: null },
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/

import { composeStories } from '@storybook/testing-react';
import { render, waitFor } from '@testing-library/react';
import React from 'react';
import * as stories from './latency_chart.stories';

const { Example } = composeStories(stories);

describe('LatencyChart', () => {
it('renders', async () => {
await waitFor(() => {
expect(() => render(<Example />)).not.toThrowError();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ export const Example: Story<Args> = (args) => {
};
Example.args = {
agentName: 'java',
query: {
environment: 'ENVIRONMENT_ALL',
kuery: '',
rangeFrom: 'now-15m',
rangeTo: 'now',
},
serviceName: 'opbeans-java',
};
19 changes: 19 additions & 0 deletions x-pack/plugins/apm/public/components/shared/service_link.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/

import { composeStories } from '@storybook/testing-react';
import { render } from '@testing-library/react';
import React from 'react';
import * as stories from './service_link.stories';

const { Example } = composeStories(stories);

describe('ServiceLink', () => {
it('renders', () => {
expect(() => render(<Example />)).not.toThrowError();
});
});

0 comments on commit ad64f06

Please sign in to comment.