detail.spec.tsx 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  1. import {browserHistory} from 'react-router';
  2. import LocationFixture from 'sentry-fixture/locationFixture';
  3. import {Organization} from 'sentry-fixture/organization';
  4. import {Project as ProjectFixture} from 'sentry-fixture/project';
  5. import {initializeOrg} from 'sentry-test/initializeOrg';
  6. import {
  7. act,
  8. render,
  9. screen,
  10. userEvent,
  11. waitFor,
  12. within,
  13. } from 'sentry-test/reactTestingLibrary';
  14. import * as modals from 'sentry/actionCreators/modal';
  15. import ProjectsStore from 'sentry/stores/projectsStore';
  16. import CreateDashboard from 'sentry/views/dashboards/create';
  17. import * as types from 'sentry/views/dashboards/types';
  18. import ViewEditDashboard from 'sentry/views/dashboards/view';
  19. import {OrganizationContext} from 'sentry/views/organizationContext';
  20. describe('Dashboards > Detail', function () {
  21. const organization = Organization({
  22. features: ['global-views', 'dashboards-basic', 'dashboards-edit', 'discover-query'],
  23. });
  24. const projects = [ProjectFixture()];
  25. describe('prebuilt dashboards', function () {
  26. let initialData;
  27. beforeEach(function () {
  28. act(() => ProjectsStore.loadInitialData(projects));
  29. initialData = initializeOrg({organization});
  30. MockApiClient.addMockResponse({
  31. url: '/organizations/org-slug/tags/',
  32. body: [],
  33. });
  34. MockApiClient.addMockResponse({
  35. url: '/organizations/org-slug/projects/',
  36. body: [ProjectFixture()],
  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: Organization({
  135. features: ['global-views', 'dashboards-basic', 'discover-query'],
  136. projects: [ProjectFixture()],
  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: LocationFixture(),
  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: [ProjectFixture()],
  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: Organization({
  451. features: [
  452. 'global-views',
  453. 'dashboards-basic',
  454. 'dashboards-edit',
  455. 'discover-query',
  456. ],
  457. projects: [ProjectFixture()],
  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: Organization({
  946. features: [
  947. 'global-views',
  948. 'dashboards-basic',
  949. 'dashboards-edit',
  950. 'discover-query',
  951. ],
  952. }),
  953. router: {
  954. location: {
  955. ...LocationFixture(),
  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: Organization({
  1006. features: [
  1007. 'global-views',
  1008. 'dashboards-basic',
  1009. 'dashboards-edit',
  1010. 'discover-query',
  1011. ],
  1012. }),
  1013. router: {
  1014. location: {
  1015. ...LocationFixture(),
  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.getAllByText('Clear')[0]);
  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: Organization({
  1050. features: [
  1051. 'global-views',
  1052. 'dashboards-basic',
  1053. 'dashboards-edit',
  1054. 'discover-query',
  1055. ],
  1056. }),
  1057. router: {
  1058. location: {
  1059. ...LocationFixture(),
  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: Organization({
  1104. features: [
  1105. 'global-views',
  1106. 'dashboards-basic',
  1107. 'dashboards-edit',
  1108. 'discover-query',
  1109. ],
  1110. }),
  1111. router: {
  1112. location: {
  1113. ...LocationFixture(),
  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: 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. ...LocationFixture(),
  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. ProjectFixture({id: '1', name: 'first', environments: ['alpha', 'beta']}),
  1198. ProjectFixture({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: Organization({
  1216. features: [
  1217. 'global-views',
  1218. 'dashboards-basic',
  1219. 'dashboards-edit',
  1220. 'discover-query',
  1221. ],
  1222. }),
  1223. router: {
  1224. location: {
  1225. ...LocationFixture(),
  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 userEvent.click(screen.getByRole('button', {name: 'All Envs'}));
  1246. expect(screen.getByRole('row', {name: 'alpha'})).toHaveAttribute(
  1247. 'aria-selected',
  1248. 'true'
  1249. );
  1250. expect(screen.getByRole('row', {name: 'beta'})).toHaveAttribute(
  1251. 'aria-selected',
  1252. 'true'
  1253. );
  1254. // Save and Cancel should not appear because alpha, beta is the same as beta, alpha
  1255. expect(screen.queryByText('Save')).not.toBeInTheDocument();
  1256. expect(screen.queryByText('Cancel')).not.toBeInTheDocument();
  1257. });
  1258. it('uses releases from the URL query params', async function () {
  1259. const testData = initializeOrg({
  1260. organization: Organization({
  1261. features: [
  1262. 'global-views',
  1263. 'dashboards-basic',
  1264. 'dashboards-edit',
  1265. 'discover-query',
  1266. ],
  1267. }),
  1268. router: {
  1269. location: {
  1270. ...LocationFixture(),
  1271. query: {
  1272. release: ['not-selected-1'],
  1273. },
  1274. },
  1275. },
  1276. });
  1277. render(
  1278. <ViewEditDashboard
  1279. {...TestStubs.routeComponentProps()}
  1280. organization={testData.organization}
  1281. params={{orgId: 'org-slug', dashboardId: '1'}}
  1282. router={testData.router}
  1283. location={testData.router.location}
  1284. >
  1285. {null}
  1286. </ViewEditDashboard>,
  1287. {context: testData.routerContext, organization: testData.organization}
  1288. );
  1289. await screen.findByText(/not-selected-1/);
  1290. screen.getByText('Save');
  1291. screen.getByText('Cancel');
  1292. });
  1293. it('resets release in URL params', async function () {
  1294. MockApiClient.addMockResponse({
  1295. url: '/organizations/org-slug/dashboards/1/',
  1296. body: TestStubs.Dashboard(widgets, {
  1297. id: '1',
  1298. title: 'Custom Errors',
  1299. filters: {
  1300. release: ['abc'],
  1301. },
  1302. }),
  1303. });
  1304. const testData = initializeOrg({
  1305. organization: Organization({
  1306. features: [
  1307. 'global-views',
  1308. 'dashboards-basic',
  1309. 'dashboards-edit',
  1310. 'discover-query',
  1311. ],
  1312. }),
  1313. router: {
  1314. location: {
  1315. ...LocationFixture(),
  1316. query: {
  1317. release: ['not-selected-1'],
  1318. },
  1319. },
  1320. },
  1321. });
  1322. render(
  1323. <ViewEditDashboard
  1324. {...TestStubs.routeComponentProps()}
  1325. organization={testData.organization}
  1326. params={{orgId: 'org-slug', dashboardId: '1'}}
  1327. router={testData.router}
  1328. location={testData.router.location}
  1329. >
  1330. {null}
  1331. </ViewEditDashboard>,
  1332. {context: testData.routerContext, organization: testData.organization}
  1333. );
  1334. await screen.findByText(/not-selected-1/);
  1335. await userEvent.click(screen.getByText('Cancel'));
  1336. // release isn't used in the redirect
  1337. expect(browserHistory.replace).toHaveBeenCalledWith(
  1338. expect.objectContaining({
  1339. query: {
  1340. end: undefined,
  1341. environment: undefined,
  1342. project: undefined,
  1343. start: undefined,
  1344. statsPeriod: undefined,
  1345. utc: undefined,
  1346. },
  1347. })
  1348. );
  1349. });
  1350. it('reflects selections in the release filter in the query params', async function () {
  1351. MockApiClient.addMockResponse({
  1352. url: '/organizations/org-slug/releases/',
  1353. body: [
  1354. TestStubs.Release({
  1355. shortVersion: 'sentry-android-shop@1.2.0',
  1356. version: 'sentry-android-shop@1.2.0',
  1357. }),
  1358. ],
  1359. });
  1360. const testData = initializeOrg({
  1361. organization: Organization({
  1362. features: [
  1363. 'global-views',
  1364. 'dashboards-basic',
  1365. 'dashboards-edit',
  1366. 'discover-query',
  1367. ],
  1368. }),
  1369. router: {
  1370. location: LocationFixture(),
  1371. },
  1372. });
  1373. render(
  1374. <ViewEditDashboard
  1375. {...TestStubs.routeComponentProps()}
  1376. organization={testData.organization}
  1377. params={{orgId: 'org-slug', dashboardId: '1'}}
  1378. router={testData.router}
  1379. location={testData.router.location}
  1380. >
  1381. {null}
  1382. </ViewEditDashboard>,
  1383. {context: testData.routerContext, organization: testData.organization}
  1384. );
  1385. await userEvent.click(await screen.findByText('All Releases'));
  1386. await userEvent.click(screen.getByText('sentry-android-shop@1.2.0'));
  1387. await userEvent.click(document.body);
  1388. expect(browserHistory.push).toHaveBeenCalledWith(
  1389. expect.objectContaining({
  1390. query: expect.objectContaining({
  1391. release: ['sentry-android-shop@1.2.0'],
  1392. }),
  1393. })
  1394. );
  1395. });
  1396. it('persists release selections made during search requests that do not appear in default query', async function () {
  1397. // Default response
  1398. MockApiClient.addMockResponse({
  1399. url: '/organizations/org-slug/releases/',
  1400. body: [
  1401. TestStubs.Release({
  1402. shortVersion: 'sentry-android-shop@1.2.0',
  1403. version: 'sentry-android-shop@1.2.0',
  1404. }),
  1405. ],
  1406. });
  1407. // Mocked search results
  1408. MockApiClient.addMockResponse({
  1409. url: '/organizations/org-slug/releases/',
  1410. body: [
  1411. TestStubs.Release({
  1412. id: '9',
  1413. shortVersion: 'search-result',
  1414. version: 'search-result',
  1415. }),
  1416. ],
  1417. match: [MockApiClient.matchData({query: 's'})],
  1418. });
  1419. const testData = initializeOrg({
  1420. organization: Organization({
  1421. features: [
  1422. 'global-views',
  1423. 'dashboards-basic',
  1424. 'dashboards-edit',
  1425. 'discover-basic',
  1426. 'discover-query',
  1427. ],
  1428. }),
  1429. router: {
  1430. location: LocationFixture(),
  1431. },
  1432. });
  1433. render(
  1434. <ViewEditDashboard
  1435. {...TestStubs.routeComponentProps()}
  1436. organization={testData.organization}
  1437. params={{orgId: 'org-slug', dashboardId: '1'}}
  1438. router={testData.router}
  1439. location={testData.router.location}
  1440. >
  1441. {null}
  1442. </ViewEditDashboard>,
  1443. {context: testData.routerContext, organization: testData.organization}
  1444. );
  1445. await userEvent.click(await screen.findByText('All Releases'));
  1446. await userEvent.type(screen.getAllByPlaceholderText('Search\u2026')[2], 's');
  1447. await userEvent.click(await screen.findByRole('option', {name: 'search-result'}));
  1448. // Validate that after search is cleared, search result still appears
  1449. expect(await screen.findByText('Latest Release(s)')).toBeInTheDocument();
  1450. expect(screen.getByRole('option', {name: 'search-result'})).toBeInTheDocument();
  1451. });
  1452. });
  1453. });