1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087 |
- 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 {useNavigate} from 'sentry/utils/useNavigate';
- 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');
- jest.mock('sentry/utils/useNavigate');
- describe('Visualize', () => {
- let organization!: ReturnType<typeof OrganizationFixture>;
- let mockNavigate!: jest.Mock;
- beforeEach(() => {
- organization = OrganizationFixture({
- features: ['dashboards-widget-builder-redesign', 'performance-view'],
- });
- jest.mocked(useCustomMeasurements).mockReturnValue({
- customMeasurements: {},
- });
- jest.mocked(useSpanTags).mockReturnValue({});
- mockNavigate = jest.fn();
- jest.mocked(useNavigate).mockReturnValue(mockNavigate);
- });
- 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();
- });
- it('removes the column selection when the aggregate has no parameters', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- yAxis: ['max(spans.db)'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.LINE,
- },
- }),
- }),
- }
- );
- expect(screen.getByRole('button', {name: 'Column Selection'})).toBeEnabled();
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'count'}));
- expect(
- screen.queryByRole('button', {name: 'Column Selection'})
- ).not.toBeInTheDocument();
- expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toBeEnabled();
- });
- it('adds the default value for the column selection when the aggregate has parameters', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- yAxis: ['count()'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.LINE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'p95'}));
- expect(screen.getByRole('button', {name: 'Column Selection'})).toBeEnabled();
- expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
- 'transaction.duration'
- );
- expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
- 'p95'
- );
- });
- it('maintains the selected aggregate when the column selection is changed and there are parameters', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- yAxis: ['max(spans.db)'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.LINE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'p95'}));
- expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
- 'spans.db'
- );
- expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
- 'p95'
- );
- });
- it('allows adding equations', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- yAxis: ['count()'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.LINE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Add Equation'}));
- expect(screen.getByLabelText('Equation')).toBeInTheDocument();
- await userEvent.click(screen.getByLabelText('Equation'));
- // Check the menu items
- const headers = screen.getAllByRole('banner');
- expect(headers[0]).toHaveTextContent('Fields');
- expect(headers[1]).toHaveTextContent('Operators');
- expect(screen.getByRole('listitem', {name: 'count()'})).toBeInTheDocument();
- // Make a selection and type in the equation
- await userEvent.click(screen.getByRole('listitem', {name: 'count()'}));
- await userEvent.type(screen.getByLabelText('Equation'), '* 2');
- expect(screen.getByLabelText('Equation')).toHaveValue('count() * 2');
- });
- it('renders a field without an aggregate in tables', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- field: ['transaction.duration'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.TABLE,
- },
- }),
- }),
- }
- );
- expect(
- await screen.findByRole('button', {name: 'Column Selection'})
- ).toHaveTextContent('transaction.duration');
- expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
- 'None'
- );
- });
- it('allows setting a field without an aggregate in tables', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- field: ['count()'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.TABLE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'None'}));
- await userEvent.click(screen.getByRole('button', {name: 'Column Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'transaction.duration'}));
- expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
- 'transaction.duration'
- );
- expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
- 'None'
- );
- });
- it('allows setting an equation in tables', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- field: ['count()'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.TABLE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Add Equation'}));
- await userEvent.click(screen.getByLabelText('Equation'));
- await userEvent.click(screen.getByRole('listitem', {name: 'count()'}));
- await userEvent.type(screen.getByLabelText('Equation'), '* 2');
- expect(screen.getByLabelText('Equation')).toHaveValue('count() * 2');
- });
- it('maintains the selected column when switching from field to aggregate', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- yAxis: ['transaction.duration'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.LINE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'p95'}));
- expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
- 'transaction.duration'
- );
- });
- it('maintains the selected column when switching from aggregate to aggregate', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- field: ['max(spans.db)'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.TABLE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'p95'}));
- expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
- 'spans.db'
- );
- });
- it('properly transitions between aggregates of higher to no parameter count', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- field: ['count_if(transaction.duration,equals,testValue)'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.TABLE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'count'}));
- expect(
- screen.queryByRole('button', {name: 'Column Selection'})
- ).not.toBeInTheDocument();
- expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
- 'count'
- );
- expect(mockNavigate).toHaveBeenCalledWith(
- expect.objectContaining({
- query: expect.objectContaining({
- field: ['count()'],
- }),
- }),
- {replace: true}
- );
- });
- it('properly transitions between aggregates of higher to lower parameter count', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- field: ['count_if(transaction.duration,equals,testValue)'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.TABLE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'count_miserable'}));
- expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
- 'user'
- );
- expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
- 'count_miserable'
- );
- expect(screen.getByDisplayValue('300')).toBeInTheDocument();
- expect(mockNavigate).toHaveBeenCalledWith(
- expect.objectContaining({
- query: expect.objectContaining({
- field: ['count_miserable(user,300)'],
- }),
- }),
- {replace: true}
- );
- });
- it('adds the default value for an aggregate with 2 parameters', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- field: ['transaction.duration'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.TABLE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'count_miserable'}));
- expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
- 'user'
- );
- });
- it('adds the default values for an aggregate with 3 parameters', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- field: ['transaction'],
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.TABLE,
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'count_if'}));
- expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
- 'transaction'
- );
- expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
- 'count_if'
- );
- expect(screen.getByText('is equal to')).toBeInTheDocument();
- expect(screen.getByDisplayValue('300')).toBeInTheDocument();
- });
- it('disables the aggregate selection when there is only one aggregate option', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.ISSUE,
- field: ['issue.id'],
- displayType: DisplayType.TABLE,
- },
- }),
- }),
- }
- );
- expect(
- await screen.findByRole('button', {name: 'Aggregate Selection'})
- ).toBeDisabled();
- });
- it('does not show the legend alias input for chart widgets', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.LINE,
- yAxis: ['p90(transaction.duration)'],
- },
- }),
- }),
- }
- );
- expect(
- await screen.findByRole('button', {name: 'Column Selection'})
- ).toHaveTextContent('transaction.duration');
- expect(
- await screen.findByRole('button', {name: 'Aggregate Selection'})
- ).toHaveTextContent('p90');
- expect(screen.queryByLabelText('Legend Alias')).not.toBeInTheDocument();
- });
- it('does not show the legend alias input for big number widgets', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.BIG_NUMBER,
- field: ['count()'],
- },
- }),
- }),
- }
- );
- expect(
- await screen.findByRole('button', {name: 'Aggregate Selection'})
- ).toHaveTextContent('count');
- expect(screen.queryByLabelText('Legend Alias')).not.toBeInTheDocument();
- });
- it('does not allow for selecting individual fields in big number widgets', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.BIG_NUMBER,
- field: ['count()'],
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- // Being unable to choose "None" in the aggregate selection means that the
- // individual field is not allowed, i.e. only aggregates appear.
- expect(screen.queryByRole('option', {name: 'None'})).not.toBeInTheDocument();
- });
- it('updates only the selected field', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.TABLE,
- field: ['count_unique(user)'],
- },
- }),
- }),
- }
- );
- expect(await screen.findByLabelText('Aggregate Selection')).toHaveTextContent(
- 'count_unique'
- );
- expect(screen.getByLabelText('Column Selection')).toHaveTextContent('user');
- // Add 3 fields
- await userEvent.click(screen.getByRole('button', {name: 'Add Field'}));
- await userEvent.click(screen.getByRole('button', {name: 'Add Field'}));
- await userEvent.click(screen.getByRole('button', {name: 'Add Field'}));
- // count() is the default aggregate when adding a field
- expect(screen.getAllByText('count')).toHaveLength(3);
- // Change the last field
- await userEvent.click(screen.getAllByText('count')[2]!);
- await userEvent.click(screen.getByRole('option', {name: 'epm'}));
- // The other fields should not be affected
- expect(screen.getByText('count_unique')).toBeInTheDocument();
- expect(screen.getAllByText('count')).toHaveLength(2);
- expect(screen.getAllByText('epm')).toHaveLength(1);
- });
- it('shows appropriate error messages for non-chart widget queries', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize
- error={{
- queries: [
- {
- fields: ['this field has an error'],
- aggregates: ['this aggregate has an error'],
- },
- ],
- }}
- />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.BIG_NUMBER,
- },
- }),
- }),
- }
- );
- expect(await screen.findByText('this field has an error')).toBeInTheDocument();
- expect(screen.queryByText('this aggregate has an error')).not.toBeInTheDocument();
- });
- it('shows appropriate error messages for chart type widget queries', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize
- error={{
- queries: [
- {
- fields: ['this field has an error'],
- aggregates: ['this aggregate has an error'],
- },
- ],
- }}
- />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.LINE,
- },
- }),
- }),
- }
- );
- expect(await screen.findByText('this aggregate has an error')).toBeInTheDocument();
- expect(screen.queryByText('this field has an error')).not.toBeInTheDocument();
- });
- it('shows radio buttons for big number widgets when there are multiple aggregates', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.BIG_NUMBER,
- field: ['count_unique(user)'],
- },
- }),
- }),
- }
- );
- expect(await screen.findByLabelText('Aggregate Selection')).toHaveTextContent(
- 'count_unique'
- );
- await userEvent.click(screen.getByRole('button', {name: 'Add Field'}));
- // There are two radio buttons, one for each aggregate, and the last one is selected
- expect(screen.getAllByLabelText('aggregate-selector')).toHaveLength(2);
- expect(screen.getByRole('radio', {name: 'field1'})).toBeChecked();
- });
- it('shifts the selected aggregate up when it is the last one and removed', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- displayType: DisplayType.BIG_NUMBER,
- field: ['count_unique(1)', 'count_unique(2)', 'count_unique(3)'],
- selectedAggregate: '2',
- },
- }),
- }),
- }
- );
- expect(await screen.findByRole('radio', {name: 'field2'})).toBeChecked();
- await userEvent.click(screen.getAllByRole('button', {name: 'Remove field'})[2]!);
- // The second field is now selected, but the URL param for selectedAggregate
- // is cleared, so the last field is selected
- expect(await screen.findByRole('radio', {name: 'field1'})).toBeChecked();
- expect(mockNavigate).toHaveBeenCalledWith(
- expect.objectContaining({
- query: expect.objectContaining({
- selectedAggregate: undefined,
- }),
- }),
- {replace: true}
- );
- });
- it('only shows the relevant options for the release dataset', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.RELEASE,
- field: ['crash_free_rate(session)'],
- },
- }),
- }),
- }
- );
- expect(
- await screen.findByRole('button', {name: 'Column Selection'})
- ).toHaveTextContent('session');
- await userEvent.click(screen.getByRole('button', {name: 'Column Selection'}));
- const listbox = await screen.findAllByRole('option');
- expect(listbox).toHaveLength(2);
- expect(listbox[0]).toHaveTextContent('session');
- expect(listbox[1]).toHaveTextContent('user');
- });
- it('clears out the field when the selected aggregate has no parameters', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- field: ['transaction.duration'],
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'count'}));
- expect(
- screen.queryByRole('button', {name: 'Column Selection'})
- ).not.toBeInTheDocument();
- });
- it('uses the provided value for a value parameter field', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- field: ['count_if(transaction.duration,equals,300)'],
- },
- }),
- }),
- }
- );
- // Simulate clearing and typing a new value from the user
- await userEvent.type(
- screen.getByDisplayValue('300'),
- '{backspace}{backspace}{backspace}400'
- );
- // Unfocus the field
- await userEvent.tab();
- expect(await screen.findByDisplayValue('400')).toBeInTheDocument();
- });
- it('restricts deleting the last aggregate in release health widgets', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.RELEASE,
- field: ['crash_free_rate(session)', 'environment'],
- },
- }),
- }),
- }
- );
- const removeButtons = await screen.findAllByRole('button', {name: 'Remove field'});
- expect(removeButtons).toHaveLength(2);
- expect(removeButtons[0]).toBeDisabled();
- expect(removeButtons[1]).toBeEnabled();
- });
- it('shows a text box and removes the column selection for apdex', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- field: ['apdex(3000)'],
- },
- }),
- }),
- }
- );
- expect(
- await screen.findByRole('button', {name: 'Aggregate Selection'})
- ).toHaveTextContent('apdex');
- expect(screen.getByRole('textbox', {name: 'Numeric Input'})).toHaveValue('3000');
- expect(
- screen.queryByRole('button', {name: 'Column Selection'})
- ).not.toBeInTheDocument();
- });
- it('resets the text box value when swapping between apdex and user_misery', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.TRANSACTIONS,
- field: ['apdex(9999)'],
- },
- }),
- }),
- }
- );
- await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
- await userEvent.click(screen.getByRole('option', {name: 'user_misery'}));
- expect(screen.getByRole('textbox', {name: 'Numeric Input'})).toHaveValue('300');
- });
- describe('spans', () => {
- beforeEach(() => {
- jest.mocked(useSpanTags).mockImplementation((type?: 'string' | 'number') => {
- if (type === 'number') {
- return {
- 'span.duration': {
- 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();
- });
- it('shows the correct column options for the aggregate field type', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.SPANS,
- displayType: DisplayType.TABLE,
- field: ['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('span.duration')).toBeInTheDocument();
- expect(within(listbox).getByText('anotherNumericTag')).toBeInTheDocument();
- });
- it('shows the correct column options for the non-aggregate field type', async () => {
- render(
- <WidgetBuilderProvider>
- <Visualize />
- </WidgetBuilderProvider>,
- {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- query: {
- dataset: WidgetType.SPANS,
- displayType: DisplayType.TABLE,
- field: ['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('span.duration')).toBeInTheDocument();
- expect(within(listbox).getByText('span.description')).toBeInTheDocument();
- });
- });
- });
|