123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- import {LocationFixture} from 'sentry-fixture/locationFixture';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {RouterFixture} from 'sentry-fixture/routerFixture';
- import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
- import type {TagCollection} from 'sentry/types/group';
- import useCustomMeasurements from 'sentry/utils/useCustomMeasurements';
- import {DisplayType, WidgetType} from 'sentry/views/dashboards/types';
- import Visualize from 'sentry/views/dashboards/widgetBuilder/components/visualize';
- import {WidgetBuilderProvider} from 'sentry/views/dashboards/widgetBuilder/contexts/widgetBuilderContext';
- import {useSpanTags} from 'sentry/views/explore/contexts/spanTagsContext';
- jest.mock('sentry/utils/useCustomMeasurements');
- jest.mock('sentry/views/explore/contexts/spanTagsContext');
- describe('Visualize', () => {
- let organization;
- beforeEach(() => {
- organization = OrganizationFixture({
- features: ['dashboards-widget-builder-redesign', 'performance-view'],
- });
- jest.mocked(useCustomMeasurements).mockReturnValue({
- customMeasurements: {},
- });
- jest.mocked(useSpanTags).mockReturnValue({});
- });
- it('renders basic aggregates correctly from the URL params', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- yAxis: ['p90(transaction.duration)', 'max(spans.db)'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.LINE,
- },
- }),
- }),
- }
- );
- expect(await screen.findByText('+ Add Series')).toBeInTheDocument();
- const p90FieldRow = (await screen.findByText('p90')).closest(
- '[data-testid="field-bar"]'
- ) as HTMLElement;
- expect(p90FieldRow).toBeInTheDocument();
- expect(within(p90FieldRow).getByText('transaction.duration')).toBeInTheDocument();
- const maxFieldRow = (await screen.findByText('max')).closest(
- '[data-testid="field-bar"]'
- ) as HTMLElement;
- expect(maxFieldRow).toBeInTheDocument();
- expect(within(maxFieldRow).getByText('spans.db')).toBeInTheDocument();
- });
- it('allows adding and deleting series', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- yAxis: ['max(spans.db)'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.LINE,
- },
- }),
- }),
- }
- );
- expect(await screen.findByRole('button', {name: 'Remove field'})).toBeDisabled();
- await userEvent.click(screen.getByRole('button', {name: 'Add Series'}));
- expect(screen.queryAllByRole('button', {name: 'Remove field'})[0]).toBeEnabled();
- await userEvent.click(screen.queryAllByRole('button', {name: 'Remove field'})[0]);
- expect(screen.queryAllByRole('button', {name: 'Remove field'})[0]).toBeDisabled();
- });
- describe('spans', () => {
- beforeEach(() => {
- jest.mocked(useSpanTags).mockImplementation((type?: 'string' | 'number') => {
- if (type === 'number') {
- return {
- 'tags[span.duration,number]': {
- key: 'span.duration',
- name: 'span.duration',
- kind: 'measurement',
- },
- 'tags[anotherNumericTag,number]': {
- key: 'anotherNumericTag',
- name: 'anotherNumericTag',
- kind: 'measurement',
- },
- } as TagCollection;
- }
- return {
- 'span.description': {
- key: 'span.description',
- name: 'span.description',
- kind: 'tag',
- },
- } as TagCollection;
- });
- });
- it('shows numeric tags as primary options for chart widgets', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.SPANS,
- displayType: DisplayType.LINE,
- yAxis: ['p90(span.duration)'],
- },
- }),
- }),
- }
- );
- await userEvent.click(
- await screen.findByRole('button', {name: 'Column Selection'})
- );
- const listbox = await screen.findByRole('listbox', {name: 'Column Selection'});
- expect(within(listbox).getByText('anotherNumericTag')).toBeInTheDocument();
- expect(within(listbox).queryByText('span.description')).not.toBeInTheDocument();
- });
- it('shows the correct aggregate options', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.SPANS,
- displayType: DisplayType.LINE,
- yAxis: ['count(span.duration)'],
- },
- }),
- }),
- }
- );
- await userEvent.click(
- await screen.findByRole('button', {name: 'Aggregate Selection'})
- );
- // count has two entries because it's already selected
- // and in the dropdown
- expect(screen.getAllByText('count')).toHaveLength(2);
- expect(screen.getByText('avg')).toBeInTheDocument();
- expect(screen.getByText('max')).toBeInTheDocument();
- expect(screen.getByText('min')).toBeInTheDocument();
- expect(screen.getByText('p50')).toBeInTheDocument();
- expect(screen.getByText('p75')).toBeInTheDocument();
- expect(screen.getByText('p90')).toBeInTheDocument();
- expect(screen.getByText('p95')).toBeInTheDocument();
- expect(screen.getByText('p99')).toBeInTheDocument();
- expect(screen.getByText('p100')).toBeInTheDocument();
- expect(screen.getByText('sum')).toBeInTheDocument();
- });
- });
- });
|