visualize.spec.tsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {RouterFixture} from 'sentry-fixture/routerFixture';
  4. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  5. import type {TagCollection} from 'sentry/types/group';
  6. import useCustomMeasurements from 'sentry/utils/useCustomMeasurements';
  7. import {useNavigate} from 'sentry/utils/useNavigate';
  8. import {DisplayType, WidgetType} from 'sentry/views/dashboards/types';
  9. import Visualize from 'sentry/views/dashboards/widgetBuilder/components/visualize';
  10. import {WidgetBuilderProvider} from 'sentry/views/dashboards/widgetBuilder/contexts/widgetBuilderContext';
  11. import {useSpanTags} from 'sentry/views/explore/contexts/spanTagsContext';
  12. jest.mock('sentry/utils/useCustomMeasurements');
  13. jest.mock('sentry/views/explore/contexts/spanTagsContext');
  14. jest.mock('sentry/utils/useNavigate');
  15. describe('Visualize', () => {
  16. let organization!: ReturnType<typeof OrganizationFixture>;
  17. let mockNavigate!: jest.Mock;
  18. beforeEach(() => {
  19. organization = OrganizationFixture({
  20. features: ['dashboards-widget-builder-redesign', 'performance-view'],
  21. });
  22. jest.mocked(useCustomMeasurements).mockReturnValue({
  23. customMeasurements: {},
  24. });
  25. jest.mocked(useSpanTags).mockReturnValue({});
  26. mockNavigate = jest.fn();
  27. jest.mocked(useNavigate).mockReturnValue(mockNavigate);
  28. });
  29. it('renders basic aggregates correctly from the URL params', async () => {
  30. render(
  31. <WidgetBuilderProvider>
  32. <Visualize />
  33. </WidgetBuilderProvider>,
  34. {
  35. organization,
  36. router: RouterFixture({
  37. location: LocationFixture({
  38. query: {
  39. yAxis: ['p90(transaction.duration)', 'max(spans.db)'],
  40. dataset: WidgetType.TRANSACTIONS,
  41. displayType: DisplayType.LINE,
  42. },
  43. }),
  44. }),
  45. }
  46. );
  47. expect(await screen.findByText('+ Add Series')).toBeInTheDocument();
  48. const p90FieldRow = (await screen.findByText('p90')).closest(
  49. '[data-testid="field-bar"]'
  50. ) as HTMLElement;
  51. expect(p90FieldRow).toBeInTheDocument();
  52. expect(within(p90FieldRow).getByText('transaction.duration')).toBeInTheDocument();
  53. const maxFieldRow = (await screen.findByText('max')).closest(
  54. '[data-testid="field-bar"]'
  55. ) as HTMLElement;
  56. expect(maxFieldRow).toBeInTheDocument();
  57. expect(within(maxFieldRow).getByText('spans.db')).toBeInTheDocument();
  58. });
  59. it('allows adding and deleting series', async () => {
  60. render(
  61. <WidgetBuilderProvider>
  62. <Visualize />
  63. </WidgetBuilderProvider>,
  64. {
  65. organization,
  66. router: RouterFixture({
  67. location: LocationFixture({
  68. query: {
  69. yAxis: ['max(spans.db)'],
  70. dataset: WidgetType.TRANSACTIONS,
  71. displayType: DisplayType.LINE,
  72. },
  73. }),
  74. }),
  75. }
  76. );
  77. expect(await screen.findByRole('button', {name: 'Remove field'})).toBeDisabled();
  78. await userEvent.click(screen.getByRole('button', {name: 'Add Series'}));
  79. expect(screen.queryAllByRole('button', {name: 'Remove field'})[0]).toBeEnabled();
  80. await userEvent.click(screen.queryAllByRole('button', {name: 'Remove field'})[0]!);
  81. expect(screen.queryAllByRole('button', {name: 'Remove field'})[0]).toBeDisabled();
  82. });
  83. it('disables the column selection when the aggregate has no parameters', async () => {
  84. render(
  85. <WidgetBuilderProvider>
  86. <Visualize />
  87. </WidgetBuilderProvider>,
  88. {
  89. organization,
  90. router: RouterFixture({
  91. location: LocationFixture({
  92. query: {
  93. yAxis: ['max(spans.db)'],
  94. dataset: WidgetType.TRANSACTIONS,
  95. displayType: DisplayType.LINE,
  96. },
  97. }),
  98. }),
  99. }
  100. );
  101. expect(screen.getByRole('button', {name: 'Column Selection'})).toBeEnabled();
  102. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  103. await userEvent.click(screen.getByRole('option', {name: 'count'}));
  104. expect(screen.getByRole('button', {name: 'Column Selection'})).toBeDisabled();
  105. expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toBeEnabled();
  106. expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveValue('');
  107. });
  108. it('adds the default value for the column selection when the aggregate has parameters', async () => {
  109. render(
  110. <WidgetBuilderProvider>
  111. <Visualize />
  112. </WidgetBuilderProvider>,
  113. {
  114. organization,
  115. router: RouterFixture({
  116. location: LocationFixture({
  117. query: {
  118. yAxis: ['count()'],
  119. dataset: WidgetType.TRANSACTIONS,
  120. displayType: DisplayType.LINE,
  121. },
  122. }),
  123. }),
  124. }
  125. );
  126. expect(screen.getByRole('button', {name: 'Column Selection'})).toBeDisabled();
  127. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  128. await userEvent.click(screen.getByRole('option', {name: 'p95'}));
  129. expect(screen.getByRole('button', {name: 'Column Selection'})).toBeEnabled();
  130. expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
  131. 'transaction.duration'
  132. );
  133. expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
  134. 'p95'
  135. );
  136. });
  137. it('maintains the selected aggregate when the column selection is changed and there are parameters', async () => {
  138. render(
  139. <WidgetBuilderProvider>
  140. <Visualize />
  141. </WidgetBuilderProvider>,
  142. {
  143. organization,
  144. router: RouterFixture({
  145. location: LocationFixture({
  146. query: {
  147. yAxis: ['max(spans.db)'],
  148. dataset: WidgetType.TRANSACTIONS,
  149. displayType: DisplayType.LINE,
  150. },
  151. }),
  152. }),
  153. }
  154. );
  155. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  156. await userEvent.click(screen.getByRole('option', {name: 'p95'}));
  157. expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
  158. 'spans.db'
  159. );
  160. expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
  161. 'p95'
  162. );
  163. });
  164. it('allows adding equations', async () => {
  165. render(
  166. <WidgetBuilderProvider>
  167. <Visualize />
  168. </WidgetBuilderProvider>,
  169. {
  170. organization,
  171. router: RouterFixture({
  172. location: LocationFixture({
  173. query: {
  174. yAxis: ['count()'],
  175. dataset: WidgetType.TRANSACTIONS,
  176. displayType: DisplayType.LINE,
  177. },
  178. }),
  179. }),
  180. }
  181. );
  182. await userEvent.click(screen.getByRole('button', {name: 'Add Equation'}));
  183. expect(screen.getByLabelText('Equation')).toBeInTheDocument();
  184. await userEvent.click(screen.getByLabelText('Equation'));
  185. // Check the menu items
  186. const headers = screen.getAllByRole('banner');
  187. expect(headers[0]).toHaveTextContent('Fields');
  188. expect(headers[1]).toHaveTextContent('Operators');
  189. expect(screen.getByRole('listitem', {name: 'count()'})).toBeInTheDocument();
  190. // Make a selection and type in the equation
  191. await userEvent.click(screen.getByRole('listitem', {name: 'count()'}));
  192. await userEvent.type(screen.getByLabelText('Equation'), '* 2');
  193. expect(screen.getByLabelText('Equation')).toHaveValue('count() * 2');
  194. });
  195. it('renders a field without an aggregate in tables', async () => {
  196. render(
  197. <WidgetBuilderProvider>
  198. <Visualize />
  199. </WidgetBuilderProvider>,
  200. {
  201. organization,
  202. router: RouterFixture({
  203. location: LocationFixture({
  204. query: {
  205. field: ['transaction.duration'],
  206. dataset: WidgetType.TRANSACTIONS,
  207. displayType: DisplayType.TABLE,
  208. },
  209. }),
  210. }),
  211. }
  212. );
  213. expect(
  214. await screen.findByRole('button', {name: 'Column Selection'})
  215. ).toHaveTextContent('transaction.duration');
  216. expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
  217. 'None'
  218. );
  219. });
  220. it('allows setting a field without an aggregate in tables', async () => {
  221. render(
  222. <WidgetBuilderProvider>
  223. <Visualize />
  224. </WidgetBuilderProvider>,
  225. {
  226. organization,
  227. router: RouterFixture({
  228. location: LocationFixture({
  229. query: {
  230. field: ['count()'],
  231. dataset: WidgetType.TRANSACTIONS,
  232. displayType: DisplayType.TABLE,
  233. },
  234. }),
  235. }),
  236. }
  237. );
  238. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  239. await userEvent.click(screen.getByRole('option', {name: 'None'}));
  240. await userEvent.click(screen.getByRole('button', {name: 'Column Selection'}));
  241. await userEvent.click(screen.getByRole('option', {name: 'transaction.duration'}));
  242. expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
  243. 'transaction.duration'
  244. );
  245. expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
  246. 'None'
  247. );
  248. });
  249. it('allows setting an equation in tables', async () => {
  250. render(
  251. <WidgetBuilderProvider>
  252. <Visualize />
  253. </WidgetBuilderProvider>,
  254. {
  255. organization,
  256. router: RouterFixture({
  257. location: LocationFixture({
  258. query: {
  259. field: ['count()'],
  260. dataset: WidgetType.TRANSACTIONS,
  261. displayType: DisplayType.TABLE,
  262. },
  263. }),
  264. }),
  265. }
  266. );
  267. await userEvent.click(screen.getByRole('button', {name: 'Add Equation'}));
  268. await userEvent.click(screen.getByLabelText('Equation'));
  269. await userEvent.click(screen.getByRole('listitem', {name: 'count()'}));
  270. await userEvent.type(screen.getByLabelText('Equation'), '* 2');
  271. expect(screen.getByLabelText('Equation')).toHaveValue('count() * 2');
  272. });
  273. it('maintains the selected column when switching from field to aggregate', async () => {
  274. render(
  275. <WidgetBuilderProvider>
  276. <Visualize />
  277. </WidgetBuilderProvider>,
  278. {
  279. organization,
  280. router: RouterFixture({
  281. location: LocationFixture({
  282. query: {
  283. yAxis: ['transaction.duration'],
  284. dataset: WidgetType.TRANSACTIONS,
  285. displayType: DisplayType.LINE,
  286. },
  287. }),
  288. }),
  289. }
  290. );
  291. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  292. await userEvent.click(screen.getByRole('option', {name: 'p95'}));
  293. expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
  294. 'transaction.duration'
  295. );
  296. });
  297. it('maintains the selected column when switching from aggregate to aggregate', async () => {
  298. render(
  299. <WidgetBuilderProvider>
  300. <Visualize />
  301. </WidgetBuilderProvider>,
  302. {
  303. organization,
  304. router: RouterFixture({
  305. location: LocationFixture({
  306. query: {
  307. field: ['max(spans.db)'],
  308. dataset: WidgetType.TRANSACTIONS,
  309. displayType: DisplayType.TABLE,
  310. },
  311. }),
  312. }),
  313. }
  314. );
  315. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  316. await userEvent.click(screen.getByRole('option', {name: 'p95'}));
  317. expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
  318. 'spans.db'
  319. );
  320. });
  321. it('properly transitions between aggregates of higher to no parameter count', async () => {
  322. render(
  323. <WidgetBuilderProvider>
  324. <Visualize />
  325. </WidgetBuilderProvider>,
  326. {
  327. organization,
  328. router: RouterFixture({
  329. location: LocationFixture({
  330. query: {
  331. field: ['count_if(transaction.duration,equals,testValue)'],
  332. dataset: WidgetType.TRANSACTIONS,
  333. displayType: DisplayType.TABLE,
  334. },
  335. }),
  336. }),
  337. }
  338. );
  339. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  340. await userEvent.click(screen.getByRole('option', {name: 'count'}));
  341. expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
  342. 'None'
  343. );
  344. expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
  345. 'count'
  346. );
  347. expect(mockNavigate).toHaveBeenCalledWith(
  348. expect.objectContaining({
  349. query: expect.objectContaining({
  350. field: ['count()'],
  351. }),
  352. })
  353. );
  354. });
  355. it('properly transitions between aggregates of higher to lower parameter count', async () => {
  356. render(
  357. <WidgetBuilderProvider>
  358. <Visualize />
  359. </WidgetBuilderProvider>,
  360. {
  361. organization,
  362. router: RouterFixture({
  363. location: LocationFixture({
  364. query: {
  365. field: ['count_if(transaction.duration,equals,testValue)'],
  366. dataset: WidgetType.TRANSACTIONS,
  367. displayType: DisplayType.TABLE,
  368. },
  369. }),
  370. }),
  371. }
  372. );
  373. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  374. await userEvent.click(screen.getByRole('option', {name: 'count_miserable'}));
  375. expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
  376. 'transaction.duration'
  377. );
  378. expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
  379. 'count_miserable'
  380. );
  381. expect(screen.getByDisplayValue('300')).toBeInTheDocument();
  382. expect(mockNavigate).toHaveBeenCalledWith(
  383. expect.objectContaining({
  384. query: expect.objectContaining({
  385. field: ['count_miserable(transaction.duration,300)'],
  386. }),
  387. })
  388. );
  389. });
  390. it('adds the default value for an aggregate with 2 parameters', async () => {
  391. render(
  392. <WidgetBuilderProvider>
  393. <Visualize />
  394. </WidgetBuilderProvider>,
  395. {
  396. organization,
  397. router: RouterFixture({
  398. location: LocationFixture({
  399. query: {
  400. field: ['transaction.duration'],
  401. dataset: WidgetType.TRANSACTIONS,
  402. displayType: DisplayType.TABLE,
  403. },
  404. }),
  405. }),
  406. }
  407. );
  408. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  409. await userEvent.click(screen.getByRole('option', {name: 'count_miserable'}));
  410. // TODO: This is supposed to only allow the user field
  411. expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
  412. 'transaction.duration'
  413. );
  414. });
  415. it('adds the default values for an aggregate with 3 parameters', async () => {
  416. render(
  417. <WidgetBuilderProvider>
  418. <Visualize />
  419. </WidgetBuilderProvider>,
  420. {
  421. organization,
  422. router: RouterFixture({
  423. location: LocationFixture({
  424. query: {
  425. field: ['transaction'],
  426. dataset: WidgetType.TRANSACTIONS,
  427. displayType: DisplayType.TABLE,
  428. },
  429. }),
  430. }),
  431. }
  432. );
  433. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  434. await userEvent.click(screen.getByRole('option', {name: 'count_if'}));
  435. expect(screen.getByRole('button', {name: 'Column Selection'})).toHaveTextContent(
  436. 'transaction'
  437. );
  438. expect(screen.getByRole('button', {name: 'Aggregate Selection'})).toHaveTextContent(
  439. 'count_if'
  440. );
  441. expect(screen.getByText('is equal to')).toBeInTheDocument();
  442. expect(screen.getByDisplayValue('300')).toBeInTheDocument();
  443. });
  444. it('disables the aggregate selection when there is only one aggregate option', async () => {
  445. render(
  446. <WidgetBuilderProvider>
  447. <Visualize />
  448. </WidgetBuilderProvider>,
  449. {
  450. organization,
  451. router: RouterFixture({
  452. location: LocationFixture({
  453. query: {
  454. dataset: WidgetType.ISSUE,
  455. field: ['issue.id'],
  456. displayType: DisplayType.TABLE,
  457. },
  458. }),
  459. }),
  460. }
  461. );
  462. expect(
  463. await screen.findByRole('button', {name: 'Aggregate Selection'})
  464. ).toBeDisabled();
  465. });
  466. it('does not show the legend alias input for chart widgets', async () => {
  467. render(
  468. <WidgetBuilderProvider>
  469. <Visualize />
  470. </WidgetBuilderProvider>,
  471. {
  472. organization,
  473. router: RouterFixture({
  474. location: LocationFixture({
  475. query: {
  476. dataset: WidgetType.TRANSACTIONS,
  477. displayType: DisplayType.LINE,
  478. yAxis: ['p90(transaction.duration)'],
  479. },
  480. }),
  481. }),
  482. }
  483. );
  484. expect(
  485. await screen.findByRole('button', {name: 'Column Selection'})
  486. ).toHaveTextContent('transaction.duration');
  487. expect(
  488. await screen.findByRole('button', {name: 'Aggregate Selection'})
  489. ).toHaveTextContent('p90');
  490. expect(screen.queryByLabelText('Legend Alias')).not.toBeInTheDocument();
  491. });
  492. it('does not show the legend alias input for big number widgets', async () => {
  493. render(
  494. <WidgetBuilderProvider>
  495. <Visualize />
  496. </WidgetBuilderProvider>,
  497. {
  498. organization,
  499. router: RouterFixture({
  500. location: LocationFixture({
  501. query: {
  502. dataset: WidgetType.TRANSACTIONS,
  503. displayType: DisplayType.BIG_NUMBER,
  504. field: ['count()'],
  505. },
  506. }),
  507. }),
  508. }
  509. );
  510. expect(
  511. await screen.findByRole('button', {name: 'Aggregate Selection'})
  512. ).toHaveTextContent('count');
  513. expect(screen.queryByLabelText('Legend Alias')).not.toBeInTheDocument();
  514. });
  515. it('does not allow for selecting individual fields in big number widgets', async () => {
  516. render(
  517. <WidgetBuilderProvider>
  518. <Visualize />
  519. </WidgetBuilderProvider>,
  520. {
  521. organization,
  522. router: RouterFixture({
  523. location: LocationFixture({
  524. query: {
  525. dataset: WidgetType.TRANSACTIONS,
  526. displayType: DisplayType.BIG_NUMBER,
  527. field: ['count()'],
  528. },
  529. }),
  530. }),
  531. }
  532. );
  533. await userEvent.click(screen.getByRole('button', {name: 'Aggregate Selection'}));
  534. // Being unable to choose "None" in the aggregate selection means that the
  535. // individual field is not allowed, i.e. only aggregates appear.
  536. expect(screen.queryByRole('option', {name: 'None'})).not.toBeInTheDocument();
  537. });
  538. it('updates only the selected field', async () => {
  539. render(
  540. <WidgetBuilderProvider>
  541. <Visualize />
  542. </WidgetBuilderProvider>,
  543. {
  544. organization,
  545. router: RouterFixture({
  546. location: LocationFixture({
  547. query: {
  548. dataset: WidgetType.TRANSACTIONS,
  549. displayType: DisplayType.TABLE,
  550. field: ['count_unique(user)'],
  551. },
  552. }),
  553. }),
  554. }
  555. );
  556. expect(await screen.findByLabelText('Aggregate Selection')).toHaveTextContent(
  557. 'count_unique'
  558. );
  559. expect(screen.getByLabelText('Column Selection')).toHaveTextContent('user');
  560. // Add 3 fields
  561. await userEvent.click(screen.getByRole('button', {name: 'Add Field'}));
  562. await userEvent.click(screen.getByRole('button', {name: 'Add Field'}));
  563. await userEvent.click(screen.getByRole('button', {name: 'Add Field'}));
  564. // count() is the default aggregate when adding a field
  565. expect(screen.getAllByText('count')).toHaveLength(3);
  566. // Change the last field
  567. await userEvent.click(screen.getAllByText('count')[2]!);
  568. await userEvent.click(screen.getByRole('option', {name: 'epm'}));
  569. // The other fields should not be affected
  570. expect(screen.getByText('count_unique')).toBeInTheDocument();
  571. expect(screen.getAllByText('count')).toHaveLength(2);
  572. expect(screen.getAllByText('epm')).toHaveLength(1);
  573. });
  574. describe('spans', () => {
  575. beforeEach(() => {
  576. jest.mocked(useSpanTags).mockImplementation((type?: 'string' | 'number') => {
  577. if (type === 'number') {
  578. return {
  579. 'span.duration': {
  580. key: 'span.duration',
  581. name: 'span.duration',
  582. kind: 'measurement',
  583. },
  584. 'tags[anotherNumericTag,number]': {
  585. key: 'anotherNumericTag',
  586. name: 'anotherNumericTag',
  587. kind: 'measurement',
  588. },
  589. } as TagCollection;
  590. }
  591. return {
  592. 'span.description': {
  593. key: 'span.description',
  594. name: 'span.description',
  595. kind: 'tag',
  596. },
  597. } as TagCollection;
  598. });
  599. });
  600. it('shows numeric tags as primary options for chart widgets', async () => {
  601. render(
  602. <WidgetBuilderProvider>
  603. <Visualize />
  604. </WidgetBuilderProvider>,
  605. {
  606. organization,
  607. router: RouterFixture({
  608. location: LocationFixture({
  609. query: {
  610. dataset: WidgetType.SPANS,
  611. displayType: DisplayType.LINE,
  612. yAxis: ['p90(span.duration)'],
  613. },
  614. }),
  615. }),
  616. }
  617. );
  618. await userEvent.click(
  619. await screen.findByRole('button', {name: 'Column Selection'})
  620. );
  621. const listbox = await screen.findByRole('listbox', {name: 'Column Selection'});
  622. expect(within(listbox).getByText('anotherNumericTag')).toBeInTheDocument();
  623. expect(within(listbox).queryByText('span.description')).not.toBeInTheDocument();
  624. });
  625. it('shows the correct aggregate options', async () => {
  626. render(
  627. <WidgetBuilderProvider>
  628. <Visualize />
  629. </WidgetBuilderProvider>,
  630. {
  631. organization,
  632. router: RouterFixture({
  633. location: LocationFixture({
  634. query: {
  635. dataset: WidgetType.SPANS,
  636. displayType: DisplayType.LINE,
  637. yAxis: ['count(span.duration)'],
  638. },
  639. }),
  640. }),
  641. }
  642. );
  643. await userEvent.click(
  644. await screen.findByRole('button', {name: 'Aggregate Selection'})
  645. );
  646. // count has two entries because it's already selected
  647. // and in the dropdown
  648. expect(screen.getAllByText('count')).toHaveLength(2);
  649. expect(screen.getByText('avg')).toBeInTheDocument();
  650. expect(screen.getByText('max')).toBeInTheDocument();
  651. expect(screen.getByText('min')).toBeInTheDocument();
  652. expect(screen.getByText('p50')).toBeInTheDocument();
  653. expect(screen.getByText('p75')).toBeInTheDocument();
  654. expect(screen.getByText('p90')).toBeInTheDocument();
  655. expect(screen.getByText('p95')).toBeInTheDocument();
  656. expect(screen.getByText('p99')).toBeInTheDocument();
  657. expect(screen.getByText('p100')).toBeInTheDocument();
  658. expect(screen.getByText('sum')).toBeInTheDocument();
  659. });
  660. it('shows the correct column options for the aggregate field type', async () => {
  661. render(
  662. <WidgetBuilderProvider>
  663. <Visualize />
  664. </WidgetBuilderProvider>,
  665. {
  666. organization,
  667. router: RouterFixture({
  668. location: LocationFixture({
  669. query: {
  670. dataset: WidgetType.SPANS,
  671. displayType: DisplayType.TABLE,
  672. field: ['p90(span.duration)'],
  673. },
  674. }),
  675. }),
  676. }
  677. );
  678. await userEvent.click(
  679. await screen.findByRole('button', {name: 'Column Selection'})
  680. );
  681. const listbox = await screen.findByRole('listbox', {name: 'Column Selection'});
  682. expect(within(listbox).getByText('span.duration')).toBeInTheDocument();
  683. expect(within(listbox).getByText('anotherNumericTag')).toBeInTheDocument();
  684. });
  685. it('shows the correct column options for the non-aggregate field type', async () => {
  686. render(
  687. <WidgetBuilderProvider>
  688. <Visualize />
  689. </WidgetBuilderProvider>,
  690. {
  691. organization,
  692. router: RouterFixture({
  693. location: LocationFixture({
  694. query: {
  695. dataset: WidgetType.SPANS,
  696. displayType: DisplayType.TABLE,
  697. field: ['span.duration'],
  698. },
  699. }),
  700. }),
  701. }
  702. );
  703. await userEvent.click(
  704. await screen.findByRole('button', {name: 'Column Selection'})
  705. );
  706. const listbox = await screen.findByRole('listbox', {name: 'Column Selection'});
  707. expect(within(listbox).getByText('span.duration')).toBeInTheDocument();
  708. expect(within(listbox).getByText('span.description')).toBeInTheDocument();
  709. });
  710. });
  711. });