1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549 |
- import ReactEchartsCore from 'echarts-for-react/lib/core';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
- import {ModalRenderProps} from 'sentry/actionCreators/modal';
- import WidgetViewerModal from 'sentry/components/modals/widgetViewerModal';
- import MemberListStore from 'sentry/stores/memberListStore';
- import PageFiltersStore from 'sentry/stores/pageFiltersStore';
- import space from 'sentry/styles/space';
- import {Series} from 'sentry/types/echarts';
- import {TableDataWithTitle} from 'sentry/utils/discover/discoverQuery';
- import {
- DisplayType,
- Widget,
- WidgetQuery,
- WidgetType,
- } from 'sentry/views/dashboardsV2/types';
- jest.mock('echarts-for-react/lib/core', () => {
- return jest.fn(({style}) => {
- return <div style={{...style, background: 'green'}}>echarts mock</div>;
- });
- });
- jest.mock('sentry/components/tooltip', () => {
- return jest.fn(props => {
- return <div>{props.children}</div>;
- });
- });
- const stubEl = (props: {children?: React.ReactNode}) => <div>{props.children}</div>;
- let eventsMetaMock;
- const waitForMetaToHaveBeenCalled = async () => {
- await waitFor(() => {
- expect(eventsMetaMock).toHaveBeenCalled();
- });
- };
- async function renderModal({
- initialData: {organization, routerContext},
- widget,
- seriesData,
- tableData,
- pageLinks,
- seriesResultsType,
- }: {
- initialData: any;
- widget: any;
- pageLinks?: string;
- seriesData?: Series[];
- seriesResultsType?: string;
- tableData?: TableDataWithTitle[];
- }) {
- const rendered = render(
- <div style={{padding: space(4)}}>
- <WidgetViewerModal
- Header={stubEl}
- Footer={stubEl as ModalRenderProps['Footer']}
- Body={stubEl as ModalRenderProps['Body']}
- CloseButton={stubEl}
- closeModal={() => undefined}
- organization={organization}
- widget={widget}
- onEdit={() => undefined}
- seriesData={seriesData}
- tableData={tableData}
- pageLinks={pageLinks}
- seriesResultsType={seriesResultsType}
- />
- </div>,
- {
- context: routerContext,
- organization,
- }
- );
- // Need to wait since WidgetViewerModal will make a request to events-meta
- // for total events count on mount
- if (widget.widgetType === WidgetType.DISCOVER) {
- await waitForMetaToHaveBeenCalled();
- }
- return rendered;
- }
- describe('Modals -> WidgetViewerModal', function () {
- let initialData, initialDataWithFlag;
- beforeEach(() => {
- initialData = initializeOrg({
- organization: {
- features: ['discover-query', 'widget-viewer-modal'],
- apdexThreshold: 400,
- },
- router: {
- location: {query: {}},
- },
- project: 1,
- projects: [],
- });
- initialDataWithFlag = {
- ...initialData,
- organization: {
- ...initialData.organization,
- features: [
- ...initialData.organization.features,
- 'discover-frontend-use-events-endpoint',
- ],
- },
- };
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/',
- body: [],
- });
- eventsMetaMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-meta/',
- body: {count: 33323612},
- });
- PageFiltersStore.init();
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [1, 2],
- environments: ['prod', 'dev'],
- datetime: {start: null, end: null, period: '24h', utc: null},
- },
- new Set()
- );
- });
- afterEach(() => {
- MockApiClient.clearMockResponses();
- PageFiltersStore.teardown();
- });
- describe('Discover Widgets', function () {
- describe('Area Chart Widget', function () {
- let mockQuery: WidgetQuery;
- let additionalMockQuery: WidgetQuery;
- let mockWidget: Widget;
- function mockEventsv2() {
- return MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- data: [
- {
- title: '/organizations/:orgId/dashboards/',
- id: '1',
- count: 1,
- },
- ],
- meta: {
- title: 'string',
- id: 'string',
- count: 1,
- isMetricsData: false,
- },
- },
- });
- }
- function mockEvents() {
- return MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- body: {
- data: [
- {
- title: '/organizations/:orgId/dashboards/',
- id: '1',
- count: 1,
- },
- ],
- meta: {
- fields: {
- title: 'string',
- id: 'string',
- count: 1,
- },
- isMetricsData: false,
- },
- },
- });
- }
- beforeEach(function () {
- mockQuery = {
- conditions: 'title:/organizations/:orgId/performance/summary/',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: [],
- name: 'Query Name',
- orderby: '',
- };
- additionalMockQuery = {
- conditions: '',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: [],
- name: 'Another Query Name',
- orderby: '',
- };
- mockWidget = {
- id: '1',
- title: 'Test Widget',
- displayType: DisplayType.AREA,
- interval: '5m',
- queries: [mockQuery, additionalMockQuery],
- widgetType: WidgetType.DISCOVER,
- };
- (ReactEchartsCore as jest.Mock).mockClear();
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: {
- data: [
- [[1646100000], [{count: 1}]],
- [[1646120000], [{count: 1}]],
- ],
- start: 1646100000,
- end: 1646120000,
- isMetricsData: false,
- },
- });
- });
- describe('with eventsv2', function () {
- it('renders Edit and Open buttons', async function () {
- mockEventsv2();
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('Edit Widget')).toBeInTheDocument();
- expect(screen.getByText('Open in Discover')).toBeInTheDocument();
- });
- it('renders updated table columns and orderby', async function () {
- const eventsv2Mock = mockEventsv2();
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('title')).toBeInTheDocument();
- expect(
- screen.getByText('/organizations/:orgId/dashboards/')
- ).toBeInTheDocument();
- expect(eventsv2Mock).toHaveBeenCalledWith(
- '/organizations/org-slug/eventsv2/',
- expect.objectContaining({
- query: expect.objectContaining({sort: ['-count()']}),
- })
- );
- });
- it('renders area chart', async function () {
- mockEventsv2();
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('echarts mock')).toBeInTheDocument();
- });
- it('renders Discover area chart widget viewer', async function () {
- mockEventsv2();
- const {container} = await renderModal({initialData, widget: mockWidget});
- expect(container).toSnapshot();
- });
- it('redirects user to Discover when clicking Open in Discover', async function () {
- mockEventsv2();
- await renderModal({initialData, widget: mockWidget});
- userEvent.click(screen.getByText('Open in Discover'));
- expect(initialData.router.push).toHaveBeenCalledWith(
- '/organizations/org-slug/discover/results/?environment=prod&environment=dev&field=count%28%29&name=Test%20Widget&project=1&project=2&query=title%3A%2Forganizations%2F%3AorgId%2Fperformance%2Fsummary%2F&statsPeriod=24h&yAxis=count%28%29'
- );
- });
- it('zooms into the selected time range', async function () {
- mockEventsv2();
- await renderModal({initialData, widget: mockWidget});
- act(() => {
- // Simulate dataZoom event on chart
- (ReactEchartsCore as jest.Mock).mock.calls[0][0].onEvents.datazoom(
- undefined,
- {
- getModel: () => {
- return {
- _payload: {
- batch: [{startValue: 1646100000000, endValue: 1646120000000}],
- },
- };
- },
- }
- );
- });
- expect(initialData.router.push).toHaveBeenCalledWith(
- expect.objectContaining({
- query: {
- viewerEnd: '2022-03-01T07:33:20',
- viewerStart: '2022-03-01T02:00:00',
- },
- })
- );
- });
- it('renders multiquery label and selector', async function () {
- mockEventsv2();
- await renderModal({initialData, widget: mockWidget});
- expect(
- screen.getByText(
- 'This widget was built with multiple queries. Table data can only be displayed for one query at a time. To edit any of the queries, edit the widget.'
- )
- ).toBeInTheDocument();
- expect(screen.getByText('Query Name')).toBeInTheDocument();
- });
- it('updates selected query when selected in the query dropdown', async function () {
- mockEventsv2();
- const {rerender} = await renderModal({initialData, widget: mockWidget});
- userEvent.click(screen.getByText('Query Name'));
- userEvent.click(screen.getByText('Another Query Name'));
- expect(initialData.router.replace).toHaveBeenCalledWith({
- query: {query: 1},
- });
- // Need to manually set the new router location and rerender to simulate the dropdown selection click
- initialData.router.location.query = {query: ['1']};
- rerender(
- <WidgetViewerModal
- Header={stubEl}
- Footer={stubEl as ModalRenderProps['Footer']}
- Body={stubEl as ModalRenderProps['Body']}
- CloseButton={stubEl}
- closeModal={() => undefined}
- organization={initialData.organization}
- widget={mockWidget}
- onEdit={() => undefined}
- />
- );
- await waitForMetaToHaveBeenCalled();
- expect(screen.getByText('Another Query Name')).toBeInTheDocument();
- });
- it('renders the correct discover query link when there are multiple queries in a widget', async function () {
- mockEventsv2();
- initialData.router.location.query = {query: ['1']};
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByRole('button', {name: 'Open in Discover'})).toHaveAttribute(
- 'href',
- '/organizations/org-slug/discover/results/?environment=prod&environment=dev&field=count%28%29&name=Test%20Widget&project=1&project=2&query=&statsPeriod=24h&yAxis=count%28%29'
- );
- });
- it('renders with first legend disabled by default', async function () {
- mockEventsv2();
- // Rerender with first legend disabled
- initialData.router.location.query = {legend: ['Query Name']};
- await renderModal({initialData, widget: mockWidget});
- expect(ReactEchartsCore).toHaveBeenLastCalledWith(
- expect.objectContaining({
- option: expect.objectContaining({
- legend: expect.objectContaining({
- selected: {'Query Name': false},
- }),
- }),
- }),
- {}
- );
- });
- it('renders total results in footer', async function () {
- mockEventsv2();
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('33,323,612')).toBeInTheDocument();
- });
- it('renders highlighted query text and multiple queries in select dropdown', async function () {
- mockEventsv2();
- const {container} = await renderModal({
- initialData,
- widget: {
- ...mockWidget,
- queries: [{...mockQuery, name: ''}, additionalMockQuery],
- },
- });
- userEvent.click(screen.getByText('/organizations/:orgId/performance/summary/'));
- expect(container).toSnapshot();
- });
- it('renders widget chart minimap', async function () {
- initialData.organization.features.push('widget-viewer-modal-minimap');
- mockEventsv2();
- await renderModal({
- initialData,
- widget: {
- ...mockWidget,
- queries: [{...mockQuery, name: ''}, additionalMockQuery],
- },
- });
- expect(ReactEchartsCore).toHaveBeenLastCalledWith(
- expect.objectContaining({
- option: expect.objectContaining({
- dataZoom: expect.arrayContaining([
- expect.objectContaining({
- realtime: false,
- showDetail: false,
- end: 100,
- start: 0,
- }),
- ]),
- }),
- }),
- {}
- );
- });
- it('zooming on minimap updates location query and updates echart start and end values', async function () {
- initialData.organization.features.push('widget-viewer-modal-minimap');
- mockEventsv2();
- await renderModal({
- initialData,
- widget: {
- ...mockWidget,
- queries: [{...mockQuery, name: ''}, additionalMockQuery],
- },
- });
- const calls = (ReactEchartsCore as jest.Mock).mock.calls;
- act(() => {
- // Simulate dataZoom event on chart
- calls[calls.length - 1][0].onEvents.datazoom(
- {seriesStart: 1646100000000, seriesEnd: 1646120000000},
- {
- getModel: () => {
- return {
- _payload: {start: 30, end: 70},
- };
- },
- }
- );
- });
- expect(initialData.router.push).toHaveBeenCalledWith(
- expect.objectContaining({
- query: {
- viewerEnd: '2022-03-01T05:53:20',
- viewerStart: '2022-03-01T03:40:00',
- },
- })
- );
- });
- it('includes group by in widget viewer table', async function () {
- mockEventsv2();
- mockWidget.queries = [
- {
- conditions: 'title:/organizations/:orgId/performance/summary/',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: ['transaction'],
- name: 'Query Name',
- orderby: '-count()',
- },
- ];
- await renderModal({initialData, widget: mockWidget});
- screen.getByText('transaction');
- });
- it('includes order by in widget viewer table if not explicitly selected', async function () {
- mockEventsv2();
- mockWidget.queries = [
- {
- conditions: 'title:/organizations/:orgId/performance/summary/',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: ['transaction'],
- name: 'Query Name',
- orderby: 'count_unique(user)',
- },
- ];
- await renderModal({initialData, widget: mockWidget});
- screen.getByText('count_unique(user)');
- });
- it('includes a custom equation order by in widget viewer table if not explicitly selected', async function () {
- mockEventsv2();
- mockWidget.queries = [
- {
- conditions: 'title:/organizations/:orgId/performance/summary/',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: ['transaction'],
- name: 'Query Name',
- orderby: '-equation|count_unique(user) + 1',
- },
- ];
- await renderModal({initialData, widget: mockWidget});
- screen.getByText('count_unique(user) + 1');
- });
- });
- describe('with events', function () {
- it('renders updated table columns and orderby', async function () {
- const eventsMock = mockEvents();
- await renderModal({initialData: initialDataWithFlag, widget: mockWidget});
- expect(screen.getByText('title')).toBeInTheDocument();
- expect(
- screen.getByText('/organizations/:orgId/dashboards/')
- ).toBeInTheDocument();
- expect(eventsMock).toHaveBeenCalledWith(
- '/organizations/org-slug/events/',
- expect.objectContaining({
- query: expect.objectContaining({sort: ['-count()']}),
- })
- );
- });
- it('renders widget chart with y axis formatter using provided seriesResultType', async function () {
- mockEvents();
- await renderModal({
- initialData: initialDataWithFlag,
- widget: mockWidget,
- seriesData: [],
- seriesResultsType: 'duration',
- });
- const calls = (ReactEchartsCore as jest.Mock).mock.calls;
- const yAxisFormatter =
- calls[calls.length - 1][0].option.yAxis.axisLabel.formatter;
- expect(yAxisFormatter(123)).toEqual('123ms');
- });
- });
- });
- describe('TopN Chart Widget', function () {
- let mockQuery, mockWidget;
- function mockEventsStats() {
- return MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: {
- data: [
- [[1646100000], [{count: 1}]],
- [[1646120000], [{count: 1}]],
- ],
- start: 1646100000,
- end: 1646120000,
- isMetricsData: false,
- },
- });
- }
- const eventsMockData = [
- {
- 'error.type': ['Test Error 1a', 'Test Error 1b', 'Test Error 1c'],
- count: 10,
- },
- {
- 'error.type': ['Test Error 2'],
- count: 6,
- },
- {
- 'error.type': ['Test Error 3'],
- count: 5,
- },
- {
- 'error.type': ['Test Error 4'],
- count: 4,
- },
- {
- 'error.type': ['Test Error 5'],
- count: 3,
- },
- {
- 'error.type': ['Test Error 6'],
- count: 2,
- },
- ];
- function mockEventsv2() {
- return MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- match: [MockApiClient.matchQuery({cursor: undefined})],
- headers: {
- Link:
- '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1",' +
- '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=0:10:0>; rel="next"; results="true"; cursor="0:10:0"',
- },
- body: {
- data: eventsMockData,
- meta: {
- 'error.type': 'array',
- count: 'integer',
- },
- },
- });
- }
- function mockEvents() {
- return MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- match: [MockApiClient.matchQuery({cursor: undefined})],
- headers: {
- Link:
- '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1",' +
- '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=0:10:0>; rel="next"; results="true"; cursor="0:10:0"',
- },
- body: {
- data: eventsMockData,
- meta: {
- fields: {
- 'error.type': 'array',
- count: 'integer',
- },
- },
- },
- });
- }
- beforeEach(function () {
- mockQuery = {
- conditions: 'title:/organizations/:orgId/performance/summary/',
- fields: ['error.type', 'count()'],
- aggregates: ['count()'],
- columns: ['error.type'],
- id: '1',
- name: 'Query Name',
- orderby: '',
- };
- mockWidget = {
- title: 'Test Widget',
- displayType: DisplayType.TOP_N,
- interval: '5m',
- queries: [mockQuery],
- widgetType: WidgetType.DISCOVER,
- };
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- match: [MockApiClient.matchQuery({cursor: '0:10:0'})],
- headers: {
- Link:
- '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1",' +
- '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=0:20:0>; rel="next"; results="true"; cursor="0:20:0"',
- },
- body: {
- data: [
- {
- 'error.type': ['Next Page Test Error'],
- count: 1,
- },
- ],
- meta: {
- 'error.type': 'array',
- count: 'integer',
- },
- },
- });
- });
- describe('with eventsv2', function () {
- it('renders Discover topn chart widget viewer', async function () {
- mockEventsStats();
- mockEventsv2();
- const {container} = await renderModal({initialData, widget: mockWidget});
- expect(container).toSnapshot();
- });
- it('sorts table when a sortable column header is clicked', async function () {
- const eventsStatsMock = mockEventsStats();
- const eventsv2Mock = mockEventsv2();
- const {rerender} = await renderModal({initialData, widget: mockWidget});
- userEvent.click(screen.getByText('count()'));
- expect(initialData.router.push).toHaveBeenCalledWith({
- query: {sort: ['-count()']},
- });
- // Need to manually set the new router location and rerender to simulate the sortable column click
- initialData.router.location.query = {sort: ['-count()']};
- rerender(
- <WidgetViewerModal
- Header={stubEl}
- Footer={stubEl as ModalRenderProps['Footer']}
- Body={stubEl as ModalRenderProps['Body']}
- CloseButton={stubEl}
- closeModal={() => undefined}
- organization={initialData.organization}
- widget={mockWidget}
- onEdit={() => undefined}
- />
- );
- await waitForMetaToHaveBeenCalled();
- expect(eventsv2Mock).toHaveBeenCalledWith(
- '/organizations/org-slug/eventsv2/',
- expect.objectContaining({
- query: expect.objectContaining({sort: ['-count()']}),
- })
- );
- expect(eventsStatsMock).toHaveBeenCalledWith(
- '/organizations/org-slug/events-stats/',
- expect.objectContaining({
- query: expect.objectContaining({orderby: '-count()'}),
- })
- );
- });
- it('renders pagination buttons', async function () {
- mockEventsStats();
- mockEventsv2();
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByRole('button', {name: 'Previous'})).toBeInTheDocument();
- expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
- });
- it('does not render pagination buttons', async function () {
- mockEventsStats();
- mockEventsv2();
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- headers: {
- Link:
- '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1",' +
- '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=0:20:0>; rel="next"; results="false"; cursor="0:20:0"',
- },
- body: {
- data: [
- {
- 'error.type': ['No Pagination'],
- count: 1,
- },
- ],
- meta: {
- 'error.type': 'array',
- count: 'integer',
- },
- },
- });
- await renderModal({initialData, widget: mockWidget});
- expect(
- screen.queryByRole('button', {name: 'Previous'})
- ).not.toBeInTheDocument();
- expect(screen.queryByRole('button', {name: 'Next'})).not.toBeInTheDocument();
- });
- it('paginates to the next page', async function () {
- mockEventsStats();
- mockEventsv2();
- const {rerender} = await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('Test Error 1c')).toBeInTheDocument();
- userEvent.click(screen.getByRole('button', {name: 'Next'}));
- expect(initialData.router.replace).toHaveBeenCalledWith(
- expect.objectContaining({
- query: {cursor: '0:10:0'},
- })
- );
- // Need to manually set the new router location and rerender to simulate the next page click
- initialData.router.location.query = {cursor: ['0:10:0']};
- rerender(
- <WidgetViewerModal
- Header={stubEl}
- Footer={stubEl as ModalRenderProps['Footer']}
- Body={stubEl as ModalRenderProps['Body']}
- CloseButton={stubEl}
- closeModal={() => undefined}
- organization={initialData.organization}
- widget={mockWidget}
- onEdit={() => undefined}
- />
- );
- await waitForMetaToHaveBeenCalled();
- expect(await screen.findByText('Next Page Test Error')).toBeInTheDocument();
- });
- it('uses provided seriesData and does not make an events-stats requests', async function () {
- const eventsStatsMock = mockEventsStats();
- mockEventsv2();
- await renderModal({initialData, widget: mockWidget, seriesData: []});
- expect(eventsStatsMock).not.toHaveBeenCalled();
- });
- it('makes events-stats requests when table is sorted', async function () {
- const eventsStatsMock = mockEventsStats();
- mockEventsv2();
- await renderModal({
- initialData,
- widget: mockWidget,
- seriesData: [],
- });
- expect(eventsStatsMock).not.toHaveBeenCalled();
- userEvent.click(screen.getByText('count()'));
- await waitForMetaToHaveBeenCalled();
- expect(eventsStatsMock).toHaveBeenCalledTimes(1);
- });
- it('renders widget chart minimap', async function () {
- mockEventsStats();
- mockEventsv2();
- initialData.organization.features.push('widget-viewer-modal-minimap');
- await renderModal({initialData, widget: mockWidget});
- expect(ReactEchartsCore).toHaveBeenLastCalledWith(
- expect.objectContaining({
- option: expect.objectContaining({
- dataZoom: expect.arrayContaining([
- expect.objectContaining({
- realtime: false,
- showDetail: false,
- end: 100,
- start: 0,
- }),
- ]),
- }),
- }),
- {}
- );
- });
- it('zooming on minimap updates location query and updates echart start and end values', async function () {
- mockEventsStats();
- mockEventsv2();
- initialData.organization.features.push('widget-viewer-modal-minimap');
- await renderModal({initialData, widget: mockWidget});
- const calls = (ReactEchartsCore as jest.Mock).mock.calls;
- act(() => {
- // Simulate dataZoom event on chart
- calls[calls.length - 1][0].onEvents.datazoom(
- {seriesStart: 1646100000000, seriesEnd: 1646120000000},
- {
- getModel: () => {
- return {
- _payload: {start: 30, end: 70},
- };
- },
- }
- );
- });
- expect(initialData.router.push).toHaveBeenCalledWith(
- expect.objectContaining({
- query: {
- viewerEnd: '2022-03-01T05:53:20',
- viewerStart: '2022-03-01T03:40:00',
- },
- })
- );
- await waitFor(() => {
- expect(ReactEchartsCore).toHaveBeenLastCalledWith(
- expect.objectContaining({
- option: expect.objectContaining({
- dataZoom: expect.arrayContaining([
- expect.objectContaining({
- realtime: false,
- showDetail: false,
- endValue: 1646114000000,
- startValue: 1646106000000,
- }),
- ]),
- }),
- }),
- {}
- );
- });
- });
- });
- describe('with events', function () {
- it('sorts table when a sortable column header is clicked', async function () {
- const eventsStatsMock = mockEventsStats();
- const eventsMock = mockEvents();
- const {rerender} = await renderModal({
- initialData: initialDataWithFlag,
- widget: mockWidget,
- });
- userEvent.click(screen.getByText('count()'));
- expect(initialDataWithFlag.router.push).toHaveBeenCalledWith({
- query: {sort: ['-count()']},
- });
- // Need to manually set the new router location and rerender to simulate the sortable column click
- initialDataWithFlag.router.location.query = {sort: ['-count()']};
- rerender(
- <WidgetViewerModal
- Header={stubEl}
- Footer={stubEl as ModalRenderProps['Footer']}
- Body={stubEl as ModalRenderProps['Body']}
- CloseButton={stubEl}
- closeModal={() => undefined}
- organization={initialDataWithFlag.organization}
- widget={mockWidget}
- onEdit={() => undefined}
- />
- );
- await waitForMetaToHaveBeenCalled();
- expect(eventsMock).toHaveBeenCalledWith(
- '/organizations/org-slug/events/',
- expect.objectContaining({
- query: expect.objectContaining({sort: ['-count()']}),
- })
- );
- expect(eventsStatsMock).toHaveBeenCalledWith(
- '/organizations/org-slug/events-stats/',
- expect.objectContaining({
- query: expect.objectContaining({orderby: '-count()'}),
- })
- );
- });
- });
- });
- describe('World Map Chart Widget', function () {
- let mockQuery, mockWidget;
- const eventsMockData = [
- {
- 'geo.country_code': 'ES',
- p75_measurements_lcp: 2000,
- },
- {
- 'geo.country_code': 'SK',
- p75_measurements_lcp: 3000,
- },
- {
- 'geo.country_code': 'CO',
- p75_measurements_lcp: 4000,
- },
- ];
- function mockEventsGeo() {
- return MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-geo/',
- body: {
- data: eventsMockData,
- meta: {
- 'geo.country_code': 'string',
- p75_measurements_lcp: 'duration',
- },
- },
- });
- }
- function mockEventsv2() {
- return MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- data: eventsMockData,
- meta: {
- 'geo.country_code': 'string',
- p75_measurements_lcp: 'duration',
- },
- },
- });
- }
- function mockEvents() {
- return MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- body: {
- data: eventsMockData,
- meta: {
- fields: {
- 'geo.country_code': 'string',
- p75_measurements_lcp: 'duration',
- },
- },
- },
- });
- }
- beforeEach(function () {
- mockQuery = {
- conditions: 'title:/organizations/:orgId/performance/summary/',
- fields: ['p75(measurements.lcp)'],
- aggregates: ['p75(measurements.lcp)'],
- columns: [],
- id: '1',
- name: 'Query Name',
- orderby: '',
- };
- mockWidget = {
- title: 'Test Widget',
- displayType: DisplayType.WORLD_MAP,
- interval: '5m',
- queries: [mockQuery],
- widgetType: WidgetType.DISCOVER,
- };
- });
- describe('with eventsv2', function () {
- it('always queries geo.country_code in the table chart', async function () {
- const eventsv2Mock = mockEventsv2();
- mockEventsGeo();
- await renderModal({initialData, widget: mockWidget});
- expect(eventsv2Mock).toHaveBeenCalledWith(
- '/organizations/org-slug/eventsv2/',
- expect.objectContaining({
- query: expect.objectContaining({
- field: ['geo.country_code', 'p75(measurements.lcp)'],
- }),
- })
- );
- expect(await screen.findByText('geo.country_code')).toBeInTheDocument();
- });
- it('renders Discover topn chart widget viewer', async function () {
- mockEventsv2();
- mockEventsGeo();
- const {container} = await renderModal({initialData, widget: mockWidget});
- expect(container).toSnapshot();
- });
- it('uses provided tableData and does not make an eventsv2 requests', async function () {
- const eventsGeoMock = mockEventsGeo();
- mockEventsv2();
- await renderModal({initialData, widget: mockWidget, tableData: []});
- expect(eventsGeoMock).not.toHaveBeenCalled();
- });
- });
- describe('with events', function () {
- it('always queries geo.country_code in the table chart', async function () {
- const eventsMock = mockEvents();
- mockEventsGeo();
- await renderModal({initialData: initialDataWithFlag, widget: mockWidget});
- expect(eventsMock).toHaveBeenCalledWith(
- '/organizations/org-slug/events/',
- expect.objectContaining({
- query: expect.objectContaining({
- field: ['geo.country_code', 'p75(measurements.lcp)'],
- }),
- })
- );
- expect(await screen.findByText('geo.country_code')).toBeInTheDocument();
- });
- });
- });
- describe('Table Widget', function () {
- const mockQuery = {
- conditions: 'title:/organizations/:orgId/performance/summary/',
- fields: ['title', 'count()'],
- aggregates: ['count()'],
- columns: ['title'],
- id: '1',
- name: 'Query Name',
- orderby: '',
- };
- const mockWidget = {
- title: 'Test Widget',
- displayType: DisplayType.TABLE,
- interval: '5m',
- queries: [mockQuery],
- widgetType: WidgetType.DISCOVER,
- };
- function mockEventsv2() {
- return MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- data: [
- {
- title: '/organizations/:orgId/dashboards/',
- id: '1',
- count: 1,
- },
- ],
- meta: {
- title: 'string',
- id: 'string',
- count: 1,
- isMetricsData: false,
- },
- },
- });
- }
- function mockEvents() {
- return MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- body: {
- data: [
- {
- title: '/organizations/:orgId/dashboards/',
- id: '1',
- count: 1,
- },
- ],
- meta: {
- fields: {
- title: 'string',
- id: 'string',
- count: 1,
- },
- isMetricsData: false,
- },
- },
- });
- }
- describe('with eventsv2', function () {
- it('makes eventsv2 requests when table is paginated', async function () {
- const eventsv2Mock = mockEventsv2();
- await renderModal({
- initialData,
- widget: mockWidget,
- tableData: [],
- pageLinks:
- '<https://sentry.io>; rel="previous"; results="false"; cursor="0:0:1", <https://sentry.io>; rel="next"; results="true"; cursor="0:20:0"',
- });
- expect(eventsv2Mock).not.toHaveBeenCalled();
- userEvent.click(screen.getByLabelText('Next'));
- await waitFor(() => {
- expect(eventsv2Mock).toHaveBeenCalled();
- });
- });
- });
- describe('with events', function () {
- it('makes events requests when table is paginated', async function () {
- const eventsMock = mockEvents();
- await renderModal({
- initialData: initialDataWithFlag,
- widget: mockWidget,
- tableData: [],
- pageLinks:
- '<https://sentry.io>; rel="previous"; results="false"; cursor="0:0:1", <https://sentry.io>; rel="next"; results="true"; cursor="0:20:0"',
- });
- expect(eventsMock).not.toHaveBeenCalled();
- userEvent.click(screen.getByLabelText('Next'));
- await waitFor(() => {
- expect(eventsMock).toHaveBeenCalled();
- });
- });
- it('disables the Open in Discover button for a custom measurement widget', async function () {
- const customMeasurementWidget = {
- ...mockWidget,
- queries: [
- {
- conditions: '',
- fields: [],
- aggregates: ['p99(measurements.custom.measurement)'],
- columns: ['title'],
- id: '1',
- name: 'Query Name',
- orderby: '',
- },
- ],
- };
- await renderModal({
- initialData: initialDataWithFlag,
- widget: customMeasurementWidget,
- tableData: [],
- pageLinks:
- '<https://sentry.io>; rel="previous"; results="false"; cursor="0:0:1", <https://sentry.io>; rel="next"; results="true"; cursor="0:20:0"',
- });
- userEvent.click(screen.getByText('Open in Discover'));
- expect(initialData.router.push).not.toHaveBeenCalled();
- });
- it('displays table data with units correctly', async function () {
- const eventsMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- match: [MockApiClient.matchQuery({cursor: undefined})],
- headers: {
- Link:
- '<http://localhost/api/0/organizations/org-slug/events/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1",' +
- '<http://localhost/api/0/organizations/org-slug/events/?cursor=0:10:0>; rel="next"; results="true"; cursor="0:10:0"',
- },
- body: {
- data: [
- {
- 'p75(measurements.custom.minute)': 94.87035966318831,
- 'p95(measurements.custom.ratio)': 0.9881980140455187,
- 'p75(measurements.custom.kibibyte)': 217.87035966318834,
- },
- ],
- meta: {
- fields: {
- 'p75(measurements.custom.minute)': 'duration',
- 'p95(measurements.custom.ratio)': 'percentage',
- 'p75(measurements.custom.kibibyte)': 'size',
- },
- units: {
- 'p75(measurements.custom.minute)': 'minute',
- 'p95(measurements.custom.ratio)': null,
- 'p75(measurements.custom.kibibyte)': 'kibibyte',
- },
- isMetricsData: true,
- tips: {},
- },
- },
- });
- await renderModal({
- initialData: initialDataWithFlag,
- widget: {
- title: 'Custom Widget',
- displayType: 'table',
- queries: [
- {
- fields: [
- 'p75(measurements.custom.kibibyte)',
- 'p75(measurements.custom.minute)',
- 'p95(measurements.custom.ratio)',
- ],
- aggregates: [
- 'p75(measurements.custom.kibibyte)',
- 'p75(measurements.custom.minute)',
- 'p95(measurements.custom.ratio)',
- ],
- columns: [],
- orderby: '-p75(measurements.custom.kibibyte)',
- },
- ],
- widgetType: 'discover',
- },
- });
- await waitFor(() => {
- expect(eventsMock).toHaveBeenCalled();
- });
- expect(screen.getByText('217.9 KiB')).toBeInTheDocument();
- expect(screen.getByText('1.58hr')).toBeInTheDocument();
- expect(screen.getByText('98.82%')).toBeInTheDocument();
- });
- });
- });
- });
- describe('Issue Table Widget', function () {
- let issuesMock;
- const mockQuery = {
- conditions: 'is:unresolved',
- fields: ['events', 'status', 'title'],
- columns: ['events', 'status', 'title'],
- aggregates: [],
- id: '1',
- name: 'Query Name',
- orderby: '',
- };
- const mockWidget = {
- id: '1',
- title: 'Issue Widget',
- displayType: DisplayType.TABLE,
- interval: '5m',
- queries: [mockQuery],
- widgetType: WidgetType.ISSUE,
- };
- beforeEach(function () {
- MemberListStore.loadInitialData([]);
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- method: 'GET',
- match: [
- MockApiClient.matchData({
- cursor: '0:10:0',
- }),
- ],
- headers: {
- Link:
- '<http://localhost/api/0/organizations/org-slug/issues/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1",' +
- '<http://localhost/api/0/organizations/org-slug/issues/?cursor=0:20:0>; rel="next"; results="true"; cursor="0:20:0"',
- },
- body: [
- {
- id: '2',
- title: 'Another Error: Failed',
- project: {
- id: '3',
- },
- status: 'unresolved',
- lifetime: {count: 5},
- count: 3,
- userCount: 1,
- },
- ],
- });
- issuesMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- method: 'GET',
- match: [
- MockApiClient.matchData({
- cursor: undefined,
- }),
- ],
- headers: {
- Link:
- '<http://localhost/api/0/organizations/org-slug/issues/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1",' +
- '<http://localhost/api/0/organizations/org-slug/issues/?cursor=0:10:0>; rel="next"; results="true"; cursor="0:10:0"',
- },
- body: [
- {
- id: '1',
- title: 'Error: Failed',
- project: {
- id: '3',
- },
- status: 'unresolved',
- lifetime: {count: 10},
- count: 6,
- userCount: 3,
- },
- ],
- });
- });
- it('renders widget title', async function () {
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('Issue Widget')).toBeInTheDocument();
- });
- it('renders Edit and Open buttons', async function () {
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('Edit Widget')).toBeInTheDocument();
- expect(screen.getByText('Open in Issues')).toBeInTheDocument();
- });
- it('renders events, status, and title table columns', async function () {
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('title')).toBeInTheDocument();
- expect(await screen.findByText('Error: Failed')).toBeInTheDocument();
- expect(screen.getByText('events')).toBeInTheDocument();
- expect(screen.getByText('6')).toBeInTheDocument();
- expect(screen.getByText('status')).toBeInTheDocument();
- expect(screen.getByText('unresolved')).toBeInTheDocument();
- });
- it('renders Issue table widget viewer', async function () {
- const {container} = await renderModal({initialData, widget: mockWidget});
- await screen.findByText('Error: Failed');
- expect(container).toSnapshot();
- });
- it('redirects user to Issues when clicking Open in Issues', async function () {
- await renderModal({initialData, widget: mockWidget});
- userEvent.click(screen.getByText('Open in Issues'));
- expect(initialData.router.push).toHaveBeenCalledWith(
- '/organizations/org-slug/issues/?environment=prod&environment=dev&project=1&project=2&query=is%3Aunresolved&sort=&statsPeriod=24h'
- );
- });
- it('sorts table when a sortable column header is clicked', async function () {
- const {rerender} = await renderModal({initialData, widget: mockWidget});
- userEvent.click(screen.getByText('events'));
- expect(initialData.router.push).toHaveBeenCalledWith({
- query: {sort: 'freq'},
- });
- // Need to manually set the new router location and rerender to simulate the sortable column click
- initialData.router.location.query = {sort: ['freq']};
- rerender(
- <WidgetViewerModal
- Header={stubEl}
- Footer={stubEl as ModalRenderProps['Footer']}
- Body={stubEl as ModalRenderProps['Body']}
- CloseButton={stubEl}
- closeModal={() => undefined}
- organization={initialData.organization}
- widget={mockWidget}
- onEdit={() => undefined}
- />
- );
- expect(issuesMock).toHaveBeenCalledWith(
- '/organizations/org-slug/issues/',
- expect.objectContaining({
- data: {
- cursor: undefined,
- environment: ['prod', 'dev'],
- expand: ['owners'],
- limit: 20,
- project: [1, 2],
- query: 'is:unresolved',
- sort: 'date',
- statsPeriod: '24h',
- },
- })
- );
- });
- it('renders pagination buttons', async function () {
- await renderModal({initialData, widget: mockWidget});
- expect(await screen.findByRole('button', {name: 'Previous'})).toBeInTheDocument();
- expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
- });
- it('paginates to the next page', async function () {
- const {rerender} = await renderModal({initialData, widget: mockWidget});
- expect(await screen.findByText('Error: Failed')).toBeInTheDocument();
- userEvent.click(screen.getByRole('button', {name: 'Next'}));
- expect(issuesMock).toHaveBeenCalledTimes(1);
- expect(initialData.router.replace).toHaveBeenCalledWith(
- expect.objectContaining({
- query: {cursor: '0:10:0', page: 1},
- })
- );
- // Need to manually set the new router location and rerender to simulate the next page click
- initialData.router.location.query = {cursor: ['0:10:0']};
- rerender(
- <WidgetViewerModal
- Header={stubEl}
- Footer={stubEl as ModalRenderProps['Footer']}
- Body={stubEl as ModalRenderProps['Body']}
- CloseButton={stubEl}
- closeModal={() => undefined}
- organization={initialData.organization}
- widget={mockWidget}
- onEdit={() => undefined}
- />
- );
- expect(await screen.findByText('Another Error: Failed')).toBeInTheDocument();
- });
- it('displays with correct table column widths', async function () {
- initialData.router.location.query = {width: ['-1', '-1', '575']};
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByTestId('grid-editable')).toHaveStyle({
- 'grid-template-columns':
- ' minmax(90px, auto) minmax(90px, auto) minmax(575px, auto)',
- });
- });
- it('uses provided tableData and does not make an issues requests', async function () {
- await renderModal({initialData, widget: mockWidget, tableData: []});
- expect(issuesMock).not.toHaveBeenCalled();
- });
- it('makes issues requests when table is sorted', async function () {
- await renderModal({
- initialData,
- widget: mockWidget,
- tableData: [],
- });
- expect(issuesMock).not.toHaveBeenCalled();
- userEvent.click(screen.getByText('events'));
- await waitFor(() => {
- expect(issuesMock).toHaveBeenCalled();
- });
- });
- });
- describe('Release Health Widgets', function () {
- let metricsMock;
- const mockQuery = {
- conditions: '',
- fields: [`sum(session)`],
- columns: [],
- aggregates: [],
- id: '1',
- name: 'Query Name',
- orderby: '',
- };
- const mockWidget = {
- id: '1',
- title: 'Release Widget',
- displayType: DisplayType.LINE,
- interval: '5m',
- queries: [mockQuery],
- widgetType: WidgetType.RELEASE,
- };
- beforeEach(function () {
- metricsMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/metrics/data/',
- body: TestStubs.MetricsTotalCountByReleaseIn24h(),
- headers: {
- link:
- '<http://localhost/api/0/organizations/org-slug/metrics/data/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1",' +
- '<http://localhost/api/0/organizations/org-slug/metrics/data/?cursor=0:10:0>; rel="next"; results="true"; cursor="0:10:0"',
- },
- });
- });
- it('does a sessions query', async function () {
- jest.useFakeTimers().setSystemTime(new Date('2022-08-02'));
- await renderModal({initialData, widget: mockWidget});
- expect(metricsMock).toHaveBeenCalled();
- });
- it('renders widget title', async function () {
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('Release Widget')).toBeInTheDocument();
- });
- it('renders Edit and Open in Releases buttons', async function () {
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('Edit Widget')).toBeInTheDocument();
- expect(screen.getByText('Open in Releases')).toBeInTheDocument();
- });
- it('Open in Releases button redirects browser', async function () {
- await renderModal({initialData, widget: mockWidget});
- userEvent.click(screen.getByText('Open in Releases'));
- expect(initialData.router.push).toHaveBeenCalledWith(
- '/organizations/org-slug/releases/?environment=prod&environment=dev&project=1&project=2&statsPeriod=24h'
- );
- });
- it('renders table header and body', async function () {
- await renderModal({initialData, widget: mockWidget});
- expect(screen.getByText('release')).toBeInTheDocument();
- expect(await screen.findByText('e102abb2c46e')).toBeInTheDocument();
- expect(screen.getByText('sum(session)')).toBeInTheDocument();
- expect(screen.getByText('6.3k')).toBeInTheDocument();
- });
- it('renders Release widget viewer', async function () {
- const {container} = await renderModal({initialData, widget: mockWidget});
- expect(await screen.findByText('e102abb2c46e')).toBeInTheDocument();
- expect(container).toSnapshot();
- });
- it('renders pagination buttons', async function () {
- await renderModal({
- initialData,
- widget: mockWidget,
- });
- expect(await screen.findByRole('button', {name: 'Previous'})).toBeInTheDocument();
- expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
- });
- it('does not render pagination buttons when sorting by release', async function () {
- await renderModal({
- initialData,
- widget: {...mockWidget, queries: [{...mockQuery, orderby: 'release'}]},
- });
- expect(screen.queryByRole('button', {name: 'Previous'})).not.toBeInTheDocument();
- expect(screen.queryByRole('button', {name: 'Next'})).not.toBeInTheDocument();
- });
- it('makes a new sessions request after sorting by a table column', async function () {
- const {rerender} = await renderModal({
- initialData,
- widget: mockWidget,
- tableData: [],
- seriesData: [],
- });
- expect(metricsMock).toHaveBeenCalledTimes(1);
- userEvent.click(screen.getByText(`sum(session)`));
- expect(initialData.router.push).toHaveBeenCalledWith({
- query: {sort: '-sum(session)'},
- });
- // Need to manually set the new router location and rerender to simulate the sortable column click
- initialData.router.location.query = {sort: '-sum(session)'};
- rerender(
- <WidgetViewerModal
- Header={stubEl}
- Footer={stubEl as ModalRenderProps['Footer']}
- Body={stubEl as ModalRenderProps['Body']}
- CloseButton={stubEl}
- closeModal={() => undefined}
- organization={initialData.organization}
- widget={mockWidget}
- onEdit={() => undefined}
- seriesData={[]}
- tableData={[]}
- />
- );
- await waitFor(() => {
- expect(metricsMock).toHaveBeenCalledTimes(2);
- });
- });
- });
- });
|