123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038 |
- import {
- initializeData as _initializeData,
- initializeDataSettings,
- } from 'sentry-test/performance/initializePerformanceData';
- import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
- import {
- PageErrorAlert,
- PageErrorProvider,
- } from 'sentry/utils/performance/contexts/pageError';
- import {PerformanceDisplayProvider} from 'sentry/utils/performance/contexts/performanceDisplayContext';
- import {OrganizationContext} from 'sentry/views/organizationContext';
- import WidgetContainer from 'sentry/views/performance/landing/widgets/components/widgetContainer';
- import {PerformanceWidgetSetting} from 'sentry/views/performance/landing/widgets/widgetDefinitions';
- import {PROJECT_PERFORMANCE_TYPE} from 'sentry/views/performance/utils';
- const initializeData = (query = {}, rest: initializeDataSettings = {}) => {
- const data = _initializeData({
- query: {statsPeriod: '7d', environment: ['prod'], project: [-42], ...query},
- ...rest,
- });
- data.eventView.additionalConditions.addFilterValues('transaction.op', ['pageload']);
- return data;
- };
- function WrappedComponent({data, withStaticFilters = false, ...rest}) {
- return (
- <OrganizationContext.Provider value={data.organization}>
- <MEPSettingProvider>
- <PerformanceDisplayProvider
- value={{performanceType: PROJECT_PERFORMANCE_TYPE.ANY}}
- >
- <WidgetContainer
- allowedCharts={[
- PerformanceWidgetSetting.TPM_AREA,
- PerformanceWidgetSetting.FAILURE_RATE_AREA,
- PerformanceWidgetSetting.USER_MISERY_AREA,
- PerformanceWidgetSetting.DURATION_HISTOGRAM,
- ]}
- rowChartSettings={[]}
- withStaticFilters={withStaticFilters}
- forceDefaultChartSetting
- {...data}
- {...rest}
- />
- </PerformanceDisplayProvider>
- </MEPSettingProvider>
- </OrganizationContext.Provider>
- );
- }
- const issuesPredicate = (url, options) =>
- url.includes('events') && options.query?.query.includes('error');
- describe('Performance > Widgets > WidgetContainer', function () {
- let wrapper;
- let eventStatsMock;
- let eventsTrendsStats;
- let eventsMock;
- let issuesListMock;
- beforeEach(function () {
- eventStatsMock = MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/org-slug/events-stats/`,
- body: [],
- });
- eventsMock = MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/org-slug/events/`,
- body: {
- data: [{}],
- meta: {},
- },
- match: [(...args) => !issuesPredicate(...args)],
- });
- issuesListMock = MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/org-slug/events/`,
- body: {
- data: [
- {
- 'issue.id': 123,
- transaction: '/issue/:id/',
- title: 'Error: Something is broken.',
- 'project.id': 1,
- count: 3100,
- issue: 'JAVASCRIPT-ABCD',
- },
- ],
- },
- match: [(...args) => issuesPredicate(...args)],
- });
- eventsTrendsStats = MockApiClient.addMockResponse({
- method: 'GET',
- url: '/organizations/org-slug/events-trends-stats/',
- body: [],
- });
- });
- afterEach(function () {
- if (wrapper) {
- wrapper.unmount();
- wrapper = undefined;
- }
- });
- it('Check requests when changing widget props', function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.TPM_AREA}
- />
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- // Change eventView reference
- data.eventView = data.eventView.clone();
- wrapper.rerender(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.TPM_AREA}
- />
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- // Change eventView statsperiod
- const modifiedData = initializeData({
- statsPeriod: '14d',
- });
- wrapper.rerender(
- <WrappedComponent
- data={modifiedData}
- defaultChartSetting={PerformanceWidgetSetting.TPM_AREA}
- />
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(2);
- expect(eventStatsMock).toHaveBeenNthCalledWith(
- 2,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- interval: '1h',
- partial: '1',
- query: 'transaction.op:pageload',
- statsPeriod: '28d',
- yAxis: 'tpm()',
- }),
- })
- );
- });
- it('Check requests when changing widget props for GenericDiscoverQuery based widget', function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_IMPROVED}
- />
- );
- expect(eventsTrendsStats).toHaveBeenCalledTimes(1);
- // Change eventView reference
- data.eventView = data.eventView.clone();
- wrapper.rerender(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_IMPROVED}
- />
- );
- expect(eventsTrendsStats).toHaveBeenCalledTimes(1);
- // Change eventView statsperiod
- const modifiedData = initializeData({
- statsPeriod: '14d',
- });
- wrapper.rerender(
- <WrappedComponent
- data={modifiedData}
- defaultChartSetting={PerformanceWidgetSetting.MOST_IMPROVED}
- />
- );
- expect(eventsTrendsStats).toHaveBeenCalledTimes(2);
- expect(eventsTrendsStats).toHaveBeenNthCalledWith(
- 2,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- cursor: '0:0:1',
- environment: ['prod'],
- field: ['transaction', 'project'],
- interval: undefined,
- middle: undefined,
- noPagination: true,
- per_page: 3,
- project: ['-42'],
- query:
- 'transaction.op:pageload tpm():>0.01 count_percentage():>0.25 count_percentage():<4 trend_percentage():>0% confidence():>6',
- sort: 'trend_percentage()',
- statsPeriod: '14d',
- trendFunction: 'avg(transaction.duration)',
- trendType: 'improved',
- }),
- })
- );
- });
- it('should call PageError Provider when errors are present', async function () {
- const data = initializeData();
- eventStatsMock = MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/org-slug/events-stats/`,
- statusCode: 400,
- body: {
- detail: 'Request did not work :(',
- },
- });
- wrapper = render(
- <PageErrorProvider>
- <PageErrorAlert />
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.TPM_AREA}
- />
- </PageErrorProvider>
- );
- // Provider update is after request promise.
- await act(async () => {});
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Transactions Per Minute'
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- expect(await screen.findByTestId('page-error-alert')).toHaveTextContent(
- 'Request did not work :('
- );
- });
- it('TPM Widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.TPM_AREA}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Transactions Per Minute'
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- expect(eventStatsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- interval: '1h',
- partial: '1',
- query: 'transaction.op:pageload',
- statsPeriod: '14d',
- yAxis: 'tpm()',
- }),
- })
- );
- });
- it('Failure Rate Widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Failure Rate'
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- expect(eventStatsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- interval: '1h',
- partial: '1',
- query: 'transaction.op:pageload',
- statsPeriod: '14d',
- yAxis: 'failure_rate()',
- }),
- })
- );
- });
- it('Widget with MEP enabled and metric meta set to true', async function () {
- const data = initializeData(
- {},
- {
- features: ['performance-use-metrics'],
- }
- );
- eventStatsMock = MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/org-slug/events-stats/`,
- body: {
- data: [],
- isMetricsData: true,
- },
- });
- eventsMock = MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/org-slug/events/`,
- body: {
- data: [{}],
- meta: {isMetricsData: true},
- },
- });
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
- />
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- expect(eventStatsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({dataset: 'metrics'}),
- })
- );
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventsMock).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({dataset: 'metrics'}),
- })
- );
- expect(await screen.findByTestId('has-metrics-data-tag')).toHaveTextContent(
- 'processed'
- );
- });
- it('Widget with MEP enabled and metric meta set to undefined', async function () {
- const data = initializeData(
- {},
- {
- features: ['performance-use-metrics'],
- }
- );
- eventStatsMock = MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/org-slug/events-stats/`,
- body: {
- data: [],
- isMetricsData: undefined,
- },
- });
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
- />
- );
- expect(await screen.findByTestId('no-metrics-data-tag')).toBeInTheDocument();
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- expect(eventStatsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({dataset: 'metrics'}),
- })
- );
- });
- it('Widget with MEP enabled and metric meta set to false', async function () {
- const data = initializeData(
- {},
- {
- features: ['performance-use-metrics'],
- }
- );
- eventStatsMock = MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/org-slug/events-stats/`,
- body: {
- data: [],
- isMetricsData: false,
- },
- });
- eventsMock = MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/org-slug/events/`,
- body: {
- data: [{}],
- meta: {isMetricsData: false},
- },
- });
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
- />
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- expect(eventStatsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({dataset: 'metrics'}),
- })
- );
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventsMock).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({dataset: 'metrics'}),
- })
- );
- expect(await screen.findByTestId('has-metrics-data-tag')).toHaveTextContent(
- 'indexed'
- );
- });
- it('User misery Widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.USER_MISERY_AREA}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'User Misery'
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- expect(eventStatsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- interval: '1h',
- partial: '1',
- query: 'transaction.op:pageload',
- statsPeriod: '14d',
- yAxis: 'user_misery()',
- }),
- })
- );
- });
- it('Worst LCP widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.WORST_LCP_VITALS}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Worst LCP Web Vitals'
- );
- expect(await screen.findByTestId('view-all-button')).toHaveTextContent('View All');
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- environment: ['prod'],
- field: [
- 'transaction',
- 'title',
- 'project.id',
- 'count_web_vitals(measurements.lcp, poor)',
- 'count_web_vitals(measurements.lcp, meh)',
- 'count_web_vitals(measurements.lcp, good)',
- ],
- per_page: 4,
- project: ['-42'],
- query: 'transaction.op:pageload',
- sort: '-count_web_vitals(measurements.lcp, poor)',
- statsPeriod: '7d',
- }),
- })
- );
- });
- it('Worst LCP widget - MEP', async function () {
- const data = initializeData(
- {},
- {
- features: ['performance-use-metrics'],
- }
- );
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.WORST_LCP_VITALS}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Worst LCP Web Vitals'
- );
- expect(await screen.findByTestId('view-all-button')).toHaveTextContent('View All');
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- environment: ['prod'],
- field: [
- 'transaction',
- 'title',
- 'project.id',
- 'count_web_vitals(measurements.lcp, poor)',
- 'count_web_vitals(measurements.lcp, meh)',
- 'count_web_vitals(measurements.lcp, good)',
- ],
- per_page: 4,
- project: ['-42'],
- query: 'transaction.op:pageload !transaction:"<< unparameterized >>"',
- sort: '-count_web_vitals(measurements.lcp, poor)',
- statsPeriod: '7d',
- }),
- })
- );
- });
- it('Worst FCP widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.WORST_FCP_VITALS}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Worst FCP Web Vitals'
- );
- expect(await screen.findByTestId('view-all-button')).toHaveTextContent('View All');
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- environment: ['prod'],
- field: [
- 'transaction',
- 'title',
- 'project.id',
- 'count_web_vitals(measurements.fcp, poor)',
- 'count_web_vitals(measurements.fcp, meh)',
- 'count_web_vitals(measurements.fcp, good)',
- ],
- per_page: 4,
- project: ['-42'],
- query: 'transaction.op:pageload',
- sort: '-count_web_vitals(measurements.fcp, poor)',
- statsPeriod: '7d',
- }),
- })
- );
- });
- it('Worst FID widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.WORST_FID_VITALS}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Worst FID Web Vitals'
- );
- expect(await screen.findByTestId('view-all-button')).toHaveTextContent('View All');
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- environment: ['prod'],
- field: [
- 'transaction',
- 'title',
- 'project.id',
- 'count_web_vitals(measurements.fid, poor)',
- 'count_web_vitals(measurements.fid, meh)',
- 'count_web_vitals(measurements.fid, good)',
- ],
- per_page: 4,
- project: ['-42'],
- query: 'transaction.op:pageload',
- sort: '-count_web_vitals(measurements.fid, poor)',
- statsPeriod: '7d',
- }),
- })
- );
- });
- it('LCP Histogram Widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.LCP_HISTOGRAM}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'LCP Distribution'
- );
- // TODO(k-fish): Add histogram mock
- });
- it('FCP Histogram Widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.FCP_HISTOGRAM}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'FCP Distribution'
- );
- // TODO(k-fish): Add histogram mock
- });
- it('Most errors widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_RELATED_ERRORS}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Most Related Errors'
- );
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- environment: ['prod'],
- field: ['transaction', 'project.id', 'failure_count()'],
- per_page: 3,
- project: ['-42'],
- query: 'transaction.op:pageload failure_count():>0',
- sort: '-failure_count()',
- statsPeriod: '7d',
- }),
- })
- );
- });
- it('Most related issues widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_RELATED_ISSUES}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Most Related Issues'
- );
- expect(issuesListMock).toHaveBeenCalledTimes(1);
- expect(issuesListMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- environment: ['prod'],
- field: ['issue', 'transaction', 'title', 'project.id', 'count()'],
- per_page: 3,
- project: ['-42'],
- query: 'event.type:error !tags[transaction]:"" count():>0',
- sort: '-count()',
- statsPeriod: '7d',
- }),
- })
- );
- });
- it('Switching from issues to errors widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_RELATED_ISSUES}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Most Related Issues'
- );
- expect(issuesListMock).toHaveBeenCalledTimes(1);
- wrapper.rerender(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_RELATED_ERRORS}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Most Related Errors'
- );
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- });
- it('Most improved trends widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_IMPROVED}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Most Improved'
- );
- expect(eventsTrendsStats).toHaveBeenCalledTimes(1);
- expect(eventsTrendsStats).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- environment: ['prod'],
- field: ['transaction', 'project'],
- interval: undefined,
- middle: undefined,
- per_page: 3,
- project: ['-42'],
- query:
- 'transaction.op:pageload tpm():>0.01 count_percentage():>0.25 count_percentage():<4 trend_percentage():>0% confidence():>6',
- sort: 'trend_percentage()',
- statsPeriod: '7d',
- trendFunction: 'avg(transaction.duration)',
- trendType: 'improved',
- }),
- })
- );
- });
- it('Most regressed trends widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_REGRESSED}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Most Regressed'
- );
- expect(eventsTrendsStats).toHaveBeenCalledTimes(1);
- expect(eventsTrendsStats).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- environment: ['prod'],
- field: ['transaction', 'project'],
- interval: undefined,
- middle: undefined,
- per_page: 3,
- project: ['-42'],
- query:
- 'transaction.op:pageload tpm():>0.01 count_percentage():>0.25 count_percentage():<4 trend_percentage():>0% confidence():>6',
- sort: '-trend_percentage()',
- statsPeriod: '7d',
- trendFunction: 'avg(transaction.duration)',
- trendType: 'regression',
- }),
- })
- );
- });
- it('Most slow frames widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_SLOW_FRAMES}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Most Slow Frames'
- );
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- cursor: '0:0:1',
- environment: ['prod'],
- field: ['transaction', 'project.id', 'epm()', 'avg(measurements.frames_slow)'],
- noPagination: true,
- per_page: 3,
- project: ['-42'],
- query: 'transaction.op:pageload epm():>0.01 avg(measurements.frames_slow):>0',
- sort: '-avg(measurements.frames_slow)',
- statsPeriod: '7d',
- }),
- })
- );
- expect(await screen.findByTestId('empty-state')).toBeInTheDocument();
- });
- it('Most slow frames widget - MEP', async function () {
- const data = initializeData(
- {},
- {
- features: ['performance-use-metrics'],
- }
- );
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_SLOW_FRAMES}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Most Slow Frames'
- );
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- cursor: '0:0:1',
- environment: ['prod'],
- field: ['transaction', 'project.id', 'epm()', 'avg(measurements.frames_slow)'],
- noPagination: true,
- per_page: 3,
- project: ['-42'],
- query: 'transaction.op:pageload epm():>0.01 avg(measurements.frames_slow):>0',
- sort: '-avg(measurements.frames_slow)',
- statsPeriod: '7d',
- }),
- })
- );
- expect(await screen.findByTestId('empty-state')).toBeInTheDocument();
- });
- it('Most frozen frames widget', async function () {
- const data = initializeData();
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.MOST_FROZEN_FRAMES}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Most Frozen Frames'
- );
- expect(eventsMock).toHaveBeenCalledTimes(1);
- expect(eventsMock).toHaveBeenNthCalledWith(
- 1,
- expect.anything(),
- expect.objectContaining({
- query: expect.objectContaining({
- cursor: '0:0:1',
- environment: ['prod'],
- field: [
- 'transaction',
- 'project.id',
- 'epm()',
- 'avg(measurements.frames_frozen)',
- ],
- noPagination: true,
- per_page: 3,
- project: ['-42'],
- query: 'transaction.op:pageload epm():>0.01 avg(measurements.frames_frozen):>0',
- sort: '-avg(measurements.frames_frozen)',
- statsPeriod: '7d',
- }),
- })
- );
- expect(await screen.findByTestId('empty-state')).toBeInTheDocument();
- });
- it('Able to change widget type from menu', async function () {
- const data = initializeData();
- const setRowChartSettings = jest.fn(() => {});
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
- setRowChartSettings={setRowChartSettings}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Failure Rate'
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(1);
- expect(setRowChartSettings).toHaveBeenCalledTimes(0);
- await userEvent.click(await screen.findByLabelText('More'));
- await userEvent.click(await screen.findByText('User Misery'));
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'User Misery'
- );
- expect(eventStatsMock).toHaveBeenCalledTimes(2);
- expect(setRowChartSettings).toHaveBeenCalledTimes(1);
- });
- it('Chart settings passed from the row are disabled in the menu', async function () {
- const data = initializeData();
- const setRowChartSettings = jest.fn(() => {});
- wrapper = render(
- <WrappedComponent
- data={data}
- defaultChartSetting={PerformanceWidgetSetting.FAILURE_RATE_AREA}
- setRowChartSettings={setRowChartSettings}
- rowChartSettings={[
- PerformanceWidgetSetting.FAILURE_RATE_AREA,
- PerformanceWidgetSetting.USER_MISERY_AREA,
- ]}
- />
- );
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Failure Rate'
- );
- // Open context menu
- await userEvent.click(await screen.findByLabelText('More'));
- // Check that the the "User Misery" option is disabled by clicking on it,
- // expecting that the selected option doesn't change
- const userMiseryOption = await screen.findByRole('option', {name: 'User Misery'});
- await userEvent.click(userMiseryOption);
- expect(await screen.findByTestId('performance-widget-title')).toHaveTextContent(
- 'Failure Rate'
- );
- });
- });
|