detail.spec.tsx 48 KB

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