1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030 |
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
- import {Client} from 'sentry/api';
- import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
- import {DashboardFilterKeys} from 'sentry/views/dashboardsV2/types';
- import {DashboardsMEPContext} from 'sentry/views/dashboardsV2/widgetCard/dashboardsMEPContext';
- import WidgetQueries, {
- flattenMultiSeriesDataWithGrouping,
- } from 'sentry/views/dashboardsV2/widgetCard/widgetQueries';
- import {OrganizationContext} from 'sentry/views/organizationContext';
- describe('Dashboards > WidgetQueries', function () {
- const initialData = initializeOrg({
- organization: TestStubs.Organization(),
- });
- const renderWithProviders = (component, context) =>
- render(
- <OrganizationContext.Provider value={initialData.organization}>
- <MEPSettingProvider forceTransactions={false}>{component}</MEPSettingProvider>
- </OrganizationContext.Provider>,
- context
- );
- const multipleQueryWidget = {
- title: 'Errors',
- interval: '5m',
- displayType: 'line',
- queries: [
- {
- conditions: 'event.type:error',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: [],
- name: 'errors',
- orderby: '',
- },
- {
- conditions: 'event.type:default',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: [],
- name: 'default',
- orderby: '',
- },
- ],
- };
- const singleQueryWidget = {
- title: 'Errors',
- interval: '5m',
- displayType: 'line',
- queries: [
- {
- conditions: 'event.type:error',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: [],
- name: 'errors',
- orderby: '',
- },
- ],
- };
- const tableWidget = {
- title: 'SDK',
- interval: '5m',
- displayType: 'table',
- queries: [
- {
- conditions: 'event.type:error',
- fields: ['sdk.name'],
- aggregates: [],
- columns: ['sdk.name'],
- name: 'sdk',
- orderby: '',
- },
- ],
- };
- const selection = {
- projects: [1],
- environments: ['prod'],
- datetime: {
- period: '14d',
- orderby: '',
- },
- };
- const api = new Client();
- afterEach(function () {
- MockApiClient.clearMockResponses();
- });
- it('can send multiple API requests', async function () {
- const errorMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: [],
- match: [MockApiClient.matchQuery({query: 'event.type:error'})],
- });
- const defaultMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: [],
- match: [MockApiClient.matchQuery({query: 'event.type:default'})],
- });
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={multipleQueryWidget}
- organization={initialData.organization}
- selection={selection}
- >
- {() => <div data-test-id="child" />}
- </WidgetQueries>
- );
- // Child should be rendered and 2 requests should be sent.
- await screen.findByTestId('child');
- expect(errorMock).toHaveBeenCalledTimes(1);
- expect(defaultMock).toHaveBeenCalledTimes(1);
- });
- it('appends dashboard filters to events series request', async function () {
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: [],
- });
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={singleQueryWidget}
- organization={initialData.organization}
- selection={selection}
- dashboardFilters={{[DashboardFilterKeys.RELEASE]: ['abc@1.2.0', 'abc@1.3.0']}}
- >
- {() => <div data-test-id="child" />}
- </WidgetQueries>
- );
- await screen.findByTestId('child');
- expect(mock).toHaveBeenCalledWith(
- '/organizations/org-slug/events-stats/',
- expect.objectContaining({
- query: expect.objectContaining({
- query: 'event.type:error release:[abc@1.2.0,abc@1.3.0] ',
- }),
- })
- );
- });
- it('appends dashboard filters to events table request', async function () {
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: [],
- });
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={tableWidget}
- organization={initialData.organization}
- selection={selection}
- dashboardFilters={{[DashboardFilterKeys.RELEASE]: ['abc@1.3.0']}}
- >
- {() => <div data-test-id="child" />}
- </WidgetQueries>
- );
- await screen.findByTestId('child');
- expect(mock).toHaveBeenCalledWith(
- '/organizations/org-slug/eventsv2/',
- expect.objectContaining({
- query: expect.objectContaining({
- query: 'event.type:error release:abc@1.3.0 ',
- }),
- })
- );
- });
- it('sets errorMessage when the first request fails', async function () {
- const okMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- match: [MockApiClient.matchQuery({query: 'event.type:error'})],
- body: [],
- });
- const failMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- statusCode: 400,
- body: {detail: 'Bad request data'},
- match: [MockApiClient.matchQuery({query: 'event.type:default'})],
- });
- let error = '';
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={multipleQueryWidget}
- organization={initialData.organization}
- selection={selection}
- >
- {({errorMessage}) => {
- error = errorMessage;
- return <div data-test-id="child" />;
- }}
- </WidgetQueries>
- );
- // Child should be rendered and 2 requests should be sent.
- await screen.findByTestId('child');
- expect(okMock).toHaveBeenCalledTimes(1);
- expect(failMock).toHaveBeenCalledTimes(1);
- expect(error).toEqual('Bad request data');
- });
- it('adjusts interval based on date window', async function () {
- const errorMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: [],
- });
- const widget = {...singleQueryWidget, interval: '1m'};
- const longSelection = {
- projects: [1],
- environments: ['prod', 'dev'],
- datetime: {
- period: '90d',
- },
- };
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={widget}
- organization={initialData.organization}
- selection={longSelection}
- >
- {() => <div data-test-id="child" />}
- </WidgetQueries>
- );
- // Child should be rendered and interval bumped up.
- await screen.findByTestId('child');
- expect(errorMock).toHaveBeenCalledTimes(1);
- expect(errorMock).toHaveBeenCalledWith(
- '/organizations/org-slug/events-stats/',
- expect.objectContaining({
- query: expect.objectContaining({
- interval: '4h',
- statsPeriod: '90d',
- environment: ['prod', 'dev'],
- project: [1],
- }),
- })
- );
- });
- it('adjusts interval based on date window 14d', async function () {
- const errorMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: [],
- });
- const widget = {...singleQueryWidget, interval: '1m'};
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={widget}
- organization={initialData.organization}
- selection={selection}
- >
- {() => <div data-test-id="child" />}
- </WidgetQueries>
- );
- // Child should be rendered and interval bumped up.
- await screen.findByTestId('child');
- expect(errorMock).toHaveBeenCalledTimes(1);
- expect(errorMock).toHaveBeenCalledWith(
- '/organizations/org-slug/events-stats/',
- expect.objectContaining({
- query: expect.objectContaining({interval: '30m'}),
- })
- );
- });
- it('can send table result queries', async function () {
- const tableMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- meta: {'sdk.name': 'string'},
- data: [{'sdk.name': 'python'}],
- },
- });
- let childProps = undefined;
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={tableWidget}
- organization={initialData.organization}
- selection={selection}
- >
- {props => {
- childProps = props;
- return <div data-test-id="child" />;
- }}
- </WidgetQueries>
- );
- // Child should be rendered and 1 requests should be sent.
- await screen.findByTestId('child');
- expect(tableMock).toHaveBeenCalledTimes(1);
- expect(tableMock).toHaveBeenCalledWith(
- '/organizations/org-slug/eventsv2/',
- expect.objectContaining({
- query: expect.objectContaining({
- query: 'event.type:error',
- field: ['sdk.name'],
- statsPeriod: '14d',
- environment: ['prod'],
- project: [1],
- }),
- })
- );
- expect(childProps.timeseriesResults).toBeUndefined();
- expect(childProps.tableResults[0].data).toHaveLength(1);
- expect(childProps.tableResults[0].meta).toBeDefined();
- });
- it('can send multiple table queries', async function () {
- const firstQuery = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- meta: {'sdk.name': 'string'},
- data: [{'sdk.name': 'python'}],
- },
- match: [MockApiClient.matchQuery({query: 'event.type:error'})],
- });
- const secondQuery = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- meta: {title: 'string'},
- data: [{title: 'ValueError'}],
- },
- match: [MockApiClient.matchQuery({query: 'title:ValueError'})],
- });
- const widget = {
- title: 'SDK',
- interval: '5m',
- displayType: 'table',
- queries: [
- {
- conditions: 'event.type:error',
- fields: ['sdk.name'],
- aggregates: [],
- columns: ['sdk.name'],
- name: 'sdk',
- orderby: '',
- },
- {
- conditions: 'title:ValueError',
- fields: ['title'],
- aggregates: [],
- columns: ['sdk.name'],
- name: 'title',
- orderby: '',
- },
- ],
- };
- let childProps = undefined;
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={widget}
- organization={initialData.organization}
- selection={selection}
- >
- {props => {
- childProps = props;
- return <div data-test-id="child" />;
- }}
- </WidgetQueries>
- );
- // Child should be rendered and 2 requests should be sent.
- await screen.findByTestId('child');
- expect(firstQuery).toHaveBeenCalledTimes(1);
- expect(secondQuery).toHaveBeenCalledTimes(1);
- expect(childProps.tableResults).toHaveLength(2);
- expect(childProps.tableResults[0].data[0]['sdk.name']).toBeDefined();
- expect(childProps.tableResults[1].data[0].title).toBeDefined();
- });
- it('can send big number result queries', async function () {
- const tableMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- meta: {'sdk.name': 'string'},
- data: [{'sdk.name': 'python'}],
- },
- });
- let childProps = undefined;
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={{
- title: 'SDK',
- interval: '5m',
- displayType: 'big_number',
- queries: [
- {
- conditions: 'event.type:error',
- fields: ['sdk.name'],
- aggregates: [],
- columns: ['sdk.name'],
- name: 'sdk',
- orderby: '',
- },
- ],
- }}
- organization={initialData.organization}
- selection={selection}
- >
- {props => {
- childProps = props;
- return <div data-test-id="child" />;
- }}
- </WidgetQueries>
- );
- // Child should be rendered and 1 requests should be sent.
- await screen.findByTestId('child');
- expect(tableMock).toHaveBeenCalledTimes(1);
- expect(tableMock).toHaveBeenCalledWith(
- '/organizations/org-slug/eventsv2/',
- expect.objectContaining({
- query: expect.objectContaining({
- referrer: 'api.dashboards.bignumberwidget',
- query: 'event.type:error',
- field: ['sdk.name'],
- statsPeriod: '14d',
- environment: ['prod'],
- project: [1],
- }),
- })
- );
- expect(childProps.timeseriesResults).toBeUndefined();
- expect(childProps.tableResults[0].data).toHaveLength(1);
- expect(childProps.tableResults[0].meta).toBeDefined();
- });
- it('can send world map result queries', async function () {
- const tableMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-geo/',
- body: {
- meta: {'sdk.name': 'string'},
- data: [{'sdk.name': 'python'}],
- },
- });
- let childProps = undefined;
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={{
- title: 'SDK',
- interval: '5m',
- displayType: 'world_map',
- queries: [
- {
- conditions: 'event.type:error',
- fields: ['count()'],
- aggregates: [],
- columns: ['count()'],
- name: 'sdk',
- orderby: '',
- },
- ],
- }}
- organization={initialData.organization}
- selection={selection}
- >
- {props => {
- childProps = props;
- return <div data-test-id="child" />;
- }}
- </WidgetQueries>
- );
- // Child should be rendered and 1 requests should be sent.
- await screen.findByTestId('child');
- expect(tableMock).toHaveBeenCalledTimes(1);
- expect(tableMock).toHaveBeenCalledWith(
- '/organizations/org-slug/events-geo/',
- expect.objectContaining({
- query: expect.objectContaining({
- referrer: 'api.dashboards.worldmapwidget',
- query: 'event.type:error',
- field: ['count()'],
- statsPeriod: '14d',
- environment: ['prod'],
- project: [1],
- }),
- })
- );
- expect(childProps.timeseriesResults).toBeUndefined();
- expect(childProps.tableResults[0].data).toHaveLength(1);
- expect(childProps.tableResults[0].meta).toBeDefined();
- });
- it('stops loading state once all queries finish even if some fail', async function () {
- const firstQuery = MockApiClient.addMockResponse({
- statusCode: 500,
- url: '/organizations/org-slug/eventsv2/',
- body: {detail: 'it didnt work'},
- match: [MockApiClient.matchQuery({query: 'event.type:error'})],
- });
- const secondQuery = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- meta: {title: 'string'},
- data: [{title: 'ValueError'}],
- },
- match: [MockApiClient.matchQuery({query: 'title:ValueError'})],
- });
- const widget = {
- title: 'SDK',
- interval: '5m',
- displayType: 'table',
- queries: [
- {
- conditions: 'event.type:error',
- fields: ['sdk.name'],
- aggregates: [],
- columns: ['sdk.name'],
- name: 'sdk',
- orderby: '',
- },
- {
- conditions: 'title:ValueError',
- fields: ['sdk.name'],
- aggregates: [],
- columns: ['sdk.name'],
- name: 'title',
- orderby: '',
- },
- ],
- };
- let childProps = undefined;
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={widget}
- organization={initialData.organization}
- selection={selection}
- >
- {props => {
- childProps = props;
- return <div data-test-id="child" />;
- }}
- </WidgetQueries>
- );
- // Child should be rendered and 2 requests should be sent.
- await screen.findByTestId('child');
- expect(firstQuery).toHaveBeenCalledTimes(1);
- expect(secondQuery).toHaveBeenCalledTimes(1);
- expect(childProps.loading).toEqual(false);
- });
- it('sets bar charts to 1d interval', async function () {
- const errorMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: [],
- match: [MockApiClient.matchQuery({interval: '1d'})],
- });
- const barWidget = {
- ...singleQueryWidget,
- displayType: 'bar',
- // Should be ignored for bars.
- interval: '5m',
- };
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={barWidget}
- organization={initialData.organization}
- selection={selection}
- >
- {() => <div data-test-id="child" />}
- </WidgetQueries>
- );
- // Child should be rendered and 1 requests should be sent.
- await screen.findByTestId('child');
- expect(errorMock).toHaveBeenCalledTimes(1);
- });
- it('returns timeseriesResults in the same order as widgetQuery', async function () {
- MockApiClient.clearMockResponses();
- const defaultMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- method: 'GET',
- body: {
- data: [
- [
- 1000,
- [
- {
- count: 100,
- },
- ],
- ],
- ],
- start: 1000,
- end: 2000,
- },
- match: [MockApiClient.matchQuery({query: 'event.type:default'})],
- });
- const errorMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- method: 'GET',
- body: {
- data: [
- [
- 1000,
- [
- {
- count: 200,
- },
- ],
- ],
- ],
- start: 1000,
- end: 2000,
- },
- match: [MockApiClient.matchQuery({query: 'event.type:error'})],
- });
- const barWidget = {
- ...multipleQueryWidget,
- displayType: 'bar',
- // Should be ignored for bars.
- interval: '5m',
- };
- const child = jest.fn(() => <div data-test-id="child" />);
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={barWidget}
- organization={initialData.organization}
- selection={selection}
- >
- {child}
- </WidgetQueries>
- );
- await screen.findByTestId('child');
- expect(defaultMock).toHaveBeenCalledTimes(1);
- expect(errorMock).toHaveBeenCalledTimes(1);
- expect(child).toHaveBeenLastCalledWith(
- expect.objectContaining({
- timeseriesResults: [
- {data: [{name: 1000000, value: 200}], seriesName: 'errors : count()'},
- {data: [{name: 1000000, value: 100}], seriesName: 'default : count()'},
- ],
- })
- );
- });
- it('calls events-stats with 4h interval when interval buckets would exceed 66', async function () {
- const eventsStatsMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: [],
- });
- const areaWidget = {
- ...singleQueryWidget,
- displayType: 'area',
- interval: '5m',
- };
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={areaWidget}
- organization={initialData.organization}
- selection={{
- ...selection,
- datetime: {
- period: '90d',
- },
- }}
- >
- {() => <div data-test-id="child" />}
- </WidgetQueries>
- );
- // Child should be rendered and 1 requests should be sent.
- await screen.findByTestId('child');
- expect(eventsStatsMock).toHaveBeenCalledTimes(1);
- expect(eventsStatsMock).toHaveBeenCalledWith(
- '/organizations/org-slug/events-stats/',
- expect.objectContaining({query: expect.objectContaining({interval: '4h'})})
- );
- });
- it('does not re-query events and sets name in widgets', async function () {
- const eventsStatsMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: TestStubs.EventsStats(),
- });
- const lineWidget = {
- ...singleQueryWidget,
- displayType: 'line',
- interval: '5m',
- };
- let childProps;
- const {rerender} = renderWithProviders(
- <WidgetQueries
- api={api}
- widget={lineWidget}
- organization={initialData.organization}
- selection={selection}
- >
- {props => {
- childProps = props;
- return <div data-test-id="child" />;
- }}
- </WidgetQueries>
- );
- expect(eventsStatsMock).toHaveBeenCalledTimes(1);
- await waitFor(() => expect(childProps.loading).toEqual(false));
- // Simulate a re-render with a new query alias
- rerender(
- <OrganizationContext.Provider value={initialData.organization}>
- <MEPSettingProvider forceTransactions={false}>
- <WidgetQueries
- api={api}
- widget={{
- ...lineWidget,
- queries: [
- {
- conditions: 'event.type:error',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: [],
- name: 'this query alias changed',
- orderby: '',
- },
- ],
- }}
- organization={initialData.organization}
- selection={selection}
- >
- {props => {
- childProps = props;
- return <div data-test-id="child" />;
- }}
- </WidgetQueries>
- </MEPSettingProvider>
- </OrganizationContext.Provider>
- );
- // Did not re-query
- expect(eventsStatsMock).toHaveBeenCalledTimes(1);
- expect(childProps.timeseriesResults[0].seriesName).toEqual(
- 'this query alias changed : count()'
- );
- });
- describe('multi-series grouped data', () => {
- const [START, END] = [1647399900, 1647399901];
- let mockCountData, mockCountUniqueData, mockRawResultData;
- beforeEach(() => {
- mockCountData = {
- start: START,
- end: END,
- data: [
- [START, [{'count()': 0}]],
- [END, [{'count()': 0}]],
- ],
- };
- mockCountUniqueData = {
- start: START,
- end: END,
- data: [
- [START, [{'count_unique()': 0}]],
- [END, [{'count_unique()': 0}]],
- ],
- };
- mockRawResultData = {
- local: {
- 'count()': mockCountData,
- 'count_unique()': mockCountUniqueData,
- order: 0,
- },
- prod: {
- 'count()': mockCountData,
- 'count_unique()': mockCountUniqueData,
- order: 1,
- },
- };
- });
- it('combines group name and aggregate names in grouped multi series data', () => {
- const actual = flattenMultiSeriesDataWithGrouping(mockRawResultData, '');
- expect(actual).toEqual([
- [
- 0,
- expect.objectContaining({
- seriesName: 'local : count()',
- data: expect.anything(),
- }),
- ],
- [
- 0,
- expect.objectContaining({
- seriesName: 'local : count_unique()',
- data: expect.anything(),
- }),
- ],
- [
- 1,
- expect.objectContaining({
- seriesName: 'prod : count()',
- data: expect.anything(),
- }),
- ],
- [
- 1,
- expect.objectContaining({
- seriesName: 'prod : count_unique()',
- data: expect.anything(),
- }),
- ],
- ]);
- });
- it('prefixes with a query alias when provided', () => {
- const actual = flattenMultiSeriesDataWithGrouping(mockRawResultData, 'Query 1');
- expect(actual).toEqual([
- [
- 0,
- expect.objectContaining({
- seriesName: 'Query 1 > local : count()',
- data: expect.anything(),
- }),
- ],
- [
- 0,
- expect.objectContaining({
- seriesName: 'Query 1 > local : count_unique()',
- data: expect.anything(),
- }),
- ],
- [
- 1,
- expect.objectContaining({
- seriesName: 'Query 1 > prod : count()',
- data: expect.anything(),
- }),
- ],
- [
- 1,
- expect.objectContaining({
- seriesName: 'Query 1 > prod : count_unique()',
- data: expect.anything(),
- }),
- ],
- ]);
- });
- });
- it('charts send metricsEnhanced requests', async function () {
- const {organization} = initialData;
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: {
- data: [
- [
- 1000,
- [
- {
- count: 100,
- },
- ],
- ],
- ],
- isMetricsData: false,
- start: 1000,
- end: 2000,
- },
- });
- const setIsMetricsMock = jest.fn();
- const children = jest.fn(() => <div />);
- renderWithProviders(
- <DashboardsMEPContext.Provider
- value={{
- isMetricsData: undefined,
- setIsMetricsData: setIsMetricsMock,
- }}
- >
- <WidgetQueries
- api={api}
- widget={singleQueryWidget}
- organization={{
- ...organization,
- features: [...organization.features, 'dashboards-mep'],
- }}
- selection={selection}
- >
- {children}
- </WidgetQueries>
- </DashboardsMEPContext.Provider>
- );
- expect(mock).toHaveBeenCalledWith(
- '/organizations/org-slug/events-stats/',
- expect.objectContaining({
- query: expect.objectContaining({dataset: 'metricsEnhanced'}),
- })
- );
- await waitFor(() => {
- expect(setIsMetricsMock).toHaveBeenCalledWith(false);
- });
- });
- it('tables send metricsEnhanced requests', async function () {
- const {organization} = initialData;
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- meta: {title: 'string', isMetricsData: true},
- data: [{title: 'ValueError'}],
- },
- });
- const setIsMetricsMock = jest.fn();
- const children = jest.fn(() => <div />);
- renderWithProviders(
- <DashboardsMEPContext.Provider
- value={{
- isMetricsData: undefined,
- setIsMetricsData: setIsMetricsMock,
- }}
- >
- <WidgetQueries
- api={api}
- widget={{...singleQueryWidget, displayType: 'table'}}
- organization={{
- ...organization,
- features: [...organization.features, 'dashboards-mep'],
- }}
- selection={selection}
- >
- {children}
- </WidgetQueries>
- </DashboardsMEPContext.Provider>
- );
- expect(mock).toHaveBeenCalledWith(
- '/organizations/org-slug/eventsv2/',
- expect.objectContaining({
- query: expect.objectContaining({dataset: 'metricsEnhanced'}),
- })
- );
- await waitFor(() => {
- expect(setIsMetricsMock).toHaveBeenCalledWith(true);
- });
- });
- it('does not inject equation aliases for top N requests', async function () {
- const testData = initializeOrg({
- organization: {
- ...TestStubs.Organization(),
- },
- });
- const eventsStatsMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: [],
- });
- const areaWidget = {
- displayType: 'area',
- interval: '5m',
- queries: [
- {
- conditions: 'event.type:error',
- fields: [],
- aggregates: ['count()', 'equation|count() * 2'],
- columns: ['project'],
- orderby: 'equation[0]',
- name: '',
- },
- ],
- };
- renderWithProviders(
- <WidgetQueries
- api={api}
- widget={areaWidget}
- organization={testData.organization}
- selection={selection}
- >
- {() => <div data-test-id="child" />}
- </WidgetQueries>
- );
- // Child should be rendered and 1 requests should be sent.
- await screen.findByTestId('child');
- expect(eventsStatsMock).toHaveBeenCalledTimes(1);
- expect(eventsStatsMock).toHaveBeenCalledWith(
- '/organizations/org-slug/events-stats/',
- expect.objectContaining({
- query: expect.objectContaining({
- field: ['project', 'count()', 'equation|count() * 2'],
- orderby: 'equation[0]',
- }),
- })
- );
- });
- });
|