results.spec.tsx 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  6. import selectEvent from 'sentry-test/selectEvent';
  7. import * as PageFilterPersistence from 'sentry/components/organizations/pageFilters/persistence';
  8. import ProjectsStore from 'sentry/stores/projectsStore';
  9. import {browserHistory} from 'sentry/utils/browserHistory';
  10. import EventView from 'sentry/utils/discover/eventView';
  11. import Results from 'sentry/views/discover/results';
  12. import {DEFAULT_EVENT_VIEW, TRANSACTION_VIEWS} from './data';
  13. const FIELDS = [
  14. {
  15. field: 'title',
  16. },
  17. {
  18. field: 'timestamp',
  19. },
  20. {
  21. field: 'user',
  22. },
  23. {
  24. field: 'count()',
  25. },
  26. ];
  27. const generateFields = () => ({
  28. field: FIELDS.map(i => i.field),
  29. });
  30. const eventTitle = 'Oh no something bad';
  31. function renderMockRequests() {
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/projects/',
  34. body: [],
  35. });
  36. MockApiClient.addMockResponse({
  37. url: '/organizations/org-slug/projects-count/',
  38. body: {myProjects: 10, allProjects: 300},
  39. });
  40. MockApiClient.addMockResponse({
  41. url: '/organizations/org-slug/tags/',
  42. body: [],
  43. });
  44. const eventsStatsMock = MockApiClient.addMockResponse({
  45. url: '/organizations/org-slug/events-stats/',
  46. body: {data: [[123, []]]},
  47. });
  48. MockApiClient.addMockResponse({
  49. url: '/organizations/org-slug/recent-searches/',
  50. body: [],
  51. });
  52. MockApiClient.addMockResponse({
  53. url: '/organizations/org-slug/recent-searches/',
  54. method: 'POST',
  55. body: [],
  56. });
  57. MockApiClient.addMockResponse({
  58. url: '/organizations/org-slug/releases/stats/',
  59. body: [],
  60. });
  61. const measurementsMetaMock = MockApiClient.addMockResponse({
  62. url: '/organizations/org-slug/measurements-meta/',
  63. method: 'GET',
  64. body: {},
  65. });
  66. const eventsResultsMock = MockApiClient.addMockResponse({
  67. url: '/organizations/org-slug/events/',
  68. body: {
  69. meta: {
  70. fields: {
  71. id: 'string',
  72. title: 'string',
  73. 'project.name': 'string',
  74. timestamp: 'date',
  75. 'user.id': 'string',
  76. },
  77. discoverSplitDecision: 'transaction-like',
  78. },
  79. data: [
  80. {
  81. id: 'deadbeef',
  82. 'user.id': 'alberto leal',
  83. title: eventTitle,
  84. 'project.name': 'project-slug',
  85. timestamp: '2019-05-23T22:12:48+00:00',
  86. },
  87. ],
  88. },
  89. });
  90. const eventsMetaMock = MockApiClient.addMockResponse({
  91. url: '/organizations/org-slug/events-meta/',
  92. body: {
  93. count: 2,
  94. },
  95. });
  96. MockApiClient.addMockResponse({
  97. url: '/organizations/org-slug/events/project-slug:deadbeef/',
  98. method: 'GET',
  99. body: {
  100. id: '1234',
  101. size: 1200,
  102. eventID: 'deadbeef',
  103. title: 'Oh no something bad',
  104. message: 'It was not good',
  105. dateCreated: '2019-05-23T22:12:48+00:00',
  106. entries: [
  107. {
  108. type: 'message',
  109. message: 'bad stuff',
  110. data: {},
  111. },
  112. ],
  113. tags: [{key: 'browser', value: 'Firefox'}],
  114. },
  115. });
  116. const eventFacetsMock = MockApiClient.addMockResponse({
  117. url: '/organizations/org-slug/events-facets/',
  118. body: [
  119. {
  120. key: 'release',
  121. topValues: [{count: 3, value: 'abcd123', name: 'abcd123'}],
  122. },
  123. {
  124. key: 'environment',
  125. topValues: [
  126. {count: 2, value: 'dev', name: 'dev'},
  127. {count: 1, value: 'prod', name: 'prod'},
  128. ],
  129. },
  130. {
  131. key: 'foo',
  132. topValues: [
  133. {count: 2, value: 'bar', name: 'bar'},
  134. {count: 1, value: 'baz', name: 'baz'},
  135. ],
  136. },
  137. ],
  138. });
  139. const mockVisit = MockApiClient.addMockResponse({
  140. url: '/organizations/org-slug/discover/saved/1/visit/',
  141. method: 'POST',
  142. body: [],
  143. statusCode: 200,
  144. });
  145. const mockSaved = MockApiClient.addMockResponse({
  146. url: '/organizations/org-slug/discover/saved/1/',
  147. method: 'GET',
  148. statusCode: 200,
  149. body: {
  150. id: '1',
  151. name: 'new',
  152. projects: [],
  153. version: 2,
  154. expired: false,
  155. dateCreated: '2021-04-08T17:53:25.195782Z',
  156. dateUpdated: '2021-04-09T12:13:18.567264Z',
  157. createdBy: {
  158. id: '2',
  159. },
  160. environment: [],
  161. fields: ['title', 'event.type', 'project', 'user.display', 'timestamp'],
  162. widths: ['-1', '-1', '-1', '-1', '-1'],
  163. range: '24h',
  164. orderby: '-user.display',
  165. queryDataset: 'discover',
  166. },
  167. });
  168. MockApiClient.addMockResponse({
  169. url: '/organizations/org-slug/discover/homepage/',
  170. method: 'GET',
  171. statusCode: 200,
  172. body: {
  173. id: '2',
  174. name: '',
  175. projects: [],
  176. version: 2,
  177. expired: false,
  178. dateCreated: '2021-04-08T17:53:25.195782Z',
  179. dateUpdated: '2021-04-09T12:13:18.567264Z',
  180. createdBy: {
  181. id: '2',
  182. },
  183. environment: [],
  184. fields: ['title', 'event.type', 'project', 'user.display', 'timestamp'],
  185. widths: ['-1', '-1', '-1', '-1', '-1'],
  186. range: '24h',
  187. orderby: '-user.display',
  188. queryDataset: 'discover',
  189. },
  190. });
  191. MockApiClient.addMockResponse({
  192. url: '/organizations/org-slug/dynamic-sampling/custom-rules/',
  193. method: 'GET',
  194. statusCode: 204,
  195. body: '',
  196. });
  197. return {
  198. eventsStatsMock,
  199. eventsMetaMock,
  200. eventsResultsMock,
  201. mockVisit,
  202. mockSaved,
  203. eventFacetsMock,
  204. measurementsMetaMock,
  205. };
  206. }
  207. describe('Results', function () {
  208. afterEach(function () {
  209. MockApiClient.clearMockResponses();
  210. ProjectsStore.reset();
  211. });
  212. describe('Events', function () {
  213. const features = ['discover-basic'];
  214. it('loads data when moving from an invalid to valid EventView', function () {
  215. const organization = OrganizationFixture({
  216. features,
  217. });
  218. // Start off with an invalid view (empty is invalid)
  219. const {router} = initializeOrg({
  220. organization,
  221. router: {
  222. location: {query: {query: 'tag:value'}},
  223. },
  224. });
  225. const mockRequests = renderMockRequests();
  226. ProjectsStore.loadInitialData([ProjectFixture()]);
  227. render(
  228. <Results
  229. location={router.location}
  230. router={router}
  231. loading={false}
  232. setSavedQuery={jest.fn()}
  233. />,
  234. {
  235. router: router,
  236. organization,
  237. }
  238. );
  239. // No request as eventview was invalid.
  240. expect(mockRequests.eventsStatsMock).not.toHaveBeenCalled();
  241. // Should redirect and retain the old query value
  242. expect(browserHistory.replace).toHaveBeenCalledWith(
  243. expect.objectContaining({
  244. pathname: '/organizations/org-slug/discover/results/',
  245. query: expect.objectContaining({
  246. query: 'tag:value',
  247. }),
  248. })
  249. );
  250. });
  251. it('pagination cursor should be cleared when making a search', async function () {
  252. const organization = OrganizationFixture({
  253. features,
  254. });
  255. const {router} = initializeOrg({
  256. organization,
  257. router: {
  258. location: {
  259. query: {
  260. ...generateFields(),
  261. cursor: '0%3A50%3A0',
  262. },
  263. },
  264. },
  265. });
  266. const mockRequests = renderMockRequests();
  267. ProjectsStore.loadInitialData([ProjectFixture()]);
  268. render(
  269. <Results
  270. organization={organization}
  271. location={router.location}
  272. router={router}
  273. loading={false}
  274. setSavedQuery={jest.fn()}
  275. />,
  276. {
  277. router: router,
  278. organization,
  279. }
  280. );
  281. // ensure cursor query string is initially present in the location
  282. expect(router.location).toEqual({
  283. query: {
  284. ...generateFields(),
  285. cursor: '0%3A50%3A0',
  286. },
  287. });
  288. await waitFor(() =>
  289. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  290. );
  291. // perform a search
  292. await userEvent.click(
  293. screen.getByPlaceholderText('Search for events, users, tags, and more')
  294. );
  295. await userEvent.paste('geo:canada');
  296. await userEvent.keyboard('{enter}');
  297. // should only be called with saved queries
  298. expect(mockRequests.mockVisit).not.toHaveBeenCalled();
  299. // cursor query string should be omitted from the query string
  300. expect(router.push).toHaveBeenCalledWith({
  301. pathname: undefined,
  302. query: {
  303. ...generateFields(),
  304. query: 'geo:canada',
  305. statsPeriod: '14d',
  306. },
  307. });
  308. });
  309. it('renders a y-axis selector', async function () {
  310. const organization = OrganizationFixture({
  311. features,
  312. });
  313. const {router} = initializeOrg({
  314. organization,
  315. router: {
  316. location: {query: {...generateFields(), yAxis: 'count()'}},
  317. },
  318. });
  319. renderMockRequests();
  320. ProjectsStore.loadInitialData([ProjectFixture()]);
  321. render(
  322. <Results
  323. organization={organization}
  324. location={router.location}
  325. router={router}
  326. loading={false}
  327. setSavedQuery={jest.fn()}
  328. />,
  329. {
  330. router: router,
  331. organization,
  332. }
  333. );
  334. // Click the 'default' option.
  335. await selectEvent.select(
  336. await screen.findByRole('button', {name: 'Y-Axis count()'}),
  337. 'count_unique(user)'
  338. );
  339. });
  340. it('renders a display selector', async function () {
  341. const organization = OrganizationFixture({
  342. features,
  343. });
  344. const {router} = initializeOrg({
  345. organization,
  346. router: {
  347. location: {query: {...generateFields(), display: 'default', yAxis: 'count'}},
  348. },
  349. });
  350. renderMockRequests();
  351. ProjectsStore.loadInitialData([ProjectFixture()]);
  352. render(
  353. <Results
  354. organization={organization}
  355. location={router.location}
  356. router={router}
  357. loading={false}
  358. setSavedQuery={jest.fn()}
  359. />,
  360. {
  361. router: router,
  362. organization,
  363. }
  364. );
  365. // Click the 'default' option.
  366. await selectEvent.select(
  367. await screen.findByRole('button', {name: /Display/}),
  368. 'Total Period'
  369. );
  370. });
  371. it('excludes top5 options when plan does not include discover-query', async function () {
  372. const organization = OrganizationFixture({
  373. features: ['discover-basic'],
  374. });
  375. const {router} = initializeOrg({
  376. organization,
  377. router: {
  378. location: {query: {...generateFields(), display: 'previous'}},
  379. },
  380. });
  381. ProjectsStore.loadInitialData([ProjectFixture()]);
  382. renderMockRequests();
  383. render(
  384. <Results
  385. organization={organization}
  386. location={router.location}
  387. router={router}
  388. loading={false}
  389. setSavedQuery={jest.fn()}
  390. />,
  391. {
  392. router: router,
  393. organization,
  394. }
  395. );
  396. await userEvent.click(await screen.findByRole('button', {name: /Display/}));
  397. expect(screen.queryByText('Top 5 Daily')).not.toBeInTheDocument();
  398. expect(screen.queryByText('Top 5 Period')).not.toBeInTheDocument();
  399. });
  400. it('needs confirmation on long queries', async function () {
  401. const organization = OrganizationFixture({
  402. features: ['discover-basic'],
  403. });
  404. const {router} = initializeOrg({
  405. organization,
  406. router: {
  407. location: {query: {...generateFields(), statsPeriod: '60d', project: '-1'}},
  408. },
  409. });
  410. ProjectsStore.loadInitialData([ProjectFixture()]);
  411. const mockRequests = renderMockRequests();
  412. render(
  413. <Results
  414. organization={organization}
  415. location={router.location}
  416. router={router}
  417. loading={false}
  418. setSavedQuery={jest.fn()}
  419. />,
  420. {
  421. router: router,
  422. organization,
  423. }
  424. );
  425. expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(0);
  426. await waitFor(() => {
  427. expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
  428. });
  429. });
  430. it('needs confirmation on long query with explicit projects', async function () {
  431. const organization = OrganizationFixture({
  432. features: ['discover-basic'],
  433. });
  434. const {router} = initializeOrg({
  435. organization,
  436. router: {
  437. location: {
  438. query: {
  439. ...generateFields(),
  440. statsPeriod: '60d',
  441. project: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(String),
  442. },
  443. },
  444. },
  445. });
  446. ProjectsStore.loadInitialData([ProjectFixture()]);
  447. const mockRequests = renderMockRequests();
  448. render(
  449. <Results
  450. organization={organization}
  451. location={router.location}
  452. router={router}
  453. loading={false}
  454. setSavedQuery={jest.fn()}
  455. />,
  456. {
  457. router: router,
  458. organization,
  459. }
  460. );
  461. expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(0);
  462. await waitFor(() => {
  463. expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
  464. });
  465. });
  466. it('does not need confirmation on short queries', async function () {
  467. const organization = OrganizationFixture({
  468. features: ['discover-basic'],
  469. });
  470. const {router} = initializeOrg({
  471. organization,
  472. router: {
  473. location: {query: {...generateFields(), statsPeriod: '30d', project: '-1'}},
  474. },
  475. });
  476. ProjectsStore.loadInitialData([ProjectFixture()]);
  477. const mockRequests = renderMockRequests();
  478. render(
  479. <Results
  480. organization={organization}
  481. location={router.location}
  482. router={router}
  483. loading={false}
  484. setSavedQuery={jest.fn()}
  485. />,
  486. {
  487. router: router,
  488. organization,
  489. }
  490. );
  491. await waitFor(() => {
  492. expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
  493. });
  494. expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(1);
  495. });
  496. it('does not need confirmation with to few projects', async function () {
  497. const organization = OrganizationFixture({
  498. features: ['discover-basic'],
  499. });
  500. const {router} = initializeOrg({
  501. organization,
  502. router: {
  503. location: {
  504. query: {
  505. ...generateFields(),
  506. statsPeriod: '90d',
  507. project: [1, 2, 3, 4].map(String),
  508. },
  509. },
  510. },
  511. });
  512. ProjectsStore.loadInitialData([ProjectFixture()]);
  513. const mockRequests = renderMockRequests();
  514. render(
  515. <Results
  516. organization={organization}
  517. location={router.location}
  518. router={router}
  519. loading={false}
  520. setSavedQuery={jest.fn()}
  521. />,
  522. {
  523. router: router,
  524. organization,
  525. }
  526. );
  527. await waitFor(() => {
  528. expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
  529. });
  530. expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(1);
  531. });
  532. it('creates event view from saved query', async function () {
  533. const organization = OrganizationFixture({
  534. features,
  535. slug: 'org-slug',
  536. });
  537. const {router} = initializeOrg({
  538. organization,
  539. router: {
  540. location: {query: {id: '1', statsPeriod: '24h'}},
  541. },
  542. });
  543. ProjectsStore.loadInitialData([ProjectFixture()]);
  544. const mockRequests = renderMockRequests();
  545. render(
  546. <Results
  547. organization={organization}
  548. location={router.location}
  549. router={router}
  550. loading={false}
  551. setSavedQuery={jest.fn()}
  552. />,
  553. {
  554. router: router,
  555. organization,
  556. }
  557. );
  558. await waitFor(() => expect(mockRequests.mockVisit).toHaveBeenCalled());
  559. expect(screen.getByRole('link', {name: 'timestamp'})).toHaveAttribute(
  560. 'href',
  561. 'undefined?field=title&field=event.type&field=project&field=user.display&field=timestamp&id=1&name=new&query=&sort=-timestamp&statsPeriod=24h&topEvents=5'
  562. );
  563. expect(screen.getByRole('link', {name: 'project'})).toHaveAttribute(
  564. 'href',
  565. 'undefined?field=title&field=event.type&field=project&field=user.display&field=timestamp&id=1&name=new&query=&sort=-project&statsPeriod=24h&topEvents=5'
  566. );
  567. // NOTE: This uses a legacy redirect for project event to the issue group event link
  568. expect(screen.getByRole('link', {name: 'deadbeef'})).toHaveAttribute(
  569. 'href',
  570. '/org-slug/project-slug/events/deadbeef/?id=1&referrer=discover-events-table&statsPeriod=24h'
  571. );
  572. expect(screen.getByRole('link', {name: 'user.display'})).toHaveAttribute(
  573. 'href',
  574. 'undefined?field=title&field=event.type&field=project&field=user.display&field=timestamp&id=1&name=new&query=&sort=user.display&statsPeriod=24h&topEvents=5'
  575. );
  576. expect(screen.getByRole('link', {name: 'title'})).toHaveAttribute(
  577. 'href',
  578. 'undefined?field=title&field=event.type&field=project&field=user.display&field=timestamp&id=1&name=new&query=&sort=-title&statsPeriod=24h&topEvents=5'
  579. );
  580. });
  581. it('overrides saved query params with location query params', async function () {
  582. const organization = OrganizationFixture({
  583. features,
  584. slug: 'org-slug',
  585. });
  586. const {router} = initializeOrg({
  587. organization,
  588. router: {
  589. location: {
  590. query: {
  591. id: '1',
  592. statsPeriod: '7d',
  593. project: ['2'],
  594. environment: ['production'],
  595. },
  596. },
  597. },
  598. });
  599. ProjectsStore.loadInitialData([ProjectFixture()]);
  600. const mockRequests = renderMockRequests();
  601. render(
  602. <Results
  603. organization={organization}
  604. location={router.location}
  605. router={router}
  606. loading={false}
  607. setSavedQuery={jest.fn()}
  608. />,
  609. {
  610. router: router,
  611. organization,
  612. }
  613. );
  614. await waitFor(() => expect(mockRequests.mockVisit).toHaveBeenCalled());
  615. expect(screen.getByRole('link', {name: 'timestamp'})).toHaveAttribute(
  616. 'href',
  617. 'undefined?environment=production&field=title&field=event.type&field=project&field=user.display&field=timestamp&id=1&name=new&project=2&query=&sort=-timestamp&statsPeriod=7d&topEvents=5'
  618. );
  619. });
  620. it('updates chart whenever yAxis parameter changes', async function () {
  621. const organization = OrganizationFixture({
  622. features,
  623. });
  624. const {router} = initializeOrg({
  625. organization,
  626. router: {
  627. location: {query: {...generateFields(), yAxis: 'count()'}},
  628. },
  629. });
  630. ProjectsStore.loadInitialData([ProjectFixture()]);
  631. const {eventsStatsMock, measurementsMetaMock} = renderMockRequests();
  632. const {rerender} = render(
  633. <Results
  634. organization={organization}
  635. location={router.location}
  636. router={router}
  637. loading={false}
  638. setSavedQuery={jest.fn()}
  639. />,
  640. {
  641. router: router,
  642. organization,
  643. }
  644. );
  645. // Should load events once
  646. expect(eventsStatsMock).toHaveBeenCalledTimes(1);
  647. expect(eventsStatsMock).toHaveBeenNthCalledWith(
  648. 1,
  649. '/organizations/org-slug/events-stats/',
  650. expect.objectContaining({
  651. query: expect.objectContaining({
  652. statsPeriod: '14d',
  653. yAxis: ['count()'],
  654. }),
  655. })
  656. );
  657. await waitFor(() => {
  658. expect(measurementsMetaMock).toHaveBeenCalled();
  659. });
  660. // Update location simulating a browser back button action
  661. rerender(
  662. <Results
  663. organization={organization}
  664. location={{
  665. ...router.location,
  666. query: {...generateFields(), yAxis: 'count_unique(user)'},
  667. }}
  668. router={router}
  669. loading={false}
  670. setSavedQuery={jest.fn()}
  671. />
  672. );
  673. // Should load events again
  674. expect(eventsStatsMock).toHaveBeenCalledTimes(2);
  675. expect(eventsStatsMock).toHaveBeenNthCalledWith(
  676. 2,
  677. '/organizations/org-slug/events-stats/',
  678. expect.objectContaining({
  679. query: expect.objectContaining({
  680. statsPeriod: '14d',
  681. yAxis: ['count_unique(user)'],
  682. }),
  683. })
  684. );
  685. await waitFor(() => {
  686. expect(measurementsMetaMock).toHaveBeenCalled();
  687. });
  688. });
  689. it('updates chart whenever display parameter changes', async function () {
  690. const organization = OrganizationFixture({
  691. features,
  692. });
  693. const {router} = initializeOrg({
  694. organization,
  695. router: {
  696. location: {query: {...generateFields(), display: 'default', yAxis: 'count()'}},
  697. },
  698. });
  699. const {eventsStatsMock, measurementsMetaMock} = renderMockRequests();
  700. ProjectsStore.loadInitialData([ProjectFixture()]);
  701. const {rerender} = render(
  702. <Results
  703. organization={organization}
  704. location={router.location}
  705. router={router}
  706. loading={false}
  707. setSavedQuery={jest.fn()}
  708. />,
  709. {
  710. router: router,
  711. organization,
  712. }
  713. );
  714. // Should load events once
  715. expect(eventsStatsMock).toHaveBeenCalledTimes(1);
  716. expect(eventsStatsMock).toHaveBeenNthCalledWith(
  717. 1,
  718. '/organizations/org-slug/events-stats/',
  719. expect.objectContaining({
  720. query: expect.objectContaining({
  721. statsPeriod: '14d',
  722. yAxis: ['count()'],
  723. }),
  724. })
  725. );
  726. await waitFor(() => {
  727. expect(measurementsMetaMock).toHaveBeenCalled();
  728. });
  729. // Update location simulating a browser back button action
  730. rerender(
  731. <Results
  732. organization={organization}
  733. location={{
  734. ...router.location,
  735. query: {...generateFields(), display: 'previous', yAxis: 'count()'},
  736. }}
  737. router={router}
  738. loading={false}
  739. setSavedQuery={jest.fn()}
  740. />
  741. );
  742. // Should load events again
  743. expect(eventsStatsMock).toHaveBeenCalledTimes(2);
  744. expect(eventsStatsMock).toHaveBeenNthCalledWith(
  745. 2,
  746. '/organizations/org-slug/events-stats/',
  747. expect.objectContaining({
  748. query: expect.objectContaining({
  749. statsPeriod: '28d',
  750. yAxis: ['count()'],
  751. }),
  752. })
  753. );
  754. await waitFor(() => {
  755. expect(measurementsMetaMock).toHaveBeenCalled();
  756. });
  757. });
  758. it('updates chart whenever display and yAxis parameters change', async function () {
  759. const organization = OrganizationFixture({
  760. features,
  761. });
  762. const {router} = initializeOrg({
  763. organization,
  764. router: {
  765. location: {query: {...generateFields(), display: 'default', yAxis: 'count()'}},
  766. },
  767. });
  768. const {eventsStatsMock, measurementsMetaMock} = renderMockRequests();
  769. ProjectsStore.loadInitialData([ProjectFixture()]);
  770. const {rerender} = render(
  771. <Results
  772. organization={organization}
  773. location={router.location}
  774. router={router}
  775. loading={false}
  776. setSavedQuery={jest.fn()}
  777. />,
  778. {
  779. router: router,
  780. organization,
  781. }
  782. );
  783. // Should load events once
  784. expect(eventsStatsMock).toHaveBeenCalledTimes(1);
  785. expect(eventsStatsMock).toHaveBeenNthCalledWith(
  786. 1,
  787. '/organizations/org-slug/events-stats/',
  788. expect.objectContaining({
  789. query: expect.objectContaining({
  790. statsPeriod: '14d',
  791. yAxis: ['count()'],
  792. }),
  793. })
  794. );
  795. await waitFor(() => {
  796. expect(measurementsMetaMock).toHaveBeenCalled();
  797. });
  798. // Update location simulating a browser back button action
  799. rerender(
  800. <Results
  801. organization={organization}
  802. location={{
  803. ...router.location,
  804. query: {
  805. ...generateFields(),
  806. display: 'previous',
  807. yAxis: 'count_unique(user)',
  808. },
  809. }}
  810. router={router}
  811. loading={false}
  812. setSavedQuery={jest.fn()}
  813. />
  814. );
  815. // Should load events again
  816. expect(eventsStatsMock).toHaveBeenCalledTimes(2);
  817. expect(eventsStatsMock).toHaveBeenNthCalledWith(
  818. 2,
  819. '/organizations/org-slug/events-stats/',
  820. expect.objectContaining({
  821. query: expect.objectContaining({
  822. statsPeriod: '28d',
  823. yAxis: ['count_unique(user)'],
  824. }),
  825. })
  826. );
  827. await waitFor(() => {
  828. expect(measurementsMetaMock).toHaveBeenCalled();
  829. });
  830. });
  831. it('appends tag value to existing query when clicked', async function () {
  832. const organization = OrganizationFixture({
  833. features,
  834. });
  835. const {router} = initializeOrg({
  836. organization,
  837. router: {
  838. location: {query: {...generateFields(), display: 'default', yAxis: 'count'}},
  839. },
  840. });
  841. const mockRequests = renderMockRequests();
  842. ProjectsStore.loadInitialData([ProjectFixture()]);
  843. render(
  844. <Results
  845. organization={organization}
  846. location={router.location}
  847. router={router}
  848. loading={false}
  849. setSavedQuery={jest.fn()}
  850. />,
  851. {
  852. router: router,
  853. organization,
  854. }
  855. );
  856. await userEvent.click(await screen.findByRole('button', {name: 'Show Tags'}));
  857. await waitFor(() => expect(mockRequests.eventFacetsMock).toHaveBeenCalled());
  858. // TODO(edward): update this to be less generic
  859. await userEvent.click(screen.getByText('environment'));
  860. await userEvent.click(screen.getByText('foo'));
  861. // since environment collides with the environment field, it is wrapped with `tags[...]`
  862. expect(
  863. await screen.findByRole('link', {
  864. name: 'environment, dev, 100% of all events. View events with this tag value.',
  865. })
  866. ).toBeInTheDocument();
  867. expect(
  868. screen.getByRole('link', {
  869. name: 'foo, bar, 100% of all events. View events with this tag value.',
  870. })
  871. ).toBeInTheDocument();
  872. });
  873. it('respects pinned filters for prebuilt queries', async function () {
  874. const organization = OrganizationFixture({
  875. features: [...features, 'global-views'],
  876. });
  877. const {router} = initializeOrg({
  878. organization,
  879. router: {
  880. location: {query: {...generateFields(), display: 'default', yAxis: 'count'}},
  881. },
  882. });
  883. renderMockRequests();
  884. jest.spyOn(PageFilterPersistence, 'getPageFilterStorage').mockReturnValue({
  885. state: {
  886. project: [1],
  887. environment: [],
  888. start: null,
  889. end: null,
  890. period: '14d',
  891. utc: null,
  892. },
  893. pinnedFilters: new Set(['projects']),
  894. });
  895. ProjectsStore.loadInitialData([ProjectFixture({id: '1', slug: 'Pinned Project'})]);
  896. render(
  897. <Results
  898. organization={organization}
  899. location={router.location}
  900. router={router}
  901. loading={false}
  902. setSavedQuery={jest.fn()}
  903. />,
  904. {router: router, organization}
  905. );
  906. const projectPageFilter = await screen.findByTestId('page-filter-project-selector');
  907. expect(projectPageFilter).toHaveTextContent('All Projects');
  908. });
  909. it('displays tip when events response contains a tip', async function () {
  910. renderMockRequests();
  911. MockApiClient.addMockResponse({
  912. url: '/organizations/org-slug/events/',
  913. body: {
  914. meta: {
  915. fields: {},
  916. tips: {query: 'this is a tip'},
  917. },
  918. data: [],
  919. },
  920. });
  921. const organization = OrganizationFixture({
  922. features,
  923. });
  924. const {router} = initializeOrg({
  925. organization,
  926. router: {
  927. location: {query: {...generateFields(), yAxis: 'count()'}},
  928. },
  929. });
  930. ProjectsStore.loadInitialData([ProjectFixture()]);
  931. render(
  932. <Results
  933. organization={organization}
  934. location={router.location}
  935. router={router}
  936. loading={false}
  937. setSavedQuery={jest.fn()}
  938. />,
  939. {router: router, organization}
  940. );
  941. expect(await screen.findByText('this is a tip')).toBeInTheDocument();
  942. });
  943. it('renders metric fallback alert', async function () {
  944. const organization = OrganizationFixture({
  945. features: ['discover-basic'],
  946. });
  947. const {router} = initializeOrg({
  948. organization,
  949. router: {
  950. location: {query: {fromMetric: 'true', id: '1'}},
  951. },
  952. });
  953. ProjectsStore.loadInitialData([ProjectFixture()]);
  954. renderMockRequests();
  955. render(
  956. <Results
  957. organization={organization}
  958. location={router.location}
  959. router={router}
  960. loading={false}
  961. setSavedQuery={jest.fn()}
  962. />,
  963. {
  964. router: router,
  965. organization,
  966. }
  967. );
  968. expect(
  969. await screen.findByText(
  970. /You've navigated to this page from a performance metric widget generated from processed events/
  971. )
  972. ).toBeInTheDocument();
  973. });
  974. it('renders unparameterized data banner', async function () {
  975. const organization = OrganizationFixture({
  976. features: ['discover-basic'],
  977. });
  978. const {router} = initializeOrg({
  979. organization,
  980. router: {
  981. location: {query: {showUnparameterizedBanner: 'true', id: '1'}},
  982. },
  983. });
  984. ProjectsStore.loadInitialData([ProjectFixture()]);
  985. renderMockRequests();
  986. render(
  987. <Results
  988. organization={organization}
  989. location={router.location}
  990. router={router}
  991. loading={false}
  992. setSavedQuery={jest.fn()}
  993. />,
  994. {
  995. router: router,
  996. organization,
  997. }
  998. );
  999. expect(
  1000. await screen.findByText(/These are unparameterized transactions/)
  1001. ).toBeInTheDocument();
  1002. });
  1003. it('updates the homepage query with up to date eventView when Set as Default is clicked', async () => {
  1004. const mockHomepageUpdate = MockApiClient.addMockResponse({
  1005. url: '/organizations/org-slug/discover/homepage/',
  1006. method: 'PUT',
  1007. statusCode: 200,
  1008. });
  1009. const organization = OrganizationFixture({
  1010. features: ['discover-basic', 'discover-query'],
  1011. });
  1012. const {router} = initializeOrg({
  1013. organization,
  1014. router: {
  1015. // These fields take priority and should be sent in the request
  1016. location: {query: {field: ['title', 'user'], id: '1'}},
  1017. },
  1018. });
  1019. ProjectsStore.loadInitialData([ProjectFixture()]);
  1020. renderMockRequests();
  1021. render(
  1022. <Results
  1023. organization={organization}
  1024. location={router.location}
  1025. router={router}
  1026. loading={false}
  1027. setSavedQuery={jest.fn()}
  1028. />,
  1029. {router: router, organization}
  1030. );
  1031. await waitFor(() =>
  1032. expect(screen.getByRole('button', {name: /set as default/i})).toBeEnabled()
  1033. );
  1034. await userEvent.click(screen.getByText('Set as Default'));
  1035. expect(mockHomepageUpdate).toHaveBeenCalledWith(
  1036. '/organizations/org-slug/discover/homepage/',
  1037. expect.objectContaining({
  1038. data: expect.objectContaining({
  1039. fields: ['title', 'user'],
  1040. }),
  1041. })
  1042. );
  1043. });
  1044. it('Changes the Use as Discover button to a reset button for saved query', async () => {
  1045. renderMockRequests();
  1046. MockApiClient.addMockResponse({
  1047. url: '/organizations/org-slug/discover/homepage/',
  1048. method: 'PUT',
  1049. statusCode: 200,
  1050. body: {
  1051. id: '2',
  1052. name: '',
  1053. projects: [],
  1054. version: 2,
  1055. expired: false,
  1056. dateCreated: '2021-04-08T17:53:25.195782Z',
  1057. dateUpdated: '2021-04-09T12:13:18.567264Z',
  1058. createdBy: {
  1059. id: '2',
  1060. },
  1061. environment: [],
  1062. fields: ['title', 'event.type', 'project', 'user.display', 'timestamp'],
  1063. widths: ['-1', '-1', '-1', '-1', '-1'],
  1064. range: '24h',
  1065. orderby: '-user.display',
  1066. queryDataset: 'discover',
  1067. },
  1068. });
  1069. const organization = OrganizationFixture({
  1070. features: ['discover-basic', 'discover-query'],
  1071. });
  1072. const {router} = initializeOrg({
  1073. organization,
  1074. router: {
  1075. location: {query: {id: '1'}},
  1076. },
  1077. });
  1078. ProjectsStore.loadInitialData([ProjectFixture()]);
  1079. renderMockRequests();
  1080. const {rerender} = render(
  1081. <Results
  1082. loading={false}
  1083. setSavedQuery={jest.fn()}
  1084. organization={organization}
  1085. location={router.location}
  1086. router={router}
  1087. />,
  1088. {router: router, organization}
  1089. );
  1090. await waitFor(() =>
  1091. expect(screen.getByRole('button', {name: /set as default/i})).toBeEnabled()
  1092. );
  1093. await userEvent.click(screen.getByText('Set as Default'));
  1094. expect(await screen.findByText('Remove Default')).toBeInTheDocument();
  1095. await userEvent.click(screen.getByText('Total Period'));
  1096. await userEvent.click(screen.getByText('Previous Period'));
  1097. const rerenderData = initializeOrg({
  1098. organization,
  1099. router: {
  1100. location: {query: {...router.location.query, display: 'previous'}},
  1101. },
  1102. });
  1103. rerender(
  1104. <Results
  1105. loading={false}
  1106. setSavedQuery={jest.fn()}
  1107. organization={organization}
  1108. location={rerenderData.router.location}
  1109. router={rerenderData.router}
  1110. />
  1111. );
  1112. screen.getByText('Previous Period');
  1113. expect(await screen.findByText('Set as Default')).toBeInTheDocument();
  1114. });
  1115. it('Changes the Use as Discover button to a reset button for prebuilt query', async () => {
  1116. MockApiClient.addMockResponse({
  1117. url: '/organizations/org-slug/discover/homepage/',
  1118. method: 'PUT',
  1119. statusCode: 200,
  1120. body: {...TRANSACTION_VIEWS[0], name: ''},
  1121. });
  1122. const organization = OrganizationFixture({
  1123. features: ['discover-basic', 'discover-query'],
  1124. });
  1125. const {router} = initializeOrg({
  1126. organization,
  1127. router: {
  1128. location: {
  1129. ...LocationFixture(),
  1130. query: {
  1131. ...EventView.fromNewQueryWithLocation(
  1132. TRANSACTION_VIEWS[0],
  1133. LocationFixture()
  1134. ).generateQueryStringObject(),
  1135. },
  1136. },
  1137. },
  1138. });
  1139. ProjectsStore.loadInitialData([ProjectFixture()]);
  1140. renderMockRequests();
  1141. const {rerender} = render(
  1142. <Results
  1143. organization={organization}
  1144. location={router.location}
  1145. router={router}
  1146. loading={false}
  1147. setSavedQuery={jest.fn()}
  1148. />,
  1149. {router: router, organization}
  1150. );
  1151. await screen.findAllByText(TRANSACTION_VIEWS[0].name);
  1152. await userEvent.click(screen.getByText('Set as Default'));
  1153. expect(await screen.findByText('Remove Default')).toBeInTheDocument();
  1154. await userEvent.click(screen.getByText('Total Period'));
  1155. await userEvent.click(screen.getByText('Previous Period'));
  1156. const rerenderData = initializeOrg({
  1157. organization,
  1158. router: {
  1159. location: {query: {...router.location.query, display: 'previous'}},
  1160. },
  1161. });
  1162. rerender(
  1163. <Results
  1164. organization={organization}
  1165. location={rerenderData.router.location}
  1166. router={rerenderData.router}
  1167. loading={false}
  1168. setSavedQuery={jest.fn()}
  1169. />
  1170. );
  1171. screen.getByText('Previous Period');
  1172. expect(await screen.findByText('Set as Default')).toBeInTheDocument();
  1173. });
  1174. it('links back to the homepage through the Discover breadcrumb', async () => {
  1175. const organization = OrganizationFixture({
  1176. features: ['discover-basic', 'discover-query'],
  1177. });
  1178. const {router} = initializeOrg({
  1179. organization,
  1180. router: {
  1181. location: {query: {id: '1'}},
  1182. },
  1183. });
  1184. ProjectsStore.loadInitialData([ProjectFixture()]);
  1185. const {measurementsMetaMock} = renderMockRequests();
  1186. render(
  1187. <Results
  1188. organization={organization}
  1189. location={router.location}
  1190. router={router}
  1191. loading={false}
  1192. setSavedQuery={jest.fn()}
  1193. />,
  1194. {router: router, organization}
  1195. );
  1196. await waitFor(() => {
  1197. expect(measurementsMetaMock).toHaveBeenCalled();
  1198. });
  1199. expect(screen.getByText('Discover')).toHaveAttribute(
  1200. 'href',
  1201. expect.stringMatching(new RegExp('^/organizations/org-slug/discover/homepage/'))
  1202. );
  1203. });
  1204. it('links back to the Saved Queries through the Saved Queries breadcrumb', async () => {
  1205. const organization = OrganizationFixture({
  1206. features: ['discover-basic', 'discover-query'],
  1207. });
  1208. const {router} = initializeOrg({
  1209. organization,
  1210. router: {
  1211. location: {query: {id: '1'}},
  1212. },
  1213. });
  1214. const {measurementsMetaMock} = renderMockRequests();
  1215. render(
  1216. <Results
  1217. organization={organization}
  1218. location={router.location}
  1219. router={router}
  1220. loading={false}
  1221. setSavedQuery={jest.fn()}
  1222. />,
  1223. {router: router, organization}
  1224. );
  1225. await waitFor(() => {
  1226. expect(measurementsMetaMock).toHaveBeenCalled();
  1227. });
  1228. expect(screen.getByRole('link', {name: 'Saved Queries'})).toHaveAttribute(
  1229. 'href',
  1230. expect.stringMatching(new RegExp('^/organizations/org-slug/discover/queries/'))
  1231. );
  1232. });
  1233. it('allows users to Set As Default on the All Events query', async () => {
  1234. const organization = OrganizationFixture({
  1235. features: ['discover-basic', 'discover-query'],
  1236. });
  1237. const {router} = initializeOrg({
  1238. organization,
  1239. router: {
  1240. location: {
  1241. ...LocationFixture(),
  1242. query: {
  1243. ...EventView.fromNewQueryWithLocation(
  1244. DEFAULT_EVENT_VIEW,
  1245. LocationFixture()
  1246. ).generateQueryStringObject(),
  1247. },
  1248. },
  1249. },
  1250. });
  1251. ProjectsStore.loadInitialData([ProjectFixture()]);
  1252. const {measurementsMetaMock} = renderMockRequests();
  1253. render(
  1254. <Results
  1255. organization={organization}
  1256. location={router.location}
  1257. router={router}
  1258. loading={false}
  1259. setSavedQuery={jest.fn()}
  1260. />,
  1261. {router: router, organization}
  1262. );
  1263. await waitFor(() => {
  1264. expect(measurementsMetaMock).toHaveBeenCalled();
  1265. });
  1266. expect(screen.getByTestId('set-as-default')).toBeEnabled();
  1267. });
  1268. it("doesn't render sample data alert", async function () {
  1269. const organization = OrganizationFixture({
  1270. features: ['discover-basic', 'discover-query'],
  1271. });
  1272. const {router} = initializeOrg({
  1273. organization,
  1274. router: {
  1275. location: {
  1276. ...LocationFixture(),
  1277. query: {
  1278. ...EventView.fromNewQueryWithLocation(
  1279. {...DEFAULT_EVENT_VIEW, query: 'event.type:error'},
  1280. LocationFixture()
  1281. ).generateQueryStringObject(),
  1282. },
  1283. },
  1284. },
  1285. });
  1286. const {measurementsMetaMock} = renderMockRequests();
  1287. render(
  1288. <Results
  1289. organization={organization}
  1290. location={router.location}
  1291. router={router}
  1292. loading={false}
  1293. setSavedQuery={jest.fn()}
  1294. />,
  1295. {router: router, organization}
  1296. );
  1297. await waitFor(() => {
  1298. expect(measurementsMetaMock).toHaveBeenCalled();
  1299. });
  1300. expect(screen.queryByText(/Based on your search criteria/)).not.toBeInTheDocument();
  1301. });
  1302. it('uses split decision to populate dataset selector', async function () {
  1303. const organization = OrganizationFixture({
  1304. features: [
  1305. 'discover-basic',
  1306. 'discover-query',
  1307. 'performance-discover-dataset-selector',
  1308. ],
  1309. });
  1310. const {router} = initializeOrg({
  1311. organization,
  1312. router: {
  1313. location: {query: {id: '1'}},
  1314. },
  1315. });
  1316. ProjectsStore.loadInitialData([ProjectFixture()]);
  1317. const mockRequests = renderMockRequests();
  1318. render(
  1319. <Results
  1320. organization={organization}
  1321. location={router.location}
  1322. router={router}
  1323. loading={false}
  1324. setSavedQuery={jest.fn()}
  1325. />,
  1326. {
  1327. router: router,
  1328. organization,
  1329. }
  1330. );
  1331. await waitFor(() => {
  1332. expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
  1333. });
  1334. expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(1);
  1335. await waitFor(() => {
  1336. expect(
  1337. screen.getByRole('button', {name: 'Dataset Transactions'})
  1338. ).toBeInTheDocument();
  1339. });
  1340. expect(
  1341. screen.getByText(
  1342. "We're splitting our datasets up to make it a bit easier to digest. We defaulted this query to Transactions. Edit as you see fit."
  1343. )
  1344. ).toBeInTheDocument();
  1345. expect(screen.queryByText('Save Changes')).not.toBeInTheDocument();
  1346. });
  1347. it('calls events endpoint with the right dataset', async function () {
  1348. const organization = OrganizationFixture({
  1349. features: [
  1350. 'discover-basic',
  1351. 'discover-query',
  1352. 'performance-discover-dataset-selector',
  1353. ],
  1354. });
  1355. const {router} = initializeOrg({
  1356. organization,
  1357. router: {
  1358. location: {query: {id: '1'}},
  1359. },
  1360. });
  1361. ProjectsStore.loadInitialData([ProjectFixture()]);
  1362. const mockRequests = renderMockRequests();
  1363. MockApiClient.addMockResponse({
  1364. url: '/organizations/org-slug/discover/saved/1/',
  1365. method: 'GET',
  1366. statusCode: 200,
  1367. body: {
  1368. id: '1',
  1369. name: 'new',
  1370. projects: [],
  1371. version: 2,
  1372. expired: false,
  1373. dateCreated: '2021-04-08T17:53:25.195782Z',
  1374. dateUpdated: '2021-04-09T12:13:18.567264Z',
  1375. createdBy: {
  1376. id: '2',
  1377. },
  1378. environment: [],
  1379. fields: ['title', 'event.type', 'project', 'user.display', 'timestamp'],
  1380. widths: ['-1', '-1', '-1', '-1', '-1'],
  1381. range: '24h',
  1382. orderby: '-user.display',
  1383. queryDataset: 'error-events',
  1384. },
  1385. });
  1386. render(
  1387. <Results
  1388. organization={organization}
  1389. location={router.location}
  1390. router={router}
  1391. loading={false}
  1392. setSavedQuery={jest.fn()}
  1393. />,
  1394. {
  1395. router: router,
  1396. organization,
  1397. }
  1398. );
  1399. await waitFor(() => {
  1400. expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
  1401. });
  1402. expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(1);
  1403. expect(screen.getByRole('button', {name: 'Dataset Errors'})).toBeInTheDocument();
  1404. expect(mockRequests.eventsStatsMock).toHaveBeenCalledWith(
  1405. '/organizations/org-slug/events-stats/',
  1406. expect.objectContaining({
  1407. query: expect.objectContaining({
  1408. dataset: 'errors',
  1409. }),
  1410. })
  1411. );
  1412. expect(mockRequests.eventsResultsMock).toHaveBeenCalledWith(
  1413. '/organizations/org-slug/events/',
  1414. expect.objectContaining({
  1415. query: expect.objectContaining({
  1416. dataset: 'errors',
  1417. }),
  1418. })
  1419. );
  1420. expect(mockRequests.eventsMetaMock).toHaveBeenCalledWith(
  1421. '/organizations/org-slug/events-meta/',
  1422. expect.objectContaining({
  1423. query: expect.objectContaining({
  1424. dataset: 'errors',
  1425. }),
  1426. })
  1427. );
  1428. });
  1429. it('does not automatically append dataset with selector feature disabled', async function () {
  1430. const organization = OrganizationFixture({
  1431. features: ['discover-basic', 'discover-query'],
  1432. });
  1433. const {router} = initializeOrg({
  1434. organization,
  1435. router: {
  1436. location: {query: {id: '1'}},
  1437. },
  1438. });
  1439. ProjectsStore.loadInitialData([ProjectFixture()]);
  1440. const mockRequests = renderMockRequests();
  1441. MockApiClient.addMockResponse({
  1442. url: '/organizations/org-slug/discover/saved/1/',
  1443. method: 'GET',
  1444. statusCode: 200,
  1445. body: {
  1446. id: '1',
  1447. name: 'new',
  1448. projects: [],
  1449. version: 2,
  1450. expired: false,
  1451. dateCreated: '2021-04-08T17:53:25.195782Z',
  1452. dateUpdated: '2021-04-09T12:13:18.567264Z',
  1453. createdBy: {
  1454. id: '2',
  1455. },
  1456. environment: [],
  1457. fields: ['title', 'event.type', 'project', 'user.display', 'timestamp'],
  1458. widths: ['-1', '-1', '-1', '-1', '-1'],
  1459. range: '24h',
  1460. orderby: '-user.display',
  1461. queryDataset: 'error-events',
  1462. },
  1463. });
  1464. render(
  1465. <Results
  1466. organization={organization}
  1467. location={router.location}
  1468. router={router}
  1469. loading={false}
  1470. setSavedQuery={jest.fn()}
  1471. />,
  1472. {
  1473. router: router,
  1474. organization,
  1475. }
  1476. );
  1477. await waitFor(() => {
  1478. expect(mockRequests.measurementsMetaMock).toHaveBeenCalled();
  1479. });
  1480. expect(mockRequests.eventsResultsMock).toHaveBeenCalledTimes(1);
  1481. expect(
  1482. screen.queryByRole('button', {name: 'Dataset Errors'})
  1483. ).not.toBeInTheDocument();
  1484. expect(mockRequests.eventsStatsMock).toHaveBeenCalledWith(
  1485. '/organizations/org-slug/events-stats/',
  1486. expect.objectContaining({
  1487. query: expect.not.objectContaining({
  1488. dataset: 'errors',
  1489. }),
  1490. })
  1491. );
  1492. expect(mockRequests.eventsResultsMock).toHaveBeenCalledWith(
  1493. '/organizations/org-slug/events/',
  1494. expect.objectContaining({
  1495. query: expect.not.objectContaining({
  1496. dataset: 'errors',
  1497. }),
  1498. })
  1499. );
  1500. expect(mockRequests.eventsMetaMock).toHaveBeenCalledWith(
  1501. '/organizations/org-slug/events-meta/',
  1502. expect.objectContaining({
  1503. query: expect.not.objectContaining({
  1504. dataset: 'errors',
  1505. }),
  1506. })
  1507. );
  1508. });
  1509. });
  1510. });