tableView.spec.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. import {browserHistory} from 'react-router';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import TagStore from 'sentry/stores/tagStore';
  7. import EventView from 'sentry/utils/discover/eventView';
  8. import TableView from 'sentry/views/eventsV2/table/tableView';
  9. describe('TableView > CellActions', function () {
  10. let initialData, rows, onChangeShowTags;
  11. const location = {
  12. pathname: '/organizations/org-slug/discover/results/',
  13. query: {
  14. id: '42',
  15. name: 'best query',
  16. field: [
  17. 'title',
  18. 'transaction',
  19. 'count()',
  20. 'timestamp',
  21. 'release',
  22. 'equation|count() + 100',
  23. ],
  24. sort: ['title'],
  25. query: '',
  26. project: [123],
  27. statsPeriod: '14d',
  28. environment: ['staging'],
  29. yAxis: 'p95',
  30. },
  31. };
  32. const eventView = EventView.fromLocation(location);
  33. function makeWrapper(context, tableData, view) {
  34. return mountWithTheme(
  35. <TableView
  36. organization={context.organization}
  37. location={location}
  38. eventView={view}
  39. isLoading={false}
  40. projects={context.organization.projects}
  41. tableData={tableData}
  42. onChangeShowTags={onChangeShowTags}
  43. />,
  44. context.routerContext
  45. );
  46. }
  47. function openContextMenu(wrapper, cellIndex) {
  48. const menu = wrapper.find('CellAction').at(cellIndex);
  49. // Hover over the menu
  50. menu.find('Container > div').at(0).simulate('mouseEnter');
  51. wrapper.update();
  52. // Open the menu
  53. wrapper.find('MenuButton').simulate('click');
  54. // Return the menu wrapper so we can interact with it.
  55. return wrapper.find('CellAction').at(cellIndex).find('Menu');
  56. }
  57. beforeEach(function () {
  58. browserHistory.push.mockReset();
  59. browserHistory.replace.mockReset();
  60. const organization = TestStubs.Organization({
  61. features: ['discover-basic'],
  62. projects: [TestStubs.Project()],
  63. });
  64. initialData = initializeOrg({
  65. organization,
  66. router: {location},
  67. });
  68. act(() => {
  69. ProjectsStore.loadInitialData(initialData.organization.projects);
  70. TagStore.reset();
  71. TagStore.loadTagsSuccess([
  72. {name: 'size', key: 'size', count: 1},
  73. {name: 'shape', key: 'shape', count: 1},
  74. {name: 'direction', key: 'direction', count: 1},
  75. ]);
  76. });
  77. onChangeShowTags = jest.fn();
  78. rows = {
  79. meta: {
  80. title: 'string',
  81. transaction: 'string',
  82. 'count()': 'integer',
  83. timestamp: 'date',
  84. release: 'string',
  85. 'equation[0]': 'integer',
  86. },
  87. data: [
  88. {
  89. title: 'some title',
  90. transaction: '/organizations/',
  91. 'count()': 9,
  92. timestamp: '2019-05-23T22:12:48+00:00',
  93. release: 'v1.0.2',
  94. 'equation[0]': 109,
  95. },
  96. ],
  97. };
  98. });
  99. afterEach(() => {
  100. ProjectsStore.reset();
  101. });
  102. it('updates sort order on equation fields', function () {
  103. const view = eventView.clone();
  104. const wrapper = makeWrapper(initialData, rows, view);
  105. const equationSort = wrapper.find('SortLink').last();
  106. expect(equationSort.find('StyledTooltip').props().title).toBe('count() + 100');
  107. expect(equationSort.find('a').props().href).toBe(
  108. '/organizations/org-slug/discover/results/?environment=staging&field=title&field=transaction&field=count%28%29&field=timestamp&field=release&field=equation%7Ccount%28%29%20%2B%20100&id=42&name=best%20query&project=123&query=&sort=-equation%5B0%5D&statsPeriod=14d&yAxis=p95'
  109. );
  110. });
  111. it('updates sort order on non-equation fields', function () {
  112. const view = eventView.clone();
  113. const wrapper = makeWrapper(initialData, rows, view);
  114. const equationSort = wrapper.find('SortLink').at(1);
  115. expect(equationSort.find('StyledTooltip').props().title).toBe('transaction');
  116. equationSort.simulate('click');
  117. expect(equationSort.find('a').props().href).toBe(
  118. '/organizations/org-slug/discover/results/?environment=staging&field=title&field=transaction&field=count%28%29&field=timestamp&field=release&field=equation%7Ccount%28%29%20%2B%20100&id=42&name=best%20query&project=123&query=&sort=-transaction&statsPeriod=14d&yAxis=p95'
  119. );
  120. });
  121. it('handles add cell action on null value', function () {
  122. rows.data[0].title = null;
  123. const wrapper = makeWrapper(initialData, rows, eventView);
  124. const menu = openContextMenu(wrapper, 0);
  125. menu.find('button[data-test-id="add-to-filter"]').simulate('click');
  126. expect(browserHistory.push).toHaveBeenCalledWith({
  127. pathname: location.pathname,
  128. query: expect.objectContaining({
  129. query: '!has:title',
  130. }),
  131. });
  132. });
  133. it('handles add cell action on null value replace has condition', function () {
  134. rows.data[0].title = null;
  135. const view = eventView.clone();
  136. view.query = 'tag:value has:title';
  137. const wrapper = makeWrapper(initialData, rows, view);
  138. const menu = openContextMenu(wrapper, 0);
  139. menu.find('button[data-test-id="add-to-filter"]').simulate('click');
  140. expect(browserHistory.push).toHaveBeenCalledWith({
  141. pathname: location.pathname,
  142. query: expect.objectContaining({
  143. query: 'tag:value !has:title',
  144. }),
  145. });
  146. });
  147. it('handles add cell action on string value replace negation', function () {
  148. const view = eventView.clone();
  149. view.query = 'tag:value !title:nope';
  150. const wrapper = makeWrapper(initialData, rows, view);
  151. const menu = openContextMenu(wrapper, 0);
  152. menu.find('button[data-test-id="add-to-filter"]').simulate('click');
  153. expect(browserHistory.push).toHaveBeenCalledWith({
  154. pathname: location.pathname,
  155. query: expect.objectContaining({
  156. query: 'tag:value title:"some title"',
  157. }),
  158. });
  159. });
  160. it('handles add cell action with multiple y axis', function () {
  161. location.query.yAxis = ['count()', 'failure_count()'];
  162. const wrapper = makeWrapper(initialData, rows, eventView);
  163. const menu = openContextMenu(wrapper, 0);
  164. menu.find('button[data-test-id="add-to-filter"]').simulate('click');
  165. expect(browserHistory.push).toHaveBeenCalledWith({
  166. pathname: location.pathname,
  167. query: expect.objectContaining({
  168. query: 'title:"some title"',
  169. yAxis: ['count()', 'failure_count()'],
  170. }),
  171. });
  172. });
  173. it('handles exclude cell action on string value', function () {
  174. const wrapper = makeWrapper(initialData, rows, eventView);
  175. const menu = openContextMenu(wrapper, 0);
  176. menu.find('button[data-test-id="exclude-from-filter"]').simulate('click');
  177. expect(browserHistory.push).toHaveBeenCalledWith({
  178. pathname: location.pathname,
  179. query: expect.objectContaining({
  180. query: '!title:"some title"',
  181. }),
  182. });
  183. });
  184. it('handles exclude cell action on string value replace inclusion', function () {
  185. const view = eventView.clone();
  186. view.query = 'tag:value title:nope';
  187. const wrapper = makeWrapper(initialData, rows, view);
  188. const menu = openContextMenu(wrapper, 0);
  189. menu.find('button[data-test-id="exclude-from-filter"]').simulate('click');
  190. expect(browserHistory.push).toHaveBeenCalledWith({
  191. pathname: location.pathname,
  192. query: expect.objectContaining({
  193. query: 'tag:value !title:"some title"',
  194. }),
  195. });
  196. });
  197. it('handles exclude cell action on null value', function () {
  198. rows.data[0].title = null;
  199. const wrapper = makeWrapper(initialData, rows, eventView);
  200. const menu = openContextMenu(wrapper, 0);
  201. menu.find('button[data-test-id="exclude-from-filter"]').simulate('click');
  202. expect(browserHistory.push).toHaveBeenCalledWith({
  203. pathname: location.pathname,
  204. query: expect.objectContaining({
  205. query: 'has:title',
  206. }),
  207. });
  208. });
  209. it('handles exclude cell action on null value replace condition', function () {
  210. const view = eventView.clone();
  211. view.query = 'tag:value !has:title';
  212. rows.data[0].title = null;
  213. const wrapper = makeWrapper(initialData, rows, view);
  214. const menu = openContextMenu(wrapper, 0);
  215. menu.find('button[data-test-id="exclude-from-filter"]').simulate('click');
  216. expect(browserHistory.push).toHaveBeenCalledWith({
  217. pathname: location.pathname,
  218. query: expect.objectContaining({
  219. query: 'tag:value has:title',
  220. }),
  221. });
  222. });
  223. it('handles greater than cell action on number value', function () {
  224. const wrapper = makeWrapper(initialData, rows, eventView);
  225. const menu = openContextMenu(wrapper, 2);
  226. menu.find('button[data-test-id="show-values-greater-than"]').simulate('click');
  227. expect(browserHistory.push).toHaveBeenCalledWith({
  228. pathname: location.pathname,
  229. query: expect.objectContaining({
  230. query: 'count():>9',
  231. }),
  232. });
  233. });
  234. it('handles less than cell action on number value', function () {
  235. const wrapper = makeWrapper(initialData, rows, eventView);
  236. const menu = openContextMenu(wrapper, 2);
  237. menu.find('button[data-test-id="show-values-less-than"]').simulate('click');
  238. expect(browserHistory.push).toHaveBeenCalledWith({
  239. pathname: location.pathname,
  240. query: expect.objectContaining({
  241. query: 'count():<9',
  242. }),
  243. });
  244. });
  245. it('handles go to transaction without project column selected', function () {
  246. rows.data[0]['project.name'] = 'project-slug';
  247. const wrapper = makeWrapper(initialData, rows, eventView);
  248. const menu = openContextMenu(wrapper, 1);
  249. menu.find('button[data-test-id="transaction-summary"]').simulate('click');
  250. expect(browserHistory.push).toHaveBeenCalledWith({
  251. pathname: '/organizations/org-slug/performance/summary/',
  252. query: expect.objectContaining({
  253. transaction: '/organizations/',
  254. project: ['2'],
  255. }),
  256. });
  257. });
  258. it('handles go to transaction with project column selected', function () {
  259. rows.data[0].project = 'project-slug';
  260. const wrapper = makeWrapper(initialData, rows, eventView);
  261. const menu = openContextMenu(wrapper, 1);
  262. menu.find('button[data-test-id="transaction-summary"]').simulate('click');
  263. expect(browserHistory.push).toHaveBeenCalledWith({
  264. pathname: '/organizations/org-slug/performance/summary/',
  265. query: expect.objectContaining({
  266. transaction: '/organizations/',
  267. project: ['2'],
  268. }),
  269. });
  270. });
  271. it('handles go to release', function () {
  272. const wrapper = makeWrapper(initialData, rows, eventView);
  273. const menu = openContextMenu(wrapper, 4);
  274. menu.find('button[data-test-id="release"]').simulate('click');
  275. expect(browserHistory.push).toHaveBeenCalledWith({
  276. pathname: '/organizations/org-slug/releases/v1.0.2/',
  277. query: expect.objectContaining({
  278. environment: eventView.environment,
  279. }),
  280. });
  281. });
  282. it('has tooltip on integer value greater than 999', function () {
  283. rows.data[0]['count()'] = 1000;
  284. const wrapper = makeWrapper(initialData, rows, eventView);
  285. const tooltip = wrapper.find('GridBody Tooltip').at(1);
  286. expect(wrapper.find('GridBody Tooltip').length).toEqual(3);
  287. expect(tooltip.prop('title')).toBe('1,000');
  288. });
  289. it('does not have tooltip on integer value less than 999', function () {
  290. const wrapper = makeWrapper(initialData, rows, eventView);
  291. expect(wrapper.find('GridBody Tooltip').length).toEqual(2);
  292. });
  293. it('renders size columns correctly', function () {
  294. const orgWithFeature = TestStubs.Organization({
  295. features: ['discover-frontend-use-events-endpoint'],
  296. projects: [TestStubs.Project()],
  297. });
  298. render(
  299. <TableView
  300. organization={orgWithFeature}
  301. location={location}
  302. eventView={EventView.fromLocation({
  303. ...location,
  304. query: {
  305. ...location.query,
  306. field: [
  307. 'title',
  308. 'p99(measurements.custom.kibibyte)',
  309. 'p99(measurements.custom.kilobyte)',
  310. ],
  311. },
  312. })}
  313. isLoading={false}
  314. projects={initialData.organization.projects}
  315. tableData={{
  316. data: [
  317. {
  318. title: '/random/transaction/name',
  319. 'p99(measurements.custom.kibibyte)': 222.3,
  320. 'p99(measurements.custom.kilobyte)': 444.3,
  321. },
  322. ],
  323. meta: {
  324. title: 'string',
  325. 'p99(measurements.custom.kibibyte)': 'size',
  326. 'p99(measurements.custom.kilobyte)': 'size',
  327. units: {
  328. title: null,
  329. 'p99(measurements.custom.kibibyte)': 'kibibyte',
  330. 'p99(measurements.custom.kilobyte)': 'kilobyte',
  331. },
  332. },
  333. }}
  334. onChangeShowTags={onChangeShowTags}
  335. />
  336. );
  337. expect(screen.getByText('222.3 KiB')).toBeInTheDocument();
  338. expect(screen.getByText('444.3 KB')).toBeInTheDocument();
  339. });
  340. it('shows events with value less than selected custom performance metric', function () {
  341. const orgWithFeature = TestStubs.Organization({
  342. features: ['discover-frontend-use-events-endpoint'],
  343. projects: [TestStubs.Project()],
  344. });
  345. render(
  346. <TableView
  347. organization={orgWithFeature}
  348. location={location}
  349. eventView={EventView.fromLocation({
  350. ...location,
  351. query: {
  352. ...location.query,
  353. field: ['title', 'p99(measurements.custom.kilobyte)'],
  354. },
  355. })}
  356. isLoading={false}
  357. projects={initialData.organization.projects}
  358. tableData={{
  359. data: [
  360. {
  361. title: '/random/transaction/name',
  362. 'p99(measurements.custom.kilobyte)': 444.3,
  363. },
  364. ],
  365. meta: {
  366. title: 'string',
  367. 'p99(measurements.custom.kilobyte)': 'size',
  368. units: {
  369. title: null,
  370. 'p99(measurements.custom.kilobyte)': 'kilobyte',
  371. },
  372. },
  373. }}
  374. onChangeShowTags={onChangeShowTags}
  375. />
  376. );
  377. userEvent.hover(screen.getByText('444.3 KB'));
  378. const buttons = screen.getAllByRole('button');
  379. userEvent.click(buttons[buttons.length - 1]);
  380. userEvent.click(screen.getByText('Show values less than'));
  381. expect(browserHistory.push).toHaveBeenCalledWith({
  382. pathname: location.pathname,
  383. query: expect.objectContaining({
  384. query: 'p99(measurements.custom.kilobyte):<444300',
  385. }),
  386. });
  387. });
  388. });