detail.spec.tsx 48 KB

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