detail.spec.tsx 47 KB

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