Skip to content

Commit

Permalink
lol idk
Browse files Browse the repository at this point in the history
  • Loading branch information
smith committed Oct 25, 2021
1 parent 695b287 commit 3719ade
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 176 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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 { Meta, Story } from '@storybook/react';
import React, { ComponentProps } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { MockApmPluginContextWrapper } from '../../../../context/apm_plugin/mock_apm_plugin_context';
import { MockUrlParamsContextProvider } from '../../../../context/url_params_context/mock_url_params_context_provider';

import { ErrorGroupList } from '.';

type Args = ComponentProps<typeof ErrorGroupList>;

const stories: Meta<Args> = {
title: 'app/ErrorGroupOverview/ErrorGroupList',
component: ErrorGroupList,
decorators: [
(StoryComponent) => {
return (
<MemoryRouter>
<MockApmPluginContextWrapper>
<MockUrlParamsContextProvider>
<StoryComponent />
</MockUrlParamsContextProvider>
</MockApmPluginContextWrapper>
</MemoryRouter>
);
},
],
};
export default stories;

export const Example: Story<Args> = (args) => {
return <ErrorGroupList {...args} />;
};
Example.args = {
items: [
{
message: 'net/http: abort Handler',
occurrenceCount: 14,
culprit: 'Main.func2',
groupId: '83a653297ec29afed264d7b60d5cda7b',
latestOccurrenceAt: '2021-10-21T16:18:41.434Z',
handled: false,
type: 'errorString',
},
{
message: 'POST /api/orders (500)',
occurrenceCount: 5,
culprit: 'logrusMiddleware',
groupId: '7a640436a9be648fd708703d1ac84650',
latestOccurrenceAt: '2021-10-21T16:18:40.162Z',
handled: false,
type: 'OpError',
},
{
message:
'write tcp 10.36.2.24:3000->10.36.1.14:34232: write: connection reset by peer',
occurrenceCount: 4,
culprit: 'apiHandlers.getProductCustomers',
groupId: '95ca0e312c109aa11e298bcf07f1445b',
latestOccurrenceAt: '2021-10-21T16:18:42.650Z',
handled: false,
type: 'OpError',
},
{
message:
'write tcp 10.36.0.21:3000->10.36.1.252:57070: write: connection reset by peer',
occurrenceCount: 3,
culprit: 'apiHandlers.getCustomers',
groupId: '4053d7e33d2b716c819bd96d9d6121a2',
latestOccurrenceAt: '2021-10-21T16:07:44.078Z',
handled: false,
type: 'OpError',
},
{
message:
'write tcp 10.36.0.21:3000->10.36.0.88:33926: write: broken pipe',
occurrenceCount: 2,
culprit: 'apiHandlers.getOrders',
groupId: '94f4ca8ec8c02e5318cf03f46ae4c1f3',
latestOccurrenceAt: '2021-10-21T16:13:45.742Z',
handled: false,
type: 'OpError',
},
],
serviceName: 'test service',
};

export const EmptyState: Story<Args> = (args) => {
return <ErrorGroupList {...args} />;
};
EmptyState.args = {
items: [],
serviceName: 'test service',
};
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 './error_group_list.stories';

const { Example } = composeStories(stories);

describe('ErrorGroupList', () => {
it('renders', () => {
expect(() => render(<Example />)).not.toThrowError();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useFetcher } from '../../../hooks/use_fetcher';
import { useTimeRange } from '../../../hooks/use_time_range';
import { FailedTransactionRateChart } from '../../shared/charts/failed_transaction_rate_chart';
import { ErrorDistribution } from '../error_group_details/Distribution';
import { ErrorGroupList } from './List';
import { ErrorGroupList } from './error_group_list';

export function ErrorGroupOverview() {
const { serviceName } = useApmServiceContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 { Meta, Story } from '@storybook/react';
import React, { ComponentProps } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { CoreStart } from '../../../../../../../../src/core/public';
import { createKibanaReactContext } from '../../../../../../../../src/plugins/kibana_react/public';
import { ServiceHealthStatus } from '../../../../../common/service_health_status';
import { MockApmPluginContextWrapper } from '../../../../context/apm_plugin/mock_apm_plugin_context';
import { items } from './__fixtures__/service_api_mock_data';
import { ServiceList } from './';

type Args = ComponentProps<typeof ServiceList>;

const KibanaReactContext = createKibanaReactContext({
notifications: { toasts: { add: () => {} } },
} as unknown as Partial<CoreStart>);

const stories: Meta<Args> = {
title: 'app/ServiceInventory/ServiceList',
component: ServiceList,
decorators: [
(StoryComponent) => {
return (
<KibanaReactContext.Provider>
<MemoryRouter
initialEntries={['/services?rangeFrom=now-15m&rangeTo=now']}
>
<MockApmPluginContextWrapper>
<StoryComponent />;
</MockApmPluginContextWrapper>
</MemoryRouter>
</KibanaReactContext.Provider>
);
},
],
};
export default stories;

export const Example: Story<Args> = (args) => {
return <ServiceList {...args} />;
};
Example.args = {
isLoading: false,
items,
};

export const EmptyState: Story<Args> = (args) => {
return <ServiceList {...args} />;
};
EmptyState.args = {
isLoading: false,
items: [],
};

export const WithHealthWarnings: Story<Args> = (args) => {
return <ServiceList {...args} />;
};
WithHealthWarnings.args = {
isLoading: false,
items: items.map((item) => ({
...item,
healthStatus: ServiceHealthStatus.warning,
})),
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,23 @@
* 2.0.
*/

import React, { ReactNode } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { Breakpoints } from '../../../../hooks/use_breakpoints';
import { ServiceHealthStatus } from '../../../../../common/service_health_status';
import { MockApmPluginContextWrapper } from '../../../../context/apm_plugin/mock_apm_plugin_context';
import { mockMoment, renderWithTheme } from '../../../../utils/testHelpers';
import { getServiceColumns, ServiceList } from './';
import { items } from './__fixtures__/service_api_mock_data';
import { composeStories } from '@storybook/testing-react';
import { act, render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import { ENVIRONMENT_ALL } from '../../../../../common/environment_filter_values';
import {
getCallApmApiSpy,
getCreateCallApmApiSpy,
} from '../../../../services/rest/callApmApiSpy';
import { Breakpoints } from '../../../../hooks/use_breakpoints';
import { getServiceColumns } from './';
import * as stories from './service_list.stories';

function Wrapper({ children }: { children?: ReactNode }) {
return (
<MemoryRouter initialEntries={['/services?rangeFrom=now-15m&rangeTo=now']}>
<MockApmPluginContextWrapper>{children}</MockApmPluginContextWrapper>
</MemoryRouter>
);
}
const { Example, EmptyState, WithHealthWarnings } = composeStories(stories);

describe('ServiceList', () => {
beforeAll(() => {
mockMoment();

const callApmApiSpy = getCallApmApiSpy().mockImplementation(
({ endpoint }) => {
if (endpoint === 'GET /internal/apm/fallback_to_transactions') {
return Promise.resolve({ fallbackToTransactions: false });
}
return Promise.reject(`Response for ${endpoint} is not defined`);
}
);

getCreateCallApmApiSpy().mockImplementation(() => callApmApiSpy as any);
});

it('renders empty state', () => {
expect(() =>
renderWithTheme(<ServiceList isLoading={false} items={[]} />, {
wrapper: Wrapper,
})
).not.toThrowError();
expect(() => render(<EmptyState />)).not.toThrowError();
});

it('renders with data', () => {
expect(() =>
renderWithTheme(<ServiceList isLoading={false} items={items} />, {
wrapper: Wrapper,
})
).not.toThrowError();
expect(() => render(<Example />)).not.toThrowError();
});

describe('responsive columns', () => {
Expand Down Expand Up @@ -213,43 +178,28 @@ describe('ServiceList', () => {

describe('without ML data', () => {
it('does not render the health column', () => {
const { queryByText } = renderWithTheme(
<ServiceList isLoading={false} items={items} />,
{
wrapper: Wrapper,
}
);
const { queryByText } = render(<Example />);
const healthHeading = queryByText('Health');

expect(healthHeading).toBeNull();
});

it('sorts by throughput', async () => {
const { findByTitle } = renderWithTheme(
<ServiceList isLoading={false} items={items} />,
{
wrapper: Wrapper,
}
);
it.skip('sorts by throughput', async () => {
const { findByTitle } = render(<Example />);

expect(await findByTitle('Throughput')).toBeInTheDocument();
await waitFor(async () => {
expect(await findByTitle('Throughput')).toBeInTheDocument();
});
});
});

describe('with ML data', () => {
it('renders the health column', async () => {
const { findByTitle } = renderWithTheme(
<ServiceList
isLoading={false}
items={items.map((item) => ({
...item,
healthStatus: ServiceHealthStatus.warning,
}))}
/>,
{ wrapper: Wrapper }
);
it.skip('renders the health column', () => {
render(<WithHealthWarnings />);

expect(await findByTitle('Health')).toBeInTheDocument();
expect(
screen.getByRole('button', { name: /Health/ })
).toBeInTheDocument();
});
});
});
Loading

0 comments on commit 3719ade

Please sign in to comment.