123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824 |
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
- import {Client} from 'sentry/api';
- import {
- DashboardFilterKeys,
- DisplayType,
- WidgetType,
- } from 'sentry/views/dashboardsV2/types';
- import ReleaseWidgetQueries from 'sentry/views/dashboardsV2/widgetCard/releaseWidgetQueries';
- describe('Dashboards > ReleaseWidgetQueries', function () {
- const {organization} = initializeOrg();
- const badMessage = 'Bad request data';
- const multipleQueryWidget = {
- title: 'Sessions vs. Users',
- interval: '5m',
- displayType: DisplayType.LINE,
- queries: [
- {
- conditions: '',
- fields: [`sum(session)`],
- aggregates: [`sum(session)`],
- columns: [],
- name: 'sessions',
- orderby: '',
- },
- {
- conditions: 'environment:prod',
- fields: [`sum(session)`],
- aggregates: [`sum(session)`],
- columns: [],
- name: 'users',
- orderby: '',
- },
- ],
- widgetType: WidgetType.RELEASE,
- };
- const singleQueryWidget = {
- title: 'Sessions',
- interval: '5m',
- displayType: DisplayType.LINE,
- queries: [
- {
- conditions: '',
- fields: [`count_unique(user)`],
- aggregates: [`count_unique(user)`],
- columns: [],
- name: 'sessions',
- orderby: '-count_unique(user)',
- },
- ],
- widgetType: WidgetType.RELEASE,
- };
- const selection = {
- projects: [1],
- environments: ['prod'],
- datetime: {
- period: '14d',
- start: null,
- end: null,
- utc: null,
- },
- };
- const api = new Client();
- afterEach(function () {
- MockApiClient.clearMockResponses();
- });
- it('can send chart requests', async function () {
- jest.useFakeTimers().setSystemTime(new Date('2022-08-02'));
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.MetricsField({
- field: `sum(sentry.sessions.session)`,
- }),
- });
- const children = jest.fn(() => <div />);
- render(
- <ReleaseWidgetQueries
- api={api}
- widget={singleQueryWidget}
- organization={organization}
- selection={selection}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- expect(mock).toHaveBeenCalledTimes(1);
- await waitFor(() =>
- expect(children).toHaveBeenLastCalledWith(
- expect.objectContaining({
- tableResults: undefined,
- timeseriesResults: [
- {
- data: expect.arrayContaining([
- {name: '2021-12-01T16:15:00Z', value: 443.6200417187068},
- {name: '2021-12-01T16:30:00Z', value: 471.7512262596214},
- {name: '2021-12-01T16:45:00Z', value: 632.5356294251225},
- {name: '2021-12-01T17:00:00Z', value: 538.6063865509535},
- ]),
- seriesName: 'sessions > sum(session)',
- },
- ],
- })
- )
- );
- });
- it('fetches release data when sorting on release for metrics api', async function () {
- const mockRelease = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/',
- body: [
- {
- version: 'be1ddfb18126dd2cbde26bfe75488503280e716e',
- },
- ],
- });
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.MetricsSessionUserCountByStatusByRelease(),
- });
- const children = jest.fn(() => <div />);
- const queries = [
- {
- conditions: '',
- fields: [`count_unique(user)`],
- aggregates: [`count_unique(user)`],
- columns: ['release'],
- name: 'sessions',
- orderby: '-release',
- },
- ];
- render(
- <ReleaseWidgetQueries
- api={api}
- widget={{...singleQueryWidget, queries}}
- organization={organization}
- selection={selection}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- await waitFor(() => expect(mockRelease).toHaveBeenCalledTimes(1));
- expect(mockRelease).toHaveBeenCalledWith(
- '/organizations/org-slug/releases/',
- expect.objectContaining({
- data: {
- environment: ['prod'],
- per_page: 50,
- project: [1],
- sort: 'date',
- },
- })
- );
- expect(mock).toHaveBeenCalledTimes(1);
- expect(mock).toHaveBeenCalledWith(
- '/organizations/org-slug/metrics/data/',
- expect.objectContaining({
- query: {
- environment: ['prod'],
- field: ['count_unique(sentry.sessions.user)'],
- groupBy: ['release'],
- includeSeries: 1,
- includeTotals: 1,
- interval: '12h',
- per_page: 100,
- project: [1],
- query: ' release:be1ddfb18126dd2cbde26bfe75488503280e716e',
- statsPeriod: '14d',
- },
- })
- );
- });
- it('calls session api when session.status is a group by', function () {
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/sessions/',
- body: TestStubs.MetricsField({
- field: `count_unique(user)`,
- }),
- });
- const children = jest.fn(() => <div />);
- const queries = [
- {
- conditions: '',
- fields: [`count_unique(user)`],
- aggregates: [`count_unique(user)`],
- columns: ['session.status'],
- name: 'sessions',
- orderby: '-count_unique(user)',
- },
- ];
- render(
- <ReleaseWidgetQueries
- api={api}
- widget={{...singleQueryWidget, queries}}
- organization={organization}
- selection={selection}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- expect(mock).toHaveBeenCalledWith(
- '/organizations/org-slug/sessions/',
- expect.objectContaining({
- query: {
- environment: ['prod'],
- field: ['count_unique(user)'],
- groupBy: ['session.status'],
- interval: '30m',
- project: [1],
- statsPeriod: '14d',
- },
- })
- );
- });
- it('appends dashboard filters to releases request', async function () {
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.MetricsSessionUserCountByStatusByRelease(),
- });
- render(
- <ReleaseWidgetQueries
- api={api}
- widget={singleQueryWidget}
- organization={organization}
- selection={selection}
- dashboardFilters={{[DashboardFilterKeys.RELEASE]: ['abc@1.3.0']}}
- >
- {() => <div data-test-id="child" />}
- </ReleaseWidgetQueries>
- );
- await screen.findByTestId('child');
- expect(mock).toHaveBeenCalledWith(
- '/organizations/org-slug/metrics/data/',
- expect.objectContaining({
- query: expect.objectContaining({
- query: ' release:abc@1.3.0 ',
- }),
- })
- );
- });
- it('strips injected sort columns', async function () {
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.MetricsSessionUserCountByStatusByRelease(),
- });
- const children = jest.fn(() => <div />);
- const injectedOrderby = {
- title: 'Sessions',
- interval: '5m',
- displayType: DisplayType.LINE,
- queries: [
- {
- conditions: '',
- fields: [`sum(session)`],
- aggregates: [`sum(session)`],
- columns: [],
- name: 'sessions',
- orderby: '-count_unique(user)',
- },
- ],
- widgetType: WidgetType.RELEASE,
- };
- render(
- <ReleaseWidgetQueries
- api={api}
- widget={injectedOrderby}
- organization={organization}
- selection={selection}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- expect(mock).toHaveBeenCalledTimes(1);
- await waitFor(() =>
- expect(children).toHaveBeenLastCalledWith(
- expect.objectContaining({
- errorMessage: undefined,
- loading: false,
- timeseriesResults: [
- {
- data: [
- {name: '2022-01-15T00:00:00Z', value: 0},
- {name: '2022-01-16T00:00:00Z', value: 0},
- {name: '2022-01-17T00:00:00Z', value: 0},
- {name: '2022-01-18T00:00:00Z', value: 0},
- {name: '2022-01-19T00:00:00Z', value: 0},
- {name: '2022-01-20T00:00:00Z', value: 0},
- {name: '2022-01-21T00:00:00Z', value: 0},
- {name: '2022-01-22T00:00:00Z', value: 0},
- {name: '2022-01-23T00:00:00Z', value: 0},
- {name: '2022-01-24T00:00:00Z', value: 23},
- {name: '2022-01-25T00:00:00Z', value: 11},
- {name: '2022-01-26T00:00:00Z', value: 0},
- {name: '2022-01-27T00:00:00Z', value: 0},
- {name: '2022-01-28T00:00:00Z', value: 0},
- ],
- seriesName: 'sessions > crashed, 1 : sum(session)',
- },
- {
- data: [
- {name: '2022-01-15T00:00:00Z', value: 1},
- {name: '2022-01-16T00:00:00Z', value: 0},
- {name: '2022-01-17T00:00:00Z', value: 0},
- {name: '2022-01-18T00:00:00Z', value: 0},
- {name: '2022-01-19T00:00:00Z', value: 0},
- {name: '2022-01-20T00:00:00Z', value: 0},
- {name: '2022-01-21T00:00:00Z', value: 0},
- {name: '2022-01-22T00:00:00Z', value: 0},
- {name: '2022-01-23T00:00:00Z', value: 0},
- {name: '2022-01-24T00:00:00Z', value: 0},
- {name: '2022-01-25T00:00:00Z', value: 0},
- {name: '2022-01-26T00:00:00Z', value: 0},
- {name: '2022-01-27T00:00:00Z', value: 0},
- {name: '2022-01-28T00:00:00Z', value: 0},
- ],
- seriesName: 'sessions > abnormal, 1 : sum(session)',
- },
- {
- data: [
- {name: '2022-01-15T00:00:00Z', value: 0},
- {name: '2022-01-16T00:00:00Z', value: 0},
- {name: '2022-01-17T00:00:00Z', value: 0},
- {name: '2022-01-18T00:00:00Z', value: 0},
- {name: '2022-01-19T00:00:00Z', value: 0},
- {name: '2022-01-20T00:00:00Z', value: 37},
- {name: '2022-01-21T00:00:00Z', value: 0},
- {name: '2022-01-22T00:00:00Z', value: 0},
- {name: '2022-01-23T00:00:00Z', value: 0},
- {name: '2022-01-24T00:00:00Z', value: 335},
- {name: '2022-01-25T00:00:00Z', value: 79},
- {name: '2022-01-26T00:00:00Z', value: 0},
- {name: '2022-01-27T00:00:00Z', value: 0},
- {name: '2022-01-28T00:00:00Z', value: 0},
- ],
- seriesName: 'sessions > errored, 1 : sum(session)',
- },
- {
- data: [
- {name: '2022-01-15T00:00:00Z', value: 0},
- {name: '2022-01-16T00:00:00Z', value: 0},
- {name: '2022-01-17T00:00:00Z', value: 0},
- {name: '2022-01-18T00:00:00Z', value: 0},
- {name: '2022-01-19T00:00:00Z', value: 0},
- {name: '2022-01-20T00:00:00Z', value: 2503},
- {name: '2022-01-21T00:00:00Z', value: 661},
- {name: '2022-01-22T00:00:00Z', value: 0},
- {name: '2022-01-23T00:00:00Z', value: 0},
- {name: '2022-01-24T00:00:00Z', value: 1464},
- {name: '2022-01-25T00:00:00Z', value: 430},
- {name: '2022-01-26T00:00:00Z', value: 0},
- {name: '2022-01-27T00:00:00Z', value: 0},
- {name: '2022-01-28T00:00:00Z', value: 0},
- ],
- seriesName: 'sessions > healthy, 1 : sum(session)',
- },
- {
- data: [
- {name: '2022-01-15T00:00:00Z', value: 1},
- {name: '2022-01-16T00:00:00Z', value: 0},
- {name: '2022-01-17T00:00:00Z', value: 0},
- {name: '2022-01-18T00:00:00Z', value: 0},
- {name: '2022-01-19T00:00:00Z', value: 0},
- {name: '2022-01-20T00:00:00Z', value: 0},
- {name: '2022-01-21T00:00:00Z', value: 0},
- {name: '2022-01-22T00:00:00Z', value: 0},
- {name: '2022-01-23T00:00:00Z', value: 0},
- {name: '2022-01-24T00:00:00Z', value: 23},
- {name: '2022-01-25T00:00:00Z', value: 11},
- {name: '2022-01-26T00:00:00Z', value: 0},
- {name: '2022-01-27T00:00:00Z', value: 0},
- {name: '2022-01-28T00:00:00Z', value: 0},
- ],
- seriesName: 'sessions > crashed, 2 : sum(session)',
- },
- {
- data: [
- {name: '2022-01-15T00:00:00Z', value: 1},
- {name: '2022-01-16T00:00:00Z', value: 0},
- {name: '2022-01-17T00:00:00Z', value: 0},
- {name: '2022-01-18T00:00:00Z', value: 0},
- {name: '2022-01-19T00:00:00Z', value: 0},
- {name: '2022-01-20T00:00:00Z', value: 0},
- {name: '2022-01-21T00:00:00Z', value: 0},
- {name: '2022-01-22T00:00:00Z', value: 0},
- {name: '2022-01-23T00:00:00Z', value: 0},
- {name: '2022-01-24T00:00:00Z', value: 0},
- {name: '2022-01-25T00:00:00Z', value: 0},
- {name: '2022-01-26T00:00:00Z', value: 0},
- {name: '2022-01-27T00:00:00Z', value: 0},
- {name: '2022-01-28T00:00:00Z', value: 0},
- ],
- seriesName: 'sessions > abnormal, 2 : sum(session)',
- },
- {
- data: [
- {name: '2022-01-15T00:00:00Z', value: 1},
- {name: '2022-01-16T00:00:00Z', value: 0},
- {name: '2022-01-17T00:00:00Z', value: 0},
- {name: '2022-01-18T00:00:00Z', value: 0},
- {name: '2022-01-19T00:00:00Z', value: 0},
- {name: '2022-01-20T00:00:00Z', value: 37},
- {name: '2022-01-21T00:00:00Z', value: 0},
- {name: '2022-01-22T00:00:00Z', value: 0},
- {name: '2022-01-23T00:00:00Z', value: 0},
- {name: '2022-01-24T00:00:00Z', value: 335},
- {name: '2022-01-25T00:00:00Z', value: 79},
- {name: '2022-01-26T00:00:00Z', value: 0},
- {name: '2022-01-27T00:00:00Z', value: 0},
- {name: '2022-01-28T00:00:00Z', value: 0},
- ],
- seriesName: 'sessions > errored, 2 : sum(session)',
- },
- {
- data: [
- {name: '2022-01-15T00:00:00Z', value: 1},
- {name: '2022-01-16T00:00:00Z', value: 0},
- {name: '2022-01-17T00:00:00Z', value: 0},
- {name: '2022-01-18T00:00:00Z', value: 0},
- {name: '2022-01-19T00:00:00Z', value: 0},
- {name: '2022-01-20T00:00:00Z', value: 2503},
- {name: '2022-01-21T00:00:00Z', value: 661},
- {name: '2022-01-22T00:00:00Z', value: 0},
- {name: '2022-01-23T00:00:00Z', value: 0},
- {name: '2022-01-24T00:00:00Z', value: 1464},
- {name: '2022-01-25T00:00:00Z', value: 430},
- {name: '2022-01-26T00:00:00Z', value: 0},
- {name: '2022-01-27T00:00:00Z', value: 0},
- {name: '2022-01-28T00:00:00Z', value: 0},
- ],
- seriesName: 'sessions > healthy, 2 : sum(session)',
- },
- ],
- })
- )
- );
- });
- it('can send table requests', async function () {
- jest.useFakeTimers().setSystemTime(new Date('2022-08-02'));
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.MetricsSessionUserCountByStatusByRelease(),
- });
- const children = jest.fn(() => <div />);
- render(
- <ReleaseWidgetQueries
- api={api}
- widget={{...singleQueryWidget, displayType: DisplayType.TABLE}}
- organization={organization}
- selection={selection}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- expect(mock).toHaveBeenCalledTimes(1);
- await waitFor(() =>
- expect(children).toHaveBeenLastCalledWith(
- expect.objectContaining({
- errorMessage: undefined,
- loading: false,
- tableResults: [
- {
- data: [
- {
- 'count_unique(user)': 1,
- id: '0',
- release: '1',
- 'session.status': 'crashed',
- 'sum(session)': 34,
- },
- {
- 'count_unique(user)': 1,
- id: '1',
- release: '1',
- 'session.status': 'abnormal',
- 'sum(session)': 1,
- },
- {
- 'count_unique(user)': 2,
- id: '2',
- release: '1',
- 'session.status': 'errored',
- 'sum(session)': 451,
- },
- {
- 'count_unique(user)': 3,
- id: '3',
- release: '1',
- 'session.status': 'healthy',
- 'sum(session)': 5058,
- },
- {
- 'count_unique(user)': 2,
- id: '4',
- release: '2',
- 'session.status': 'crashed',
- 'sum(session)': 35,
- },
- {
- 'count_unique(user)': 1,
- id: '5',
- release: '2',
- 'session.status': 'abnormal',
- 'sum(session)': 1,
- },
- {
- 'count_unique(user)': 1,
- id: '6',
- release: '2',
- 'session.status': 'errored',
- 'sum(session)': 452,
- },
- {
- 'count_unique(user)': 10,
- id: '7',
- release: '2',
- 'session.status': 'healthy',
- 'sum(session)': 5059,
- },
- ],
- meta: {
- 'count_unique(user)': 'integer',
- release: 'string',
- 'session.status': 'string',
- 'sum(session)': 'integer',
- },
- title: 'sessions',
- },
- ],
- timeseriesResults: undefined,
- })
- )
- );
- });
- it('can send big number requests', async function () {
- jest.useFakeTimers().setSystemTime(new Date('2022-08-02'));
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.MetricsField({
- field: `count_unique(sentry.sessions.user)`,
- }),
- });
- const children = jest.fn(() => <div />);
- render(
- <ReleaseWidgetQueries
- api={api}
- widget={{...singleQueryWidget, displayType: DisplayType.BIG_NUMBER}}
- organization={organization}
- selection={selection}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- expect(mock).toHaveBeenCalledTimes(1);
- expect(mock).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- field: ['count_unique(sentry.sessions.user)'],
- orderBy: '-count_unique(sentry.sessions.user)',
- }),
- })
- );
- await waitFor(() =>
- expect(children).toHaveBeenLastCalledWith(
- expect.objectContaining({
- loading: false,
- tableResults: [
- {
- data: [{'count_unique(user)': 51292.95404741901, id: '0'}],
- meta: {'count_unique(user)': 'integer'},
- title: 'sessions',
- },
- ],
- })
- )
- );
- });
- it('can send multiple API requests', function () {
- jest.useFakeTimers().setSystemTime(new Date('2022-08-02'));
- const metricsMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.SessionsField({
- field: `sum(sentry.sessions.session)`,
- }),
- match: [
- MockApiClient.matchQuery({
- field: [`sum(sentry.sessions.session)`],
- }),
- ],
- });
- render(
- <ReleaseWidgetQueries
- api={api}
- widget={multipleQueryWidget}
- organization={organization}
- selection={selection}
- >
- {() => <div data-test-id="child" />}
- </ReleaseWidgetQueries>
- );
- // Child should be rendered and 2 requests should be sent.
- expect(screen.getByTestId('child')).toBeInTheDocument();
- expect(metricsMock).toHaveBeenCalledTimes(2);
- expect(metricsMock).toHaveBeenNthCalledWith(
- 1,
- '/organizations/org-slug/metrics/data/',
- expect.objectContaining({
- query: {
- environment: ['prod'],
- field: ['sum(sentry.sessions.session)'],
- groupBy: [],
- interval: '30m',
- project: [1],
- statsPeriod: '14d',
- per_page: 1,
- includeSeries: 1,
- includeTotals: 0,
- },
- })
- );
- expect(metricsMock).toHaveBeenNthCalledWith(
- 2,
- '/organizations/org-slug/metrics/data/',
- expect.objectContaining({
- query: {
- environment: ['prod'],
- field: ['sum(sentry.sessions.session)'],
- groupBy: [],
- interval: '30m',
- project: [1],
- query: 'environment:prod',
- statsPeriod: '14d',
- per_page: 1,
- includeSeries: 1,
- includeTotals: 0,
- },
- })
- );
- });
- it('sets errorMessage when the first request fails', async function () {
- const failMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- statusCode: 400,
- body: {detail: badMessage},
- match: [
- MockApiClient.matchQuery({
- field: [`sum(sentry.sessions.session)`],
- }),
- ],
- });
- const children = jest.fn(() => <div data-test-id="child" />);
- render(
- <ReleaseWidgetQueries
- api={api}
- widget={multipleQueryWidget}
- organization={organization}
- selection={selection}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- // Child should be rendered and 2 requests should be sent.
- expect(screen.getByTestId('child')).toBeInTheDocument();
- expect(failMock).toHaveBeenCalledTimes(2);
- await waitFor(() =>
- expect(children).toHaveBeenLastCalledWith(
- expect.objectContaining({errorMessage: badMessage})
- )
- );
- });
- it('adjusts interval based on date window', function () {
- jest.useFakeTimers().setSystemTime(new Date('2022-08-02'));
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.SessionsField({
- field: `sum(sentry.sessions.session)`,
- }),
- });
- render(
- <ReleaseWidgetQueries
- api={api}
- widget={{...singleQueryWidget, interval: '1m'}}
- organization={organization}
- selection={{...selection, datetime: {...selection.datetime, period: '14d'}}}
- >
- {() => <div data-test-id="child" />}
- </ReleaseWidgetQueries>
- );
- expect(screen.getByTestId('child')).toBeInTheDocument();
- expect(mock).toHaveBeenCalledTimes(1);
- expect(mock).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- interval: '30m',
- statsPeriod: '14d',
- environment: ['prod'],
- project: [1],
- }),
- })
- );
- });
- it('does not re-fetch when renaming legend alias / adding falsy fields', () => {
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.SessionsField({
- field: `sum(sentry.sessions.session)`,
- }),
- });
- const children = jest.fn(() => <div />);
- const {rerender} = render(
- <ReleaseWidgetQueries
- api={api}
- widget={singleQueryWidget}
- organization={organization}
- selection={selection}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- expect(mock).toHaveBeenCalledTimes(1);
- rerender(
- <ReleaseWidgetQueries
- api={api}
- widget={{
- ...singleQueryWidget,
- queries: [
- {
- ...singleQueryWidget.queries[0],
- name: 'New Legend Alias',
- fields: [...singleQueryWidget.queries[0].fields, ''],
- },
- ],
- }}
- organization={organization}
- selection={selection}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- // no additional request has been sent, the total count of requests is still 1
- expect(mock).toHaveBeenCalledTimes(1);
- });
- it('does not re-fetch when dashboard filter remains the same', () => {
- const mock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.SessionsField({
- field: `sum(sentry.sessions.session)`,
- }),
- });
- const children = jest.fn(() => <div />);
- const {rerender} = render(
- <ReleaseWidgetQueries
- api={api}
- widget={singleQueryWidget}
- organization={organization}
- selection={selection}
- dashboardFilters={{[DashboardFilterKeys.RELEASE]: ['abc@1.3.0']}}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- expect(mock).toHaveBeenCalledTimes(1);
- rerender(
- <ReleaseWidgetQueries
- api={api}
- widget={singleQueryWidget}
- organization={organization}
- selection={selection}
- dashboardFilters={{[DashboardFilterKeys.RELEASE]: ['abc@1.3.0']}}
- >
- {children}
- </ReleaseWidgetQueries>
- );
- // no additional request has been sent, the total count of requests is still 1
- expect(mock).toHaveBeenCalledTimes(1);
- });
- });
|