detail.spec.tsx 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540
  1. import {browserHistory} from 'react-router';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {
  4. act,
  5. render,
  6. screen,
  7. userEvent,
  8. waitFor,
  9. within,
  10. } from 'sentry-test/reactTestingLibrary';
  11. import * as modals from 'sentry/actionCreators/modal';
  12. import ProjectsStore from 'sentry/stores/projectsStore';
  13. import CreateDashboard from 'sentry/views/dashboards/create';
  14. import * as types from 'sentry/views/dashboards/types';
  15. import ViewEditDashboard from 'sentry/views/dashboards/view';
  16. import {OrganizationContext} from 'sentry/views/organizationContext';
  17. describe('Dashboards > Detail', function () {
  18. const organization = TestStubs.Organization({
  19. features: ['global-views', 'dashboards-basic', 'dashboards-edit', 'discover-query'],
  20. });
  21. const projects = [TestStubs.Project()];
  22. describe('prebuilt dashboards', function () {
  23. let initialData;
  24. beforeEach(function () {
  25. act(() => ProjectsStore.loadInitialData(projects));
  26. initialData = initializeOrg({organization});
  27. MockApiClient.addMockResponse({
  28. url: '/organizations/org-slug/tags/',
  29. body: [],
  30. });
  31. MockApiClient.addMockResponse({
  32. url: '/organizations/org-slug/projects/',
  33. body: [TestStubs.Project()],
  34. });
  35. MockApiClient.addMockResponse({
  36. url: '/organizations/org-slug/dashboards/',
  37. body: [
  38. TestStubs.Dashboard([], {id: 'default-overview', title: 'Default'}),
  39. TestStubs.Dashboard([], {id: '1', title: 'Custom Errors'}),
  40. ],
  41. });
  42. MockApiClient.addMockResponse({
  43. url: '/organizations/org-slug/dashboards/default-overview/',
  44. body: TestStubs.Dashboard([], {id: 'default-overview', title: 'Default'}),
  45. });
  46. MockApiClient.addMockResponse({
  47. url: '/organizations/org-slug/dashboards/1/visit/',
  48. method: 'POST',
  49. body: [],
  50. statusCode: 200,
  51. });
  52. MockApiClient.addMockResponse({
  53. url: '/organizations/org-slug/users/',
  54. method: 'GET',
  55. body: [],
  56. });
  57. MockApiClient.addMockResponse({
  58. url: '/organizations/org-slug/sdk-updates/',
  59. body: [],
  60. });
  61. MockApiClient.addMockResponse({
  62. url: '/prompts-activity/',
  63. body: {},
  64. });
  65. MockApiClient.addMockResponse({
  66. url: '/organizations/org-slug/events/',
  67. method: 'GET',
  68. body: [],
  69. });
  70. MockApiClient.addMockResponse({
  71. url: '/organizations/org-slug/events-stats/',
  72. body: {data: []},
  73. });
  74. MockApiClient.addMockResponse({
  75. method: 'GET',
  76. url: '/organizations/org-slug/issues/',
  77. body: [],
  78. });
  79. MockApiClient.addMockResponse({
  80. url: '/organizations/org-slug/releases/',
  81. body: [],
  82. });
  83. });
  84. afterEach(function () {
  85. MockApiClient.clearMockResponses();
  86. });
  87. it('assigns unique IDs to all widgets so grid keys are unique', async function () {
  88. MockApiClient.addMockResponse({
  89. url: '/organizations/org-slug/events-stats/',
  90. body: {data: []},
  91. });
  92. MockApiClient.addMockResponse({
  93. url: '/organizations/org-slug/dashboards/default-overview/',
  94. body: TestStubs.Dashboard(
  95. [
  96. TestStubs.Widget(
  97. [
  98. {
  99. name: '',
  100. conditions: 'event.type:error',
  101. fields: ['count()'],
  102. aggregates: ['count()'],
  103. columns: [],
  104. },
  105. ],
  106. {
  107. title: 'Default Widget 1',
  108. interval: '1d',
  109. }
  110. ),
  111. TestStubs.Widget(
  112. [
  113. {
  114. name: '',
  115. conditions: 'event.type:transaction',
  116. fields: ['count()'],
  117. aggregates: ['count()'],
  118. columns: [],
  119. },
  120. ],
  121. {
  122. title: 'Default Widget 2',
  123. interval: '1d',
  124. }
  125. ),
  126. ],
  127. {id: 'default-overview', title: 'Default'}
  128. ),
  129. });
  130. initialData = initializeOrg({
  131. organization: TestStubs.Organization({
  132. features: ['global-views', 'dashboards-basic', 'discover-query'],
  133. projects: [TestStubs.Project()],
  134. }),
  135. });
  136. render(
  137. <OrganizationContext.Provider value={initialData.organization}>
  138. <ViewEditDashboard
  139. {...TestStubs.routeComponentProps()}
  140. organization={initialData.organization}
  141. params={{orgId: 'org-slug', dashboardId: 'default-overview'}}
  142. router={initialData.router}
  143. location={initialData.router.location}
  144. >
  145. {null}
  146. </ViewEditDashboard>
  147. </OrganizationContext.Provider>,
  148. {context: initialData.routerContext}
  149. );
  150. expect(await screen.findByText('Default Widget 1')).toBeInTheDocument();
  151. expect(screen.getByText('Default Widget 2')).toBeInTheDocument();
  152. });
  153. it('opens the widget viewer modal in a prebuilt dashboard using the widget id specified in the url', async () => {
  154. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  155. render(
  156. <CreateDashboard
  157. {...TestStubs.routeComponentProps()}
  158. organization={initialData.organization}
  159. params={{templateId: 'default-template', widgetId: '2'}}
  160. router={initialData.router}
  161. location={{...initialData.router.location, pathname: '/widget/2/'}}
  162. >
  163. {null}
  164. </CreateDashboard>,
  165. {context: initialData.routerContext, organization: initialData.organization}
  166. );
  167. await waitFor(() => {
  168. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  169. expect.objectContaining({
  170. organization: initialData.organization,
  171. widget: expect.objectContaining({
  172. displayType: 'line',
  173. interval: '5m',
  174. queries: [
  175. {
  176. aggregates: ['count()'],
  177. columns: [],
  178. conditions: '!event.type:transaction',
  179. fields: ['count()'],
  180. name: 'Events',
  181. orderby: 'count()',
  182. },
  183. ],
  184. title: 'Events',
  185. widgetType: 'discover',
  186. }),
  187. onClose: expect.anything(),
  188. })
  189. );
  190. });
  191. });
  192. });
  193. describe('custom dashboards', function () {
  194. let initialData, widgets, mockVisit, mockPut;
  195. beforeEach(function () {
  196. window.confirm = jest.fn();
  197. initialData = initializeOrg({
  198. organization,
  199. router: {
  200. location: TestStubs.location(),
  201. },
  202. });
  203. widgets = [
  204. TestStubs.Widget(
  205. [
  206. {
  207. name: '',
  208. conditions: 'event.type:error',
  209. fields: ['count()'],
  210. columns: [],
  211. aggregates: ['count()'],
  212. },
  213. ],
  214. {
  215. title: 'Errors',
  216. interval: '1d',
  217. widgetType: 'discover',
  218. id: '1',
  219. }
  220. ),
  221. TestStubs.Widget(
  222. [
  223. {
  224. name: '',
  225. conditions: 'event.type:transaction',
  226. fields: ['count()'],
  227. columns: [],
  228. aggregates: ['count()'],
  229. },
  230. ],
  231. {
  232. title: 'Transactions',
  233. interval: '1d',
  234. widgetType: 'discover',
  235. id: '2',
  236. }
  237. ),
  238. TestStubs.Widget(
  239. [
  240. {
  241. name: '',
  242. conditions: 'event.type:transaction transaction:/api/cats',
  243. fields: ['p50()'],
  244. columns: [],
  245. aggregates: ['p50()'],
  246. },
  247. ],
  248. {
  249. title: 'p50 of /api/cats',
  250. interval: '1d',
  251. id: '3',
  252. }
  253. ),
  254. ];
  255. mockVisit = MockApiClient.addMockResponse({
  256. url: '/organizations/org-slug/dashboards/1/visit/',
  257. method: 'POST',
  258. body: [],
  259. statusCode: 200,
  260. });
  261. MockApiClient.addMockResponse({
  262. url: '/organizations/org-slug/tags/',
  263. body: [],
  264. });
  265. MockApiClient.addMockResponse({
  266. url: '/organizations/org-slug/projects/',
  267. body: [TestStubs.Project()],
  268. });
  269. MockApiClient.addMockResponse({
  270. url: '/organizations/org-slug/dashboards/',
  271. body: [
  272. TestStubs.Dashboard([], {
  273. id: 'default-overview',
  274. title: 'Default',
  275. widgetDisplay: ['area'],
  276. }),
  277. TestStubs.Dashboard([], {
  278. id: '1',
  279. title: 'Custom Errors',
  280. widgetDisplay: ['area'],
  281. }),
  282. ],
  283. });
  284. MockApiClient.addMockResponse({
  285. url: '/organizations/org-slug/dashboards/1/',
  286. body: TestStubs.Dashboard(widgets, {
  287. id: '1',
  288. title: 'Custom Errors',
  289. filters: {},
  290. }),
  291. });
  292. mockPut = MockApiClient.addMockResponse({
  293. url: '/organizations/org-slug/dashboards/1/',
  294. method: 'PUT',
  295. body: TestStubs.Dashboard(widgets, {id: '1', title: 'Custom Errors'}),
  296. });
  297. MockApiClient.addMockResponse({
  298. url: '/organizations/org-slug/events-stats/',
  299. body: {data: []},
  300. });
  301. MockApiClient.addMockResponse({
  302. method: 'POST',
  303. url: '/organizations/org-slug/dashboards/widgets/',
  304. body: [],
  305. });
  306. MockApiClient.addMockResponse({
  307. method: 'GET',
  308. url: '/organizations/org-slug/recent-searches/',
  309. body: [],
  310. });
  311. MockApiClient.addMockResponse({
  312. method: 'GET',
  313. url: '/organizations/org-slug/issues/',
  314. body: [],
  315. });
  316. MockApiClient.addMockResponse({
  317. url: '/organizations/org-slug/events/',
  318. method: 'GET',
  319. body: [],
  320. });
  321. MockApiClient.addMockResponse({
  322. url: '/organizations/org-slug/users/',
  323. method: 'GET',
  324. body: [],
  325. });
  326. MockApiClient.addMockResponse({
  327. url: '/organizations/org-slug/releases/',
  328. body: [],
  329. });
  330. MockApiClient.addMockResponse({
  331. url: '/organizations/org-slug/sdk-updates/',
  332. body: [],
  333. });
  334. MockApiClient.addMockResponse({
  335. url: '/prompts-activity/',
  336. body: {},
  337. });
  338. });
  339. afterEach(function () {
  340. MockApiClient.clearMockResponses();
  341. jest.clearAllMocks();
  342. });
  343. it('can remove widgets', async function () {
  344. const updateMock = MockApiClient.addMockResponse({
  345. url: '/organizations/org-slug/dashboards/1/',
  346. method: 'PUT',
  347. body: TestStubs.Dashboard([widgets[0]], {id: '1', title: 'Custom Errors'}),
  348. });
  349. render(
  350. <OrganizationContext.Provider value={initialData.organization}>
  351. <ViewEditDashboard
  352. {...TestStubs.routeComponentProps()}
  353. organization={initialData.organization}
  354. params={{orgId: 'org-slug', dashboardId: '1'}}
  355. router={initialData.router}
  356. location={initialData.router.location}
  357. >
  358. {null}
  359. </ViewEditDashboard>
  360. </OrganizationContext.Provider>,
  361. {context: initialData.routerContext}
  362. );
  363. await waitFor(() => expect(mockVisit).toHaveBeenCalledTimes(1));
  364. // Enter edit mode.
  365. await userEvent.click(screen.getByRole('button', {name: 'Edit Dashboard'}));
  366. // Remove the second and third widgets
  367. await userEvent.click(screen.getAllByRole('button', {name: 'Delete Widget'})[1]);
  368. await userEvent.click(screen.getAllByRole('button', {name: 'Delete Widget'})[1]);
  369. // Save changes
  370. await userEvent.click(screen.getByRole('button', {name: 'Save and Finish'}));
  371. expect(updateMock).toHaveBeenCalled();
  372. expect(updateMock).toHaveBeenCalledWith(
  373. '/organizations/org-slug/dashboards/1/',
  374. expect.objectContaining({
  375. data: expect.objectContaining({
  376. title: 'Custom Errors',
  377. widgets: [expect.objectContaining(widgets[0])],
  378. }),
  379. })
  380. );
  381. // Visit should not be called again on dashboard update
  382. expect(mockVisit).toHaveBeenCalledTimes(1);
  383. });
  384. it('appends dashboard-level filters to series request', async function () {
  385. MockApiClient.addMockResponse({
  386. url: '/organizations/org-slug/dashboards/1/',
  387. body: TestStubs.Dashboard(widgets, {
  388. id: '1',
  389. title: 'Custom Errors',
  390. filters: {release: ['abc@1.2.0']},
  391. }),
  392. });
  393. const mock = MockApiClient.addMockResponse({
  394. url: '/organizations/org-slug/events-stats/',
  395. body: [],
  396. });
  397. render(
  398. <OrganizationContext.Provider value={initialData.organization}>
  399. <ViewEditDashboard
  400. {...TestStubs.routeComponentProps()}
  401. organization={initialData.organization}
  402. params={{orgId: 'org-slug', dashboardId: '1'}}
  403. router={initialData.router}
  404. location={initialData.router.location}
  405. >
  406. {null}
  407. </ViewEditDashboard>
  408. </OrganizationContext.Provider>,
  409. {context: initialData.routerContext}
  410. );
  411. await waitFor(() =>
  412. expect(mock).toHaveBeenLastCalledWith(
  413. '/organizations/org-slug/events-stats/',
  414. expect.objectContaining({
  415. query: expect.objectContaining({
  416. query: 'event.type:transaction transaction:/api/cats release:abc@1.2.0 ',
  417. }),
  418. })
  419. )
  420. );
  421. });
  422. it('shows add widget option', async function () {
  423. render(
  424. <OrganizationContext.Provider value={initialData.organization}>
  425. <ViewEditDashboard
  426. {...TestStubs.routeComponentProps()}
  427. organization={initialData.organization}
  428. params={{orgId: 'org-slug', dashboardId: '1'}}
  429. router={initialData.router}
  430. location={initialData.router.location}
  431. >
  432. {null}
  433. </ViewEditDashboard>
  434. </OrganizationContext.Provider>,
  435. {context: initialData.routerContext}
  436. );
  437. // Enter edit mode.
  438. await userEvent.click(screen.getByRole('button', {name: 'Edit Dashboard'}));
  439. expect(await screen.findByRole('button', {name: 'Add widget'})).toBeInTheDocument();
  440. });
  441. it('shows top level release filter', async function () {
  442. const mockReleases = MockApiClient.addMockResponse({
  443. url: '/organizations/org-slug/releases/',
  444. body: [TestStubs.Release()],
  445. });
  446. initialData = initializeOrg({
  447. organization: TestStubs.Organization({
  448. features: [
  449. 'global-views',
  450. 'dashboards-basic',
  451. 'dashboards-edit',
  452. 'discover-query',
  453. ],
  454. projects: [TestStubs.Project()],
  455. }),
  456. });
  457. render(
  458. <OrganizationContext.Provider value={initialData.organization}>
  459. <ViewEditDashboard
  460. {...TestStubs.routeComponentProps()}
  461. organization={initialData.organization}
  462. params={{orgId: 'org-slug', dashboardId: '1'}}
  463. router={initialData.router}
  464. location={initialData.router.location}
  465. >
  466. {null}
  467. </ViewEditDashboard>
  468. </OrganizationContext.Provider>,
  469. {context: initialData.routerContext}
  470. );
  471. expect(await screen.findByText('All Releases')).toBeInTheDocument();
  472. expect(mockReleases).toHaveBeenCalledTimes(1);
  473. });
  474. it('hides add widget option', async function () {
  475. // @ts-expect-error this is assigning to readonly property...
  476. types.MAX_WIDGETS = 1;
  477. render(
  478. <OrganizationContext.Provider value={initialData.organization}>
  479. <ViewEditDashboard
  480. {...TestStubs.routeComponentProps()}
  481. organization={initialData.organization}
  482. params={{orgId: 'org-slug', dashboardId: '1'}}
  483. router={initialData.router}
  484. location={initialData.router.location}
  485. >
  486. {null}
  487. </ViewEditDashboard>
  488. </OrganizationContext.Provider>,
  489. {context: initialData.routerContext}
  490. );
  491. // Enter edit mode.
  492. await userEvent.click(await screen.findByRole('button', {name: 'Edit Dashboard'}));
  493. expect(screen.queryByRole('button', {name: 'Add widget'})).not.toBeInTheDocument();
  494. });
  495. it('renders successfully if more widgets than stored layouts', async function () {
  496. // A case where someone has async added widgets to a dashboard
  497. MockApiClient.addMockResponse({
  498. url: '/organizations/org-slug/dashboards/1/',
  499. body: TestStubs.Dashboard(
  500. [
  501. TestStubs.Widget(
  502. [
  503. {
  504. name: '',
  505. conditions: 'event.type:error',
  506. fields: ['count()'],
  507. aggregates: ['count()'],
  508. columns: [],
  509. },
  510. ],
  511. {
  512. title: 'First Widget',
  513. interval: '1d',
  514. id: '1',
  515. layout: {i: 'grid-item-1', x: 0, y: 0, w: 2, h: 6},
  516. }
  517. ),
  518. TestStubs.Widget(
  519. [
  520. {
  521. name: '',
  522. conditions: 'event.type:error',
  523. fields: ['count()'],
  524. aggregates: ['count()'],
  525. columns: [],
  526. },
  527. ],
  528. {
  529. title: 'Second Widget',
  530. interval: '1d',
  531. id: '2',
  532. }
  533. ),
  534. ],
  535. {id: '1', title: 'Custom Errors'}
  536. ),
  537. });
  538. render(
  539. <ViewEditDashboard
  540. {...TestStubs.routeComponentProps()}
  541. organization={initialData.organization}
  542. params={{orgId: 'org-slug', dashboardId: '1'}}
  543. router={initialData.router}
  544. location={initialData.router.location}
  545. >
  546. {null}
  547. </ViewEditDashboard>,
  548. {context: initialData.routerContext, organization: initialData.organization}
  549. );
  550. expect(await screen.findByText('First Widget')).toBeInTheDocument();
  551. expect(await screen.findByText('Second Widget')).toBeInTheDocument();
  552. });
  553. it('does not trigger request if layout not updated', async () => {
  554. MockApiClient.addMockResponse({
  555. url: '/organizations/org-slug/dashboards/1/',
  556. body: TestStubs.Dashboard(
  557. [
  558. TestStubs.Widget(
  559. [
  560. {
  561. name: '',
  562. conditions: 'event.type:error',
  563. fields: ['count()'],
  564. aggregates: ['count()'],
  565. columns: [],
  566. },
  567. ],
  568. {
  569. title: 'First Widget',
  570. interval: '1d',
  571. id: '1',
  572. layout: {i: 'grid-item-1', x: 0, y: 0, w: 2, h: 6},
  573. }
  574. ),
  575. ],
  576. {id: '1', title: 'Custom Errors'}
  577. ),
  578. });
  579. render(
  580. <ViewEditDashboard
  581. {...TestStubs.routeComponentProps()}
  582. organization={initialData.organization}
  583. params={{orgId: 'org-slug', dashboardId: '1'}}
  584. router={initialData.router}
  585. location={initialData.router.location}
  586. >
  587. {null}
  588. </ViewEditDashboard>,
  589. {context: initialData.routerContext, organization: initialData.organization}
  590. );
  591. await userEvent.click(await screen.findByText('Edit Dashboard'));
  592. await userEvent.click(await screen.findByText('Save and Finish'));
  593. expect(screen.getByText('Edit Dashboard')).toBeInTheDocument();
  594. expect(mockPut).not.toHaveBeenCalled();
  595. });
  596. it('renders the custom resize handler for a widget', async () => {
  597. MockApiClient.addMockResponse({
  598. url: '/organizations/org-slug/dashboards/1/',
  599. body: TestStubs.Dashboard(
  600. [
  601. TestStubs.Widget(
  602. [
  603. {
  604. name: '',
  605. conditions: 'event.type:error',
  606. fields: ['count()'],
  607. aggregates: ['count()'],
  608. columns: [],
  609. },
  610. ],
  611. {
  612. title: 'First Widget',
  613. interval: '1d',
  614. id: '1',
  615. layout: {i: 'grid-item-1', x: 0, y: 0, w: 2, h: 6},
  616. }
  617. ),
  618. ],
  619. {id: '1', title: 'Custom Errors'}
  620. ),
  621. });
  622. render(
  623. <ViewEditDashboard
  624. {...TestStubs.routeComponentProps()}
  625. organization={initialData.organization}
  626. params={{orgId: 'org-slug', dashboardId: '1'}}
  627. router={initialData.router}
  628. location={initialData.router.location}
  629. >
  630. {null}
  631. </ViewEditDashboard>,
  632. {context: initialData.routerContext, organization: initialData.organization}
  633. );
  634. await userEvent.click(await screen.findByText('Edit Dashboard'));
  635. const widget = screen
  636. .getByText('First Widget')
  637. .closest('.react-grid-item') as HTMLElement;
  638. const resizeHandle = within(widget).getByTestId('custom-resize-handle');
  639. expect(resizeHandle).toBeVisible();
  640. });
  641. it('does not trigger an alert when the widgets have no layout and user cancels without changes', async () => {
  642. MockApiClient.addMockResponse({
  643. url: '/organizations/org-slug/dashboards/1/',
  644. body: TestStubs.Dashboard(
  645. [
  646. TestStubs.Widget(
  647. [
  648. {
  649. name: '',
  650. conditions: 'event.type:error',
  651. fields: ['count()'],
  652. aggregates: ['count()'],
  653. columns: [],
  654. },
  655. ],
  656. {
  657. title: 'First Widget',
  658. interval: '1d',
  659. id: '1',
  660. layout: null,
  661. }
  662. ),
  663. ],
  664. {id: '1', title: 'Custom Errors'}
  665. ),
  666. });
  667. render(
  668. <ViewEditDashboard
  669. {...TestStubs.routeComponentProps()}
  670. organization={initialData.organization}
  671. params={{orgId: 'org-slug', dashboardId: '1'}}
  672. router={initialData.router}
  673. location={initialData.router.location}
  674. >
  675. {null}
  676. </ViewEditDashboard>,
  677. {context: initialData.routerContext, organization: initialData.organization}
  678. );
  679. await userEvent.click(await screen.findByText('Edit Dashboard'));
  680. await userEvent.click(await screen.findByText('Cancel'));
  681. expect(window.confirm).not.toHaveBeenCalled();
  682. });
  683. it('opens the widget viewer modal using the widget id specified in the url', async () => {
  684. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  685. const widget = TestStubs.Widget(
  686. [
  687. {
  688. name: '',
  689. conditions: 'event.type:error',
  690. fields: ['count()'],
  691. aggregates: ['count()'],
  692. columns: [],
  693. orderby: '',
  694. },
  695. ],
  696. {
  697. title: 'First Widget',
  698. interval: '1d',
  699. id: '1',
  700. layout: null,
  701. }
  702. );
  703. MockApiClient.addMockResponse({
  704. url: '/organizations/org-slug/dashboards/1/',
  705. body: TestStubs.Dashboard([widget], {id: '1', title: 'Custom Errors'}),
  706. });
  707. render(
  708. <ViewEditDashboard
  709. {...TestStubs.routeComponentProps()}
  710. organization={initialData.organization}
  711. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 1}}
  712. router={initialData.router}
  713. location={{...initialData.router.location, pathname: '/widget/123/'}}
  714. >
  715. {null}
  716. </ViewEditDashboard>,
  717. {context: initialData.routerContext, organization: initialData.organization}
  718. );
  719. await waitFor(() => {
  720. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  721. expect.objectContaining({
  722. organization: initialData.organization,
  723. widget,
  724. onClose: expect.anything(),
  725. })
  726. );
  727. });
  728. });
  729. it('redirects user to dashboard url if widget is not found', async () => {
  730. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  731. MockApiClient.addMockResponse({
  732. url: '/organizations/org-slug/dashboards/1/',
  733. body: TestStubs.Dashboard([], {id: '1', title: 'Custom Errors'}),
  734. });
  735. render(
  736. <ViewEditDashboard
  737. {...TestStubs.routeComponentProps()}
  738. organization={initialData.organization}
  739. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 123}}
  740. router={initialData.router}
  741. location={{...initialData.router.location, pathname: '/widget/123/'}}
  742. >
  743. {null}
  744. </ViewEditDashboard>,
  745. {context: initialData.routerContext, organization: initialData.organization}
  746. );
  747. expect(await screen.findByText('All Releases')).toBeInTheDocument();
  748. expect(openWidgetViewerModal).not.toHaveBeenCalled();
  749. expect(initialData.router.replace).toHaveBeenCalledWith(
  750. expect.objectContaining({
  751. pathname: '/organizations/org-slug/dashboard/1/',
  752. query: {},
  753. })
  754. );
  755. });
  756. it('saves a new dashboard with the page filters', async () => {
  757. const mockPOST = MockApiClient.addMockResponse({
  758. url: '/organizations/org-slug/dashboards/',
  759. method: 'POST',
  760. body: [],
  761. });
  762. render(
  763. <CreateDashboard
  764. {...TestStubs.routeComponentProps()}
  765. organization={initialData.organization}
  766. params={{templateId: undefined}}
  767. router={initialData.router}
  768. location={{
  769. ...initialData.router.location,
  770. query: {
  771. ...initialData.router.location.query,
  772. statsPeriod: '7d',
  773. project: [2],
  774. environment: ['alpha', 'beta'],
  775. },
  776. }}
  777. >
  778. {null}
  779. </CreateDashboard>,
  780. {
  781. context: initialData.routerContext,
  782. organization: initialData.organization,
  783. }
  784. );
  785. await userEvent.click(await screen.findByText('Save and Finish'));
  786. expect(mockPOST).toHaveBeenCalledWith(
  787. '/organizations/org-slug/dashboards/',
  788. expect.objectContaining({
  789. data: expect.objectContaining({
  790. projects: [2],
  791. environment: ['alpha', 'beta'],
  792. period: '7d',
  793. }),
  794. })
  795. );
  796. });
  797. it('saves a template with the page filters', async () => {
  798. const mockPOST = MockApiClient.addMockResponse({
  799. url: '/organizations/org-slug/dashboards/',
  800. method: 'POST',
  801. body: [],
  802. });
  803. render(
  804. <CreateDashboard
  805. {...TestStubs.routeComponentProps()}
  806. organization={initialData.organization}
  807. params={{templateId: 'default-template'}}
  808. router={initialData.router}
  809. location={{
  810. ...initialData.router.location,
  811. query: {
  812. ...initialData.router.location.query,
  813. statsPeriod: '7d',
  814. project: [2],
  815. environment: ['alpha', 'beta'],
  816. },
  817. }}
  818. >
  819. {null}
  820. </CreateDashboard>,
  821. {
  822. context: initialData.routerContext,
  823. organization: initialData.organization,
  824. }
  825. );
  826. await userEvent.click(await screen.findByText('Add Dashboard'));
  827. expect(mockPOST).toHaveBeenCalledWith(
  828. '/organizations/org-slug/dashboards/',
  829. expect.objectContaining({
  830. data: expect.objectContaining({
  831. projects: [2],
  832. environment: ['alpha', 'beta'],
  833. period: '7d',
  834. }),
  835. })
  836. );
  837. });
  838. it('does not render save and cancel buttons on templates', async () => {
  839. MockApiClient.addMockResponse({
  840. url: '/organizations/org-slug/releases/',
  841. body: [
  842. TestStubs.Release({
  843. shortVersion: 'sentry-android-shop@1.2.0',
  844. version: 'sentry-android-shop@1.2.0',
  845. }),
  846. ],
  847. });
  848. render(
  849. <CreateDashboard
  850. {...TestStubs.routeComponentProps()}
  851. organization={initialData.organization}
  852. params={{templateId: 'default-template'}}
  853. router={initialData.router}
  854. location={initialData.router.location}
  855. >
  856. {null}
  857. </CreateDashboard>,
  858. {
  859. context: initialData.routerContext,
  860. organization: initialData.organization,
  861. }
  862. );
  863. await userEvent.click(await screen.findByText('24H'));
  864. await userEvent.click(screen.getByText('Last 7 days'));
  865. await screen.findByText('7D');
  866. expect(screen.queryByText('Cancel')).not.toBeInTheDocument();
  867. expect(screen.queryByText('Save')).not.toBeInTheDocument();
  868. });
  869. it('opens the widget viewer with saved dashboard filters', async () => {
  870. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  871. MockApiClient.addMockResponse({
  872. url: '/organizations/org-slug/dashboards/1/',
  873. body: TestStubs.Dashboard(widgets, {
  874. id: '1',
  875. filters: {release: ['sentry-android-shop@1.2.0']},
  876. }),
  877. });
  878. render(
  879. <ViewEditDashboard
  880. {...TestStubs.routeComponentProps()}
  881. organization={initialData.organization}
  882. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 1}}
  883. router={initialData.router}
  884. location={{...initialData.router.location, pathname: '/widget/1/'}}
  885. >
  886. {null}
  887. </ViewEditDashboard>,
  888. {context: initialData.routerContext, organization: initialData.organization}
  889. );
  890. await waitFor(() => {
  891. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  892. expect.objectContaining({
  893. dashboardFilters: {release: ['sentry-android-shop@1.2.0']},
  894. })
  895. );
  896. });
  897. });
  898. it('opens the widget viewer with unsaved dashboard filters', async () => {
  899. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  900. MockApiClient.addMockResponse({
  901. url: '/organizations/org-slug/dashboards/1/',
  902. body: TestStubs.Dashboard(widgets, {
  903. id: '1',
  904. filters: {release: ['sentry-android-shop@1.2.0']},
  905. }),
  906. });
  907. render(
  908. <ViewEditDashboard
  909. {...TestStubs.routeComponentProps()}
  910. organization={initialData.organization}
  911. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 1}}
  912. router={initialData.router}
  913. location={{
  914. ...initialData.router.location,
  915. pathname: '/widget/1/',
  916. query: {release: ['unsaved-release-filter@1.2.0']},
  917. }}
  918. >
  919. {null}
  920. </ViewEditDashboard>,
  921. {context: initialData.routerContext, organization: initialData.organization}
  922. );
  923. await waitFor(() => {
  924. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  925. expect.objectContaining({
  926. dashboardFilters: {release: ['unsaved-release-filter@1.2.0']},
  927. })
  928. );
  929. });
  930. });
  931. it('can save dashboard filters in existing dashboard', async () => {
  932. MockApiClient.addMockResponse({
  933. url: '/organizations/org-slug/releases/',
  934. body: [
  935. TestStubs.Release({
  936. shortVersion: 'sentry-android-shop@1.2.0',
  937. version: 'sentry-android-shop@1.2.0',
  938. }),
  939. ],
  940. });
  941. const testData = initializeOrg({
  942. organization: TestStubs.Organization({
  943. features: [
  944. 'global-views',
  945. 'dashboards-basic',
  946. 'dashboards-edit',
  947. 'discover-query',
  948. ],
  949. }),
  950. router: {
  951. location: {
  952. ...TestStubs.location(),
  953. query: {
  954. statsPeriod: '7d',
  955. release: ['sentry-android-shop@1.2.0'],
  956. },
  957. },
  958. },
  959. });
  960. render(
  961. <ViewEditDashboard
  962. {...TestStubs.routeComponentProps()}
  963. organization={testData.organization}
  964. params={{orgId: 'org-slug', dashboardId: '1'}}
  965. router={testData.router}
  966. location={testData.router.location}
  967. >
  968. {null}
  969. </ViewEditDashboard>,
  970. {context: testData.routerContext, organization: testData.organization}
  971. );
  972. await userEvent.click(await screen.findByText('Save'));
  973. expect(mockPut).toHaveBeenCalledWith(
  974. '/organizations/org-slug/dashboards/1/',
  975. expect.objectContaining({
  976. data: expect.objectContaining({
  977. period: '7d',
  978. filters: {release: ['sentry-android-shop@1.2.0']},
  979. }),
  980. })
  981. );
  982. });
  983. it('can clear dashboard filters in compact select', async () => {
  984. MockApiClient.addMockResponse({
  985. url: '/organizations/org-slug/dashboards/1/',
  986. body: TestStubs.Dashboard(widgets, {
  987. id: '1',
  988. title: 'Custom Errors',
  989. filters: {release: ['sentry-android-shop@1.2.0']},
  990. }),
  991. });
  992. MockApiClient.addMockResponse({
  993. url: '/organizations/org-slug/releases/',
  994. body: [
  995. TestStubs.Release({
  996. shortVersion: 'sentry-android-shop@1.2.0',
  997. version: 'sentry-android-shop@1.2.0',
  998. }),
  999. ],
  1000. });
  1001. const testData = initializeOrg({
  1002. organization: TestStubs.Organization({
  1003. features: [
  1004. 'global-views',
  1005. 'dashboards-basic',
  1006. 'dashboards-edit',
  1007. 'discover-query',
  1008. ],
  1009. }),
  1010. router: {
  1011. location: {
  1012. ...TestStubs.location(),
  1013. query: {
  1014. statsPeriod: '7d',
  1015. },
  1016. },
  1017. },
  1018. });
  1019. render(
  1020. <ViewEditDashboard
  1021. {...TestStubs.routeComponentProps()}
  1022. organization={testData.organization}
  1023. params={{orgId: 'org-slug', dashboardId: '1'}}
  1024. router={testData.router}
  1025. location={testData.router.location}
  1026. >
  1027. {null}
  1028. </ViewEditDashboard>,
  1029. {context: testData.routerContext, organization: testData.organization}
  1030. );
  1031. await screen.findByText('7D');
  1032. await userEvent.click(await screen.findByText('sentry-android-shop@1.2.0'));
  1033. await userEvent.click(screen.getByText('Clear'));
  1034. screen.getByText('All Releases');
  1035. await userEvent.click(document.body);
  1036. expect(browserHistory.push).toHaveBeenCalledWith(
  1037. expect.objectContaining({
  1038. query: expect.objectContaining({
  1039. release: '',
  1040. }),
  1041. })
  1042. );
  1043. });
  1044. it('can save absolute time range in existing dashboard', async () => {
  1045. const testData = initializeOrg({
  1046. organization: TestStubs.Organization({
  1047. features: [
  1048. 'global-views',
  1049. 'dashboards-basic',
  1050. 'dashboards-edit',
  1051. 'discover-query',
  1052. ],
  1053. }),
  1054. router: {
  1055. location: {
  1056. ...TestStubs.location(),
  1057. query: {
  1058. start: '2022-07-14T07:00:00',
  1059. end: '2022-07-19T23:59:59',
  1060. utc: 'true',
  1061. },
  1062. },
  1063. },
  1064. });
  1065. render(
  1066. <ViewEditDashboard
  1067. {...TestStubs.routeComponentProps()}
  1068. organization={testData.organization}
  1069. params={{orgId: 'org-slug', dashboardId: '1'}}
  1070. router={testData.router}
  1071. location={testData.router.location}
  1072. >
  1073. {null}
  1074. </ViewEditDashboard>,
  1075. {context: testData.routerContext, organization: testData.organization}
  1076. );
  1077. await userEvent.click(await screen.findByText('Save'));
  1078. expect(mockPut).toHaveBeenCalledWith(
  1079. '/organizations/org-slug/dashboards/1/',
  1080. expect.objectContaining({
  1081. data: expect.objectContaining({
  1082. start: '2022-07-14T07:00:00.000',
  1083. end: '2022-07-19T23:59:59.000',
  1084. utc: true,
  1085. }),
  1086. })
  1087. );
  1088. });
  1089. it('can clear dashboard filters in existing dashboard', async () => {
  1090. MockApiClient.addMockResponse({
  1091. url: '/organizations/org-slug/releases/',
  1092. body: [
  1093. TestStubs.Release({
  1094. shortVersion: 'sentry-android-shop@1.2.0',
  1095. version: 'sentry-android-shop@1.2.0',
  1096. }),
  1097. ],
  1098. });
  1099. const testData = initializeOrg({
  1100. organization: TestStubs.Organization({
  1101. features: [
  1102. 'global-views',
  1103. 'dashboards-basic',
  1104. 'dashboards-edit',
  1105. 'discover-query',
  1106. ],
  1107. }),
  1108. router: {
  1109. location: {
  1110. ...TestStubs.location(),
  1111. query: {
  1112. statsPeriod: '7d',
  1113. environment: ['alpha', 'beta'],
  1114. },
  1115. },
  1116. },
  1117. });
  1118. render(
  1119. <ViewEditDashboard
  1120. {...TestStubs.routeComponentProps()}
  1121. organization={testData.organization}
  1122. params={{orgId: 'org-slug', dashboardId: '1'}}
  1123. router={testData.router}
  1124. location={testData.router.location}
  1125. >
  1126. {null}
  1127. </ViewEditDashboard>,
  1128. {context: testData.routerContext, organization: testData.organization}
  1129. );
  1130. await screen.findByText('7D');
  1131. await userEvent.click(await screen.findByText('All Releases'));
  1132. await userEvent.click(screen.getByText('sentry-android-shop@1.2.0'));
  1133. await userEvent.keyboard('{Escape}');
  1134. await userEvent.click(screen.getByText('Cancel'));
  1135. screen.getByText('All Releases');
  1136. expect(browserHistory.replace).toHaveBeenCalledWith(
  1137. expect.objectContaining({
  1138. query: expect.objectContaining({
  1139. project: undefined,
  1140. statsPeriod: undefined,
  1141. environment: undefined,
  1142. }),
  1143. })
  1144. );
  1145. });
  1146. it('disables the Edit Dashboard button when there are unsaved filters', async () => {
  1147. MockApiClient.addMockResponse({
  1148. url: '/organizations/org-slug/releases/',
  1149. body: [
  1150. TestStubs.Release({
  1151. shortVersion: 'sentry-android-shop@1.2.0',
  1152. version: 'sentry-android-shop@1.2.0',
  1153. }),
  1154. ],
  1155. });
  1156. const testData = initializeOrg({
  1157. organization: TestStubs.Organization({
  1158. features: [
  1159. 'global-views',
  1160. 'dashboards-basic',
  1161. 'dashboards-edit',
  1162. 'discover-basic',
  1163. 'discover-query',
  1164. ],
  1165. }),
  1166. router: {
  1167. location: {
  1168. ...TestStubs.location(),
  1169. query: {
  1170. statsPeriod: '7d',
  1171. environment: ['alpha', 'beta'],
  1172. },
  1173. },
  1174. },
  1175. });
  1176. render(
  1177. <ViewEditDashboard
  1178. {...TestStubs.routeComponentProps()}
  1179. organization={testData.organization}
  1180. params={{orgId: 'org-slug', dashboardId: '1'}}
  1181. router={testData.router}
  1182. location={testData.router.location}
  1183. >
  1184. {null}
  1185. </ViewEditDashboard>,
  1186. {context: testData.routerContext, organization: testData.organization}
  1187. );
  1188. expect(await screen.findByText('Save')).toBeInTheDocument();
  1189. expect(screen.getByText('Cancel')).toBeInTheDocument();
  1190. expect(screen.getByRole('button', {name: 'Edit Dashboard'})).toBeDisabled();
  1191. });
  1192. it('ignores the order of selection of page filters to render unsaved filters', async () => {
  1193. const testProjects = [
  1194. TestStubs.Project({id: '1', name: 'first', environments: ['alpha', 'beta']}),
  1195. TestStubs.Project({id: '2', name: 'second', environments: ['alpha', 'beta']}),
  1196. ];
  1197. act(() => ProjectsStore.loadInitialData(testProjects));
  1198. MockApiClient.addMockResponse({
  1199. url: '/organizations/org-slug/projects/',
  1200. body: testProjects,
  1201. });
  1202. MockApiClient.addMockResponse({
  1203. url: '/organizations/org-slug/dashboards/1/',
  1204. body: TestStubs.Dashboard(widgets, {
  1205. id: '1',
  1206. title: 'Custom Errors',
  1207. filters: {},
  1208. environment: ['alpha', 'beta'],
  1209. }),
  1210. });
  1211. const testData = initializeOrg({
  1212. organization: TestStubs.Organization({
  1213. features: [
  1214. 'global-views',
  1215. 'dashboards-basic',
  1216. 'dashboards-edit',
  1217. 'discover-query',
  1218. ],
  1219. }),
  1220. router: {
  1221. location: {
  1222. ...TestStubs.location(),
  1223. query: {
  1224. environment: ['beta', 'alpha'], // Reversed order from saved dashboard
  1225. },
  1226. },
  1227. },
  1228. });
  1229. render(
  1230. <ViewEditDashboard
  1231. {...TestStubs.routeComponentProps()}
  1232. organization={testData.organization}
  1233. params={{orgId: 'org-slug', dashboardId: '1'}}
  1234. router={testData.router}
  1235. location={testData.router.location}
  1236. >
  1237. {null}
  1238. </ViewEditDashboard>,
  1239. {context: testData.routerContext, organization: testData.organization}
  1240. );
  1241. await waitFor(() => expect(screen.queryAllByText('Loading\u2026')).toEqual([]));
  1242. await screen.findByText(/beta, alpha/);
  1243. // Save and Cancel should not appear because alpha, beta is the same as beta, alpha
  1244. expect(screen.queryByText('Save')).not.toBeInTheDocument();
  1245. expect(screen.queryByText('Cancel')).not.toBeInTheDocument();
  1246. });
  1247. it('uses releases from the URL query params', async function () {
  1248. const testData = initializeOrg({
  1249. organization: TestStubs.Organization({
  1250. features: [
  1251. 'global-views',
  1252. 'dashboards-basic',
  1253. 'dashboards-edit',
  1254. 'discover-query',
  1255. ],
  1256. }),
  1257. router: {
  1258. location: {
  1259. ...TestStubs.location(),
  1260. query: {
  1261. release: ['not-selected-1'],
  1262. },
  1263. },
  1264. },
  1265. });
  1266. render(
  1267. <ViewEditDashboard
  1268. {...TestStubs.routeComponentProps()}
  1269. organization={testData.organization}
  1270. params={{orgId: 'org-slug', dashboardId: '1'}}
  1271. router={testData.router}
  1272. location={testData.router.location}
  1273. >
  1274. {null}
  1275. </ViewEditDashboard>,
  1276. {context: testData.routerContext, organization: testData.organization}
  1277. );
  1278. await screen.findByText(/not-selected-1/);
  1279. screen.getByText('Save');
  1280. screen.getByText('Cancel');
  1281. });
  1282. it('resets release in URL params', async function () {
  1283. MockApiClient.addMockResponse({
  1284. url: '/organizations/org-slug/dashboards/1/',
  1285. body: TestStubs.Dashboard(widgets, {
  1286. id: '1',
  1287. title: 'Custom Errors',
  1288. filters: {
  1289. release: ['abc'],
  1290. },
  1291. }),
  1292. });
  1293. const testData = initializeOrg({
  1294. organization: TestStubs.Organization({
  1295. features: [
  1296. 'global-views',
  1297. 'dashboards-basic',
  1298. 'dashboards-edit',
  1299. 'discover-query',
  1300. ],
  1301. }),
  1302. router: {
  1303. location: {
  1304. ...TestStubs.location(),
  1305. query: {
  1306. release: ['not-selected-1'],
  1307. },
  1308. },
  1309. },
  1310. });
  1311. render(
  1312. <ViewEditDashboard
  1313. {...TestStubs.routeComponentProps()}
  1314. organization={testData.organization}
  1315. params={{orgId: 'org-slug', dashboardId: '1'}}
  1316. router={testData.router}
  1317. location={testData.router.location}
  1318. >
  1319. {null}
  1320. </ViewEditDashboard>,
  1321. {context: testData.routerContext, organization: testData.organization}
  1322. );
  1323. await screen.findByText(/not-selected-1/);
  1324. await userEvent.click(screen.getByText('Cancel'));
  1325. // release isn't used in the redirect
  1326. expect(browserHistory.replace).toHaveBeenCalledWith(
  1327. expect.objectContaining({
  1328. query: {
  1329. end: undefined,
  1330. environment: undefined,
  1331. project: undefined,
  1332. start: undefined,
  1333. statsPeriod: undefined,
  1334. utc: undefined,
  1335. },
  1336. })
  1337. );
  1338. });
  1339. it('reflects selections in the release filter in the query params', async function () {
  1340. MockApiClient.addMockResponse({
  1341. url: '/organizations/org-slug/releases/',
  1342. body: [
  1343. TestStubs.Release({
  1344. shortVersion: 'sentry-android-shop@1.2.0',
  1345. version: 'sentry-android-shop@1.2.0',
  1346. }),
  1347. ],
  1348. });
  1349. const testData = initializeOrg({
  1350. organization: TestStubs.Organization({
  1351. features: [
  1352. 'global-views',
  1353. 'dashboards-basic',
  1354. 'dashboards-edit',
  1355. 'discover-query',
  1356. ],
  1357. }),
  1358. router: {
  1359. location: TestStubs.location(),
  1360. },
  1361. });
  1362. render(
  1363. <ViewEditDashboard
  1364. {...TestStubs.routeComponentProps()}
  1365. organization={testData.organization}
  1366. params={{orgId: 'org-slug', dashboardId: '1'}}
  1367. router={testData.router}
  1368. location={testData.router.location}
  1369. >
  1370. {null}
  1371. </ViewEditDashboard>,
  1372. {context: testData.routerContext, organization: testData.organization}
  1373. );
  1374. await userEvent.click(await screen.findByText('All Releases'));
  1375. await userEvent.click(screen.getByText('sentry-android-shop@1.2.0'));
  1376. await userEvent.click(document.body);
  1377. expect(browserHistory.push).toHaveBeenCalledWith(
  1378. expect.objectContaining({
  1379. query: expect.objectContaining({
  1380. release: ['sentry-android-shop@1.2.0'],
  1381. }),
  1382. })
  1383. );
  1384. });
  1385. it('persists release selections made during search requests that do not appear in default query', async function () {
  1386. // Default response
  1387. MockApiClient.addMockResponse({
  1388. url: '/organizations/org-slug/releases/',
  1389. body: [
  1390. TestStubs.Release({
  1391. shortVersion: 'sentry-android-shop@1.2.0',
  1392. version: 'sentry-android-shop@1.2.0',
  1393. }),
  1394. ],
  1395. });
  1396. // Mocked search results
  1397. MockApiClient.addMockResponse({
  1398. url: '/organizations/org-slug/releases/',
  1399. body: [
  1400. TestStubs.Release({
  1401. id: '9',
  1402. shortVersion: 'search-result',
  1403. version: 'search-result',
  1404. }),
  1405. ],
  1406. match: [MockApiClient.matchData({query: 's'})],
  1407. });
  1408. const testData = initializeOrg({
  1409. organization: TestStubs.Organization({
  1410. features: [
  1411. 'global-views',
  1412. 'dashboards-basic',
  1413. 'dashboards-edit',
  1414. 'discover-basic',
  1415. 'discover-query',
  1416. ],
  1417. }),
  1418. router: {
  1419. location: TestStubs.location(),
  1420. },
  1421. });
  1422. render(
  1423. <ViewEditDashboard
  1424. {...TestStubs.routeComponentProps()}
  1425. organization={testData.organization}
  1426. params={{orgId: 'org-slug', dashboardId: '1'}}
  1427. router={testData.router}
  1428. location={testData.router.location}
  1429. >
  1430. {null}
  1431. </ViewEditDashboard>,
  1432. {context: testData.routerContext, organization: testData.organization}
  1433. );
  1434. await userEvent.click(await screen.findByText('All Releases'));
  1435. await userEvent.type(screen.getByPlaceholderText('Search\u2026'), 's');
  1436. await userEvent.click(await screen.findByRole('option', {name: 'search-result'}));
  1437. // Validate that after search is cleared, search result still appears
  1438. expect(await screen.findByText('Latest Release(s)')).toBeInTheDocument();
  1439. expect(screen.getByRole('option', {name: 'search-result'})).toBeInTheDocument();
  1440. });
  1441. });
  1442. });