index.spec.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {
  5. render,
  6. renderGlobalModal,
  7. screen,
  8. userEvent,
  9. waitFor,
  10. } from 'sentry-test/reactTestingLibrary';
  11. import * as modal from 'sentry/actionCreators/modal';
  12. import * as LineChart from 'sentry/components/charts/lineChart';
  13. import SimpleTableChart from 'sentry/components/charts/simpleTableChart';
  14. import {MINUTE, SECOND} from 'sentry/utils/formatters';
  15. import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  16. import type {Widget} from 'sentry/views/dashboards/types';
  17. import {DisplayType, WidgetType} from 'sentry/views/dashboards/types';
  18. import WidgetCard from 'sentry/views/dashboards/widgetCard';
  19. import ReleaseWidgetQueries from 'sentry/views/dashboards/widgetCard/releaseWidgetQueries';
  20. jest.mock('sentry/components/charts/simpleTableChart', () => jest.fn(() => <div />));
  21. jest.mock('sentry/views/dashboards/widgetCard/releaseWidgetQueries');
  22. describe('Dashboards > WidgetCard', function () {
  23. const {router, organization, routerContext} = initializeOrg({
  24. organization: OrganizationFixture({
  25. features: ['dashboards-edit', 'discover-basic'],
  26. projects: [ProjectFixture()],
  27. }),
  28. router: {orgId: 'orgId'},
  29. } as Parameters<typeof initializeOrg>[0]);
  30. const renderWithProviders = (component: React.ReactNode) =>
  31. render(
  32. <MEPSettingProvider forceTransactions={false}>{component}</MEPSettingProvider>,
  33. {organization, router, context: routerContext}
  34. );
  35. const multipleQueryWidget: Widget = {
  36. title: 'Errors',
  37. description: 'Valid widget description',
  38. interval: '5m',
  39. displayType: DisplayType.LINE,
  40. widgetType: WidgetType.DISCOVER,
  41. queries: [
  42. {
  43. conditions: 'event.type:error',
  44. fields: ['count()', 'failure_count()'],
  45. aggregates: ['count()', 'failure_count()'],
  46. columns: [],
  47. name: 'errors',
  48. orderby: '',
  49. },
  50. {
  51. conditions: 'event.type:default',
  52. fields: ['count()', 'failure_count()'],
  53. aggregates: ['count()', 'failure_count()'],
  54. columns: [],
  55. name: 'default',
  56. orderby: '',
  57. },
  58. ],
  59. };
  60. const selection = {
  61. projects: [1],
  62. environments: ['prod'],
  63. datetime: {
  64. period: '14d',
  65. start: null,
  66. end: null,
  67. utc: false,
  68. },
  69. };
  70. const api = new MockApiClient();
  71. let eventsMock;
  72. beforeEach(function () {
  73. MockApiClient.addMockResponse({
  74. url: '/organizations/org-slug/events-stats/',
  75. body: {meta: {isMetricsData: false}},
  76. });
  77. eventsMock = MockApiClient.addMockResponse({
  78. url: '/organizations/org-slug/events/',
  79. body: {
  80. meta: {fields: {title: 'string'}},
  81. data: [{title: 'title'}],
  82. },
  83. });
  84. });
  85. afterEach(function () {
  86. MockApiClient.clearMockResponses();
  87. });
  88. it('renders with Open in Discover button and opens the Query Selector Modal when clicked', async function () {
  89. const spy = jest.spyOn(modal, 'openDashboardWidgetQuerySelectorModal');
  90. renderWithProviders(
  91. <WidgetCard
  92. api={api}
  93. widget={multipleQueryWidget}
  94. selection={selection}
  95. isEditingDashboard={false}
  96. onDelete={() => undefined}
  97. onEdit={() => undefined}
  98. onDuplicate={() => undefined}
  99. renderErrorMessage={() => undefined}
  100. showContextMenu
  101. widgetLimitReached={false}
  102. />
  103. );
  104. await userEvent.click(await screen.findByLabelText('Widget actions'));
  105. expect(screen.getByText('Open in Discover')).toBeInTheDocument();
  106. await userEvent.click(screen.getByText('Open in Discover'));
  107. expect(spy).toHaveBeenCalledWith({
  108. isMetricsData: false,
  109. organization,
  110. widget: multipleQueryWidget,
  111. });
  112. });
  113. it('renders with Open in Discover button and opens in Discover when clicked', async function () {
  114. renderWithProviders(
  115. <WidgetCard
  116. api={api}
  117. widget={{...multipleQueryWidget, queries: [multipleQueryWidget.queries[0]]}}
  118. selection={selection}
  119. isEditingDashboard={false}
  120. onDelete={() => undefined}
  121. onEdit={() => undefined}
  122. onDuplicate={() => undefined}
  123. renderErrorMessage={() => undefined}
  124. showContextMenu
  125. widgetLimitReached={false}
  126. />
  127. );
  128. await userEvent.click(await screen.findByLabelText('Widget actions'));
  129. expect(screen.getByText('Open in Discover')).toBeInTheDocument();
  130. await userEvent.click(screen.getByText('Open in Discover'));
  131. expect(router.push).toHaveBeenCalledWith(
  132. '/organizations/org-slug/discover/results/?environment=prod&field=count%28%29&field=failure_count%28%29&name=Errors&project=1&query=event.type%3Aerror&statsPeriod=14d&yAxis=count%28%29&yAxis=failure_count%28%29'
  133. );
  134. });
  135. it('renders widget description in dashboard', async function () {
  136. renderWithProviders(
  137. <WidgetCard
  138. api={api}
  139. widget={multipleQueryWidget}
  140. selection={selection}
  141. isEditingDashboard={false}
  142. onDelete={() => undefined}
  143. onEdit={() => undefined}
  144. onDuplicate={() => undefined}
  145. renderErrorMessage={() => undefined}
  146. showContextMenu
  147. widgetLimitReached={false}
  148. />
  149. );
  150. expect(await screen.findByText('Valid widget description')).toBeInTheDocument();
  151. });
  152. it('Opens in Discover with prepended fields pulled from equations', async function () {
  153. renderWithProviders(
  154. <WidgetCard
  155. api={api}
  156. widget={{
  157. ...multipleQueryWidget,
  158. queries: [
  159. {
  160. ...multipleQueryWidget.queries[0],
  161. fields: [
  162. 'equation|(count() + failure_count()) / count_if(transaction.duration,equals,300)',
  163. ],
  164. columns: [],
  165. aggregates: [
  166. 'equation|(count() + failure_count()) / count_if(transaction.duration,equals,300)',
  167. ],
  168. },
  169. ],
  170. }}
  171. selection={selection}
  172. isEditingDashboard={false}
  173. onDelete={() => undefined}
  174. onEdit={() => undefined}
  175. onDuplicate={() => undefined}
  176. renderErrorMessage={() => undefined}
  177. showContextMenu
  178. widgetLimitReached={false}
  179. />
  180. );
  181. await userEvent.click(await screen.findByLabelText('Widget actions'));
  182. expect(screen.getByText('Open in Discover')).toBeInTheDocument();
  183. await userEvent.click(screen.getByText('Open in Discover'));
  184. expect(router.push).toHaveBeenCalledWith(
  185. '/organizations/org-slug/discover/results/?environment=prod&field=count_if%28transaction.duration%2Cequals%2C300%29&field=failure_count%28%29&field=count%28%29&field=equation%7C%28count%28%29%20%2B%20failure_count%28%29%29%20%2F%20count_if%28transaction.duration%2Cequals%2C300%29&name=Errors&project=1&query=event.type%3Aerror&statsPeriod=14d&yAxis=equation%7C%28count%28%29%20%2B%20failure_count%28%29%29%20%2F%20count_if%28transaction.duration%2Cequals%2C300%29'
  186. );
  187. });
  188. it('Opens in Discover with Top N', async function () {
  189. renderWithProviders(
  190. <WidgetCard
  191. api={api}
  192. widget={{
  193. ...multipleQueryWidget,
  194. displayType: DisplayType.TOP_N,
  195. queries: [
  196. {
  197. ...multipleQueryWidget.queries[0],
  198. fields: ['transaction', 'count()'],
  199. columns: ['transaction'],
  200. aggregates: ['count()'],
  201. },
  202. ],
  203. }}
  204. selection={selection}
  205. isEditingDashboard={false}
  206. onDelete={() => undefined}
  207. onEdit={() => undefined}
  208. onDuplicate={() => undefined}
  209. renderErrorMessage={() => undefined}
  210. showContextMenu
  211. widgetLimitReached={false}
  212. />
  213. );
  214. await userEvent.click(await screen.findByLabelText('Widget actions'));
  215. expect(screen.getByText('Open in Discover')).toBeInTheDocument();
  216. await userEvent.click(screen.getByText('Open in Discover'));
  217. expect(router.push).toHaveBeenCalledWith(
  218. '/organizations/org-slug/discover/results/?display=top5&environment=prod&field=transaction&field=count%28%29&name=Errors&project=1&query=event.type%3Aerror&statsPeriod=14d&yAxis=count%28%29'
  219. );
  220. });
  221. it('allows Open in Discover when the widget contains custom measurements', async function () {
  222. renderWithProviders(
  223. <WidgetCard
  224. api={api}
  225. widget={{
  226. ...multipleQueryWidget,
  227. displayType: DisplayType.LINE,
  228. queries: [
  229. {
  230. ...multipleQueryWidget.queries[0],
  231. conditions: '',
  232. fields: [],
  233. columns: [],
  234. aggregates: ['p99(measurements.custom.measurement)'],
  235. },
  236. ],
  237. }}
  238. selection={selection}
  239. isEditingDashboard={false}
  240. onDelete={() => undefined}
  241. onEdit={() => undefined}
  242. onDuplicate={() => undefined}
  243. renderErrorMessage={() => undefined}
  244. showContextMenu
  245. widgetLimitReached={false}
  246. />
  247. );
  248. await userEvent.click(await screen.findByLabelText('Widget actions'));
  249. expect(screen.getByText('Open in Discover')).toBeInTheDocument();
  250. await userEvent.click(screen.getByText('Open in Discover'));
  251. expect(router.push).toHaveBeenCalledWith(
  252. '/organizations/org-slug/discover/results/?environment=prod&field=p99%28measurements.custom.measurement%29&name=Errors&project=1&query=&statsPeriod=14d&yAxis=p99%28measurements.custom.measurement%29'
  253. );
  254. });
  255. it('calls onDuplicate when Duplicate Widget is clicked', async function () {
  256. const mock = jest.fn();
  257. renderWithProviders(
  258. <WidgetCard
  259. api={api}
  260. widget={{
  261. ...multipleQueryWidget,
  262. displayType: DisplayType.AREA,
  263. queries: [{...multipleQueryWidget.queries[0], fields: ['count()']}],
  264. }}
  265. selection={selection}
  266. isEditingDashboard={false}
  267. onDelete={() => undefined}
  268. onEdit={() => undefined}
  269. onDuplicate={mock}
  270. renderErrorMessage={() => undefined}
  271. showContextMenu
  272. widgetLimitReached={false}
  273. />
  274. );
  275. await userEvent.click(await screen.findByLabelText('Widget actions'));
  276. expect(screen.getByText('Duplicate Widget')).toBeInTheDocument();
  277. await userEvent.click(screen.getByText('Duplicate Widget'));
  278. expect(mock).toHaveBeenCalledTimes(1);
  279. });
  280. it('does not add duplicate widgets if max widget is reached', async function () {
  281. const mock = jest.fn();
  282. renderWithProviders(
  283. <WidgetCard
  284. api={api}
  285. widget={{
  286. ...multipleQueryWidget,
  287. displayType: DisplayType.AREA,
  288. queries: [{...multipleQueryWidget.queries[0], fields: ['count()']}],
  289. }}
  290. selection={selection}
  291. isEditingDashboard={false}
  292. onDelete={() => undefined}
  293. onEdit={() => undefined}
  294. onDuplicate={mock}
  295. renderErrorMessage={() => undefined}
  296. showContextMenu
  297. widgetLimitReached
  298. />
  299. );
  300. await userEvent.click(await screen.findByLabelText('Widget actions'));
  301. expect(screen.getByText('Duplicate Widget')).toBeInTheDocument();
  302. await userEvent.click(screen.getByText('Duplicate Widget'));
  303. expect(mock).toHaveBeenCalledTimes(0);
  304. });
  305. it('calls onEdit when Edit Widget is clicked', async function () {
  306. const mock = jest.fn();
  307. renderWithProviders(
  308. <WidgetCard
  309. api={api}
  310. widget={{
  311. ...multipleQueryWidget,
  312. displayType: DisplayType.AREA,
  313. queries: [{...multipleQueryWidget.queries[0], fields: ['count()']}],
  314. }}
  315. selection={selection}
  316. isEditingDashboard={false}
  317. onDelete={() => undefined}
  318. onEdit={mock}
  319. onDuplicate={() => undefined}
  320. renderErrorMessage={() => undefined}
  321. showContextMenu
  322. widgetLimitReached={false}
  323. />
  324. );
  325. await userEvent.click(await screen.findByLabelText('Widget actions'));
  326. expect(screen.getByText('Edit Widget')).toBeInTheDocument();
  327. await userEvent.click(screen.getByText('Edit Widget'));
  328. expect(mock).toHaveBeenCalledTimes(1);
  329. });
  330. it('renders delete widget option', async function () {
  331. const mock = jest.fn();
  332. renderWithProviders(
  333. <WidgetCard
  334. api={api}
  335. widget={{
  336. ...multipleQueryWidget,
  337. displayType: DisplayType.AREA,
  338. queries: [{...multipleQueryWidget.queries[0], fields: ['count()']}],
  339. }}
  340. selection={selection}
  341. isEditingDashboard={false}
  342. onDelete={mock}
  343. onEdit={() => undefined}
  344. onDuplicate={() => undefined}
  345. renderErrorMessage={() => undefined}
  346. showContextMenu
  347. widgetLimitReached={false}
  348. />
  349. );
  350. await userEvent.click(await screen.findByLabelText('Widget actions'));
  351. expect(screen.getByText('Delete Widget')).toBeInTheDocument();
  352. await userEvent.click(screen.getByText('Delete Widget'));
  353. // Confirm Modal
  354. renderGlobalModal();
  355. await screen.findByRole('dialog');
  356. await userEvent.click(screen.getByTestId('confirm-button'));
  357. expect(mock).toHaveBeenCalled();
  358. });
  359. it('calls events with a limit of 20 items', async function () {
  360. const mock = jest.fn();
  361. renderWithProviders(
  362. <WidgetCard
  363. api={api}
  364. widget={{
  365. ...multipleQueryWidget,
  366. displayType: DisplayType.TABLE,
  367. queries: [{...multipleQueryWidget.queries[0], fields: ['count()']}],
  368. }}
  369. selection={selection}
  370. isEditingDashboard={false}
  371. onDelete={mock}
  372. onEdit={() => undefined}
  373. onDuplicate={() => undefined}
  374. renderErrorMessage={() => undefined}
  375. showContextMenu
  376. widgetLimitReached={false}
  377. tableItemLimit={20}
  378. />
  379. );
  380. await waitFor(() => {
  381. expect(eventsMock).toHaveBeenCalledWith(
  382. '/organizations/org-slug/events/',
  383. expect.objectContaining({
  384. query: expect.objectContaining({
  385. per_page: 20,
  386. }),
  387. })
  388. );
  389. });
  390. });
  391. it('calls events with a default limit of 5 items', async function () {
  392. const mock = jest.fn();
  393. renderWithProviders(
  394. <WidgetCard
  395. api={api}
  396. widget={{
  397. ...multipleQueryWidget,
  398. displayType: DisplayType.TABLE,
  399. queries: [{...multipleQueryWidget.queries[0], fields: ['count()']}],
  400. }}
  401. selection={selection}
  402. isEditingDashboard={false}
  403. onDelete={mock}
  404. onEdit={() => undefined}
  405. onDuplicate={() => undefined}
  406. renderErrorMessage={() => undefined}
  407. showContextMenu
  408. widgetLimitReached={false}
  409. />
  410. );
  411. await waitFor(() => {
  412. expect(eventsMock).toHaveBeenCalledWith(
  413. '/organizations/org-slug/events/',
  414. expect.objectContaining({
  415. query: expect.objectContaining({
  416. per_page: 5,
  417. }),
  418. })
  419. );
  420. });
  421. });
  422. it('has sticky table headers', async function () {
  423. const tableWidget: Widget = {
  424. title: 'Table Widget',
  425. interval: '5m',
  426. displayType: DisplayType.TABLE,
  427. widgetType: WidgetType.DISCOVER,
  428. queries: [
  429. {
  430. conditions: '',
  431. fields: ['transaction', 'count()'],
  432. columns: ['transaction'],
  433. aggregates: ['count()'],
  434. name: 'Table',
  435. orderby: '',
  436. },
  437. ],
  438. };
  439. renderWithProviders(
  440. <WidgetCard
  441. api={api}
  442. widget={tableWidget}
  443. selection={selection}
  444. isEditingDashboard={false}
  445. onDelete={() => undefined}
  446. onEdit={() => undefined}
  447. onDuplicate={() => undefined}
  448. renderErrorMessage={() => undefined}
  449. showContextMenu
  450. widgetLimitReached={false}
  451. tableItemLimit={20}
  452. />
  453. );
  454. await waitFor(() => expect(eventsMock).toHaveBeenCalled());
  455. expect(SimpleTableChart).toHaveBeenCalledWith(
  456. expect.objectContaining({stickyHeaders: true}),
  457. expect.anything()
  458. );
  459. });
  460. it('calls release queries', function () {
  461. const widget: Widget = {
  462. title: 'Release Widget',
  463. interval: '5m',
  464. displayType: DisplayType.LINE,
  465. widgetType: WidgetType.RELEASE,
  466. queries: [],
  467. };
  468. renderWithProviders(
  469. <WidgetCard
  470. api={api}
  471. widget={widget}
  472. selection={selection}
  473. isEditingDashboard={false}
  474. onDelete={() => undefined}
  475. onEdit={() => undefined}
  476. onDuplicate={() => undefined}
  477. renderErrorMessage={() => undefined}
  478. showContextMenu
  479. widgetLimitReached={false}
  480. tableItemLimit={20}
  481. />
  482. );
  483. expect(ReleaseWidgetQueries).toHaveBeenCalledTimes(1);
  484. });
  485. it('opens the widget viewer modal when a widget has no id', async () => {
  486. const widget: Widget = {
  487. title: 'Widget',
  488. interval: '5m',
  489. displayType: DisplayType.LINE,
  490. widgetType: WidgetType.DISCOVER,
  491. queries: [],
  492. };
  493. renderWithProviders(
  494. <WidgetCard
  495. api={api}
  496. widget={widget}
  497. selection={selection}
  498. isEditingDashboard={false}
  499. onDelete={() => undefined}
  500. onEdit={() => undefined}
  501. onDuplicate={() => undefined}
  502. renderErrorMessage={() => undefined}
  503. showContextMenu
  504. widgetLimitReached={false}
  505. index="10"
  506. isPreview
  507. />
  508. );
  509. await userEvent.click(await screen.findByLabelText('Open Widget Viewer'));
  510. expect(router.push).toHaveBeenCalledWith(
  511. expect.objectContaining({pathname: '/mock-pathname/widget/10/'})
  512. );
  513. });
  514. it('renders stored data disclaimer', async function () {
  515. MockApiClient.addMockResponse({
  516. url: '/organizations/org-slug/events/',
  517. body: {
  518. meta: {title: 'string', isMetricsData: false},
  519. data: [{title: 'title'}],
  520. },
  521. });
  522. renderWithProviders(
  523. <WidgetCard
  524. api={api}
  525. organization={{
  526. ...organization,
  527. features: [...organization.features, 'dashboards-mep'],
  528. }}
  529. widget={{
  530. ...multipleQueryWidget,
  531. displayType: DisplayType.TABLE,
  532. queries: [{...multipleQueryWidget.queries[0]}],
  533. }}
  534. selection={selection}
  535. isEditingDashboard={false}
  536. onDelete={() => undefined}
  537. onEdit={() => undefined}
  538. onDuplicate={() => undefined}
  539. renderErrorMessage={() => undefined}
  540. showContextMenu
  541. widgetLimitReached={false}
  542. showStoredAlert
  543. />
  544. );
  545. // Badge in the widget header
  546. expect(await screen.findByText('Indexed')).toBeInTheDocument();
  547. expect(
  548. // Alert below the widget
  549. await screen.findByText(/we've automatically adjusted your results/i)
  550. ).toBeInTheDocument();
  551. });
  552. it('renders chart using axis and tooltip formatters from custom measurement meta', async function () {
  553. const spy = jest.spyOn(LineChart, 'LineChart');
  554. const eventsStatsMock = MockApiClient.addMockResponse({
  555. url: '/organizations/org-slug/events-stats/',
  556. body: {
  557. data: [
  558. [
  559. 1658262600,
  560. [
  561. {
  562. count: 24,
  563. },
  564. ],
  565. ],
  566. ],
  567. meta: {
  568. fields: {
  569. time: 'date',
  570. p95_measurements_custom: 'duration',
  571. },
  572. units: {
  573. time: null,
  574. p95_measurements_custom: 'millisecond',
  575. },
  576. isMetricsData: true,
  577. tips: {},
  578. },
  579. },
  580. });
  581. renderWithProviders(
  582. <WidgetCard
  583. api={api}
  584. organization={organization}
  585. widget={{
  586. title: '',
  587. interval: '5m',
  588. widgetType: WidgetType.DISCOVER,
  589. displayType: DisplayType.LINE,
  590. queries: [
  591. {
  592. conditions: '',
  593. name: '',
  594. fields: [],
  595. columns: [],
  596. aggregates: ['p95(measurements.custom)'],
  597. orderby: '',
  598. },
  599. ],
  600. }}
  601. selection={selection}
  602. isEditingDashboard={false}
  603. onDelete={() => undefined}
  604. onEdit={() => undefined}
  605. onDuplicate={() => undefined}
  606. renderErrorMessage={() => undefined}
  607. showContextMenu
  608. widgetLimitReached={false}
  609. />
  610. );
  611. await waitFor(function () {
  612. expect(eventsStatsMock).toHaveBeenCalled();
  613. });
  614. const {tooltip, yAxis} = spy.mock.calls.pop()?.[0] ?? {};
  615. expect(tooltip).toBeDefined();
  616. expect(yAxis).toBeDefined();
  617. // @ts-expect-error
  618. expect(yAxis.axisLabel.formatter(24, 'p95(measurements.custom)')).toEqual('24ms');
  619. });
  620. it('renders label in seconds when there is a transition from seconds to minutes in the y axis', async function () {
  621. const spy = jest.spyOn(LineChart, 'LineChart');
  622. const eventsStatsMock = MockApiClient.addMockResponse({
  623. url: '/organizations/org-slug/events-stats/',
  624. body: {
  625. data: [
  626. [
  627. 1658262600,
  628. [
  629. {
  630. count: 40 * SECOND,
  631. },
  632. ],
  633. ],
  634. [
  635. 1658262601,
  636. [
  637. {
  638. count: 50 * SECOND,
  639. },
  640. ],
  641. ],
  642. [
  643. 1658262602,
  644. [
  645. {
  646. count: MINUTE,
  647. },
  648. ],
  649. ],
  650. [
  651. 1658262603,
  652. [
  653. {
  654. count: 1.3 * MINUTE,
  655. },
  656. ],
  657. ],
  658. ],
  659. meta: {
  660. fields: {
  661. time: 'date',
  662. p50_transaction_duration: 'duration',
  663. },
  664. units: {
  665. time: null,
  666. p50_transaction_duration: 'millisecond',
  667. },
  668. isMetricsData: false,
  669. tips: {},
  670. },
  671. },
  672. });
  673. renderWithProviders(
  674. <WidgetCard
  675. api={api}
  676. organization={organization}
  677. widget={{
  678. title: '',
  679. interval: '5m',
  680. widgetType: WidgetType.DISCOVER,
  681. displayType: DisplayType.LINE,
  682. queries: [
  683. {
  684. conditions: '',
  685. name: '',
  686. fields: [],
  687. columns: [],
  688. aggregates: ['p50(transaction.duration)'],
  689. orderby: '',
  690. },
  691. ],
  692. }}
  693. selection={selection}
  694. isEditingDashboard={false}
  695. onDelete={() => undefined}
  696. onEdit={() => undefined}
  697. onDuplicate={() => undefined}
  698. renderErrorMessage={() => undefined}
  699. showContextMenu
  700. widgetLimitReached={false}
  701. />
  702. );
  703. await waitFor(function () {
  704. expect(eventsStatsMock).toHaveBeenCalled();
  705. });
  706. const {yAxis} = spy.mock.calls.pop()?.[0] ?? {};
  707. expect(yAxis).toBeDefined();
  708. // @ts-expect-error
  709. expect(yAxis.axisLabel.formatter(60000, 'p50(transaction.duration)')).toEqual('60s');
  710. expect((yAxis as any).minInterval).toEqual(SECOND);
  711. });
  712. it('displays indexed badge in preview mode', async function () {
  713. renderWithProviders(
  714. <WidgetCard
  715. api={api}
  716. organization={{
  717. ...organization,
  718. features: [...organization.features, 'dashboards-mep'],
  719. }}
  720. widget={multipleQueryWidget}
  721. selection={selection}
  722. isEditingDashboard={false}
  723. onDelete={() => undefined}
  724. onEdit={() => undefined}
  725. onDuplicate={() => undefined}
  726. renderErrorMessage={() => undefined}
  727. showContextMenu
  728. widgetLimitReached={false}
  729. isPreview
  730. />
  731. );
  732. expect(await screen.findByText('Indexed')).toBeInTheDocument();
  733. });
  734. });