12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022 |
- 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/dashboards/types';
- import {DashboardsMEPContext} from 'sentry/views/dashboards/widgetCard/dashboardsMEPContext';
- import WidgetQueries, {
- flattenMultiSeriesDataWithGrouping,
- } from 'sentry/views/dashboards/widgetCard/widgetQueries';
- describe('Dashboards > WidgetQueries', function () {
- const initialData = initializeOrg();
- const renderWithProviders = component =>
- render(
- <MEPSettingProvider forceTransactions={false}>{component}</MEPSettingProvider>
- );
- 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/events/',
- 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/events/',
- 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/events/',
- 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/events/',
- 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/events/',
- body: {
- meta: {'sdk.name': 'string'},
- data: [{'sdk.name': 'python'}],
- },
- match: [MockApiClient.matchQuery({query: 'event.type:error'})],
- });
- const secondQuery = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- 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/events/',
- 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/events/',
- 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/events/',
- body: {detail: 'it didnt work'},
- match: [MockApiClient.matchQuery({query: 'event.type:error'})],
- });
- const secondQuery = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- 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(
- <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>
- );
- // 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/events/',
- 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/events/',
- 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]',
- }),
- })
- );
- });
- });
|