detail.spec.tsx 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  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 add widget option with dataset selector flag', async function () {
  456. initialData = initializeOrg({
  457. organization: OrganizationFixture({
  458. features: [
  459. 'global-views',
  460. 'dashboards-basic',
  461. 'dashboards-edit',
  462. 'discover-query',
  463. 'custom-metrics',
  464. 'performance-discover-dataset-selector',
  465. ],
  466. }),
  467. });
  468. render(
  469. <OrganizationContext.Provider value={initialData.organization}>
  470. <ViewEditDashboard
  471. {...RouteComponentPropsFixture()}
  472. organization={initialData.organization}
  473. params={{orgId: 'org-slug', dashboardId: '1'}}
  474. router={initialData.router}
  475. location={initialData.router.location}
  476. >
  477. {null}
  478. </ViewEditDashboard>
  479. </OrganizationContext.Provider>,
  480. {router: initialData.router}
  481. );
  482. await userEvent.click(screen.getAllByText('Add Widget')[0]);
  483. const menuOptions = await screen.findAllByTestId('menu-list-item-label');
  484. expect(menuOptions.map(e => e.textContent)).toEqual([
  485. 'Errors',
  486. 'Transactions',
  487. 'Issues',
  488. 'Metrics',
  489. ]);
  490. });
  491. it('shows add widget option without dataset selector flag', async function () {
  492. initialData = initializeOrg({
  493. organization: OrganizationFixture({
  494. features: [
  495. 'global-views',
  496. 'dashboards-basic',
  497. 'dashboards-edit',
  498. 'discover-query',
  499. 'custom-metrics',
  500. ],
  501. }),
  502. });
  503. render(
  504. <OrganizationContext.Provider value={initialData.organization}>
  505. <ViewEditDashboard
  506. {...RouteComponentPropsFixture()}
  507. organization={initialData.organization}
  508. params={{orgId: 'org-slug', dashboardId: '1'}}
  509. router={initialData.router}
  510. location={initialData.router.location}
  511. >
  512. {null}
  513. </ViewEditDashboard>
  514. </OrganizationContext.Provider>,
  515. {router: initialData.router}
  516. );
  517. await userEvent.click(screen.getAllByText('Add Widget')[0]);
  518. const menuOptions = await screen.findAllByTestId('menu-list-item-label');
  519. expect(menuOptions.map(e => e.textContent)).toEqual([
  520. 'Errors and Transactions',
  521. 'Issues',
  522. 'Metrics',
  523. ]);
  524. });
  525. it('shows top level release filter', async function () {
  526. const mockReleases = MockApiClient.addMockResponse({
  527. url: '/organizations/org-slug/releases/',
  528. body: [ReleaseFixture()],
  529. });
  530. initialData = initializeOrg({
  531. organization: OrganizationFixture({
  532. features: [
  533. 'global-views',
  534. 'dashboards-basic',
  535. 'dashboards-edit',
  536. 'discover-query',
  537. ],
  538. }),
  539. });
  540. render(
  541. <OrganizationContext.Provider value={initialData.organization}>
  542. <ViewEditDashboard
  543. {...RouteComponentPropsFixture()}
  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. </OrganizationContext.Provider>,
  552. {router: initialData.router}
  553. );
  554. expect(await screen.findByText('All Releases')).toBeInTheDocument();
  555. expect(mockReleases).toHaveBeenCalledTimes(1);
  556. });
  557. it('hides add widget option', async function () {
  558. // @ts-expect-error this is assigning to readonly property...
  559. types.MAX_WIDGETS = 1;
  560. render(
  561. <OrganizationContext.Provider value={initialData.organization}>
  562. <ViewEditDashboard
  563. {...RouteComponentPropsFixture()}
  564. organization={initialData.organization}
  565. params={{orgId: 'org-slug', dashboardId: '1'}}
  566. router={initialData.router}
  567. location={initialData.router.location}
  568. >
  569. {null}
  570. </ViewEditDashboard>
  571. </OrganizationContext.Provider>,
  572. {router: initialData.router}
  573. );
  574. // Enter edit mode.
  575. await userEvent.click(await screen.findByRole('button', {name: 'Edit Dashboard'}));
  576. expect(screen.queryByRole('button', {name: 'Add widget'})).not.toBeInTheDocument();
  577. });
  578. it('renders successfully if more widgets than stored layouts', async function () {
  579. // A case where someone has async added widgets to a dashboard
  580. MockApiClient.addMockResponse({
  581. url: '/organizations/org-slug/dashboards/1/',
  582. body: DashboardFixture(
  583. [
  584. WidgetFixture({
  585. queries: [
  586. {
  587. name: '',
  588. conditions: 'event.type:error',
  589. fields: ['count()'],
  590. aggregates: ['count()'],
  591. columns: [],
  592. orderby: '-count()',
  593. },
  594. ],
  595. title: 'First Widget',
  596. interval: '1d',
  597. id: '1',
  598. layout: {x: 0, y: 0, w: 2, h: 6, minH: 0},
  599. }),
  600. WidgetFixture({
  601. queries: [
  602. {
  603. name: '',
  604. conditions: 'event.type:error',
  605. fields: ['count()'],
  606. aggregates: ['count()'],
  607. columns: [],
  608. orderby: '-count()',
  609. },
  610. ],
  611. title: 'Second Widget',
  612. interval: '1d',
  613. id: '2',
  614. }),
  615. ],
  616. {id: '1', title: 'Custom Errors'}
  617. ),
  618. });
  619. render(
  620. <ViewEditDashboard
  621. {...RouteComponentPropsFixture()}
  622. organization={initialData.organization}
  623. params={{orgId: 'org-slug', dashboardId: '1'}}
  624. router={initialData.router}
  625. location={initialData.router.location}
  626. >
  627. {null}
  628. </ViewEditDashboard>,
  629. {router: initialData.router, organization: initialData.organization}
  630. );
  631. expect(await screen.findByText('First Widget')).toBeInTheDocument();
  632. expect(await screen.findByText('Second Widget')).toBeInTheDocument();
  633. });
  634. it('does not trigger request if layout not updated', async () => {
  635. MockApiClient.addMockResponse({
  636. url: '/organizations/org-slug/dashboards/1/',
  637. body: DashboardFixture(
  638. [
  639. WidgetFixture({
  640. queries: [
  641. {
  642. name: '',
  643. conditions: 'event.type:error',
  644. fields: ['count()'],
  645. aggregates: ['count()'],
  646. columns: [],
  647. orderby: '-count()',
  648. },
  649. ],
  650. title: 'First Widget',
  651. interval: '1d',
  652. id: '1',
  653. layout: {x: 0, y: 0, w: 2, h: 6, minH: 0},
  654. }),
  655. ],
  656. {id: '1', title: 'Custom Errors'}
  657. ),
  658. });
  659. render(
  660. <ViewEditDashboard
  661. {...RouteComponentPropsFixture()}
  662. organization={initialData.organization}
  663. params={{orgId: 'org-slug', dashboardId: '1'}}
  664. router={initialData.router}
  665. location={initialData.router.location}
  666. >
  667. {null}
  668. </ViewEditDashboard>,
  669. {router: initialData.router, organization: initialData.organization}
  670. );
  671. await userEvent.click(await screen.findByText('Edit Dashboard'));
  672. await userEvent.click(await screen.findByText('Save and Finish'));
  673. expect(screen.getByText('Edit Dashboard')).toBeInTheDocument();
  674. expect(mockPut).not.toHaveBeenCalled();
  675. });
  676. it('renders the custom resize handler for a widget', async () => {
  677. MockApiClient.addMockResponse({
  678. url: '/organizations/org-slug/dashboards/1/',
  679. body: DashboardFixture(
  680. [
  681. WidgetFixture({
  682. queries: [
  683. {
  684. name: '',
  685. conditions: 'event.type:error',
  686. fields: ['count()'],
  687. aggregates: ['count()'],
  688. columns: [],
  689. orderby: '-count()',
  690. },
  691. ],
  692. title: 'First Widget',
  693. interval: '1d',
  694. id: '1',
  695. layout: {x: 0, y: 0, w: 2, h: 6, minH: 0},
  696. }),
  697. ],
  698. {id: '1', title: 'Custom Errors'}
  699. ),
  700. });
  701. render(
  702. <ViewEditDashboard
  703. {...RouteComponentPropsFixture()}
  704. organization={initialData.organization}
  705. params={{orgId: 'org-slug', dashboardId: '1'}}
  706. router={initialData.router}
  707. location={initialData.router.location}
  708. >
  709. {null}
  710. </ViewEditDashboard>,
  711. {router: initialData.router, organization: initialData.organization}
  712. );
  713. await userEvent.click(await screen.findByText('Edit Dashboard'));
  714. const widget = screen
  715. .getByText('First Widget')
  716. .closest('.react-grid-item') as HTMLElement;
  717. const resizeHandle = within(widget).getByTestId('custom-resize-handle');
  718. expect(resizeHandle).toBeVisible();
  719. });
  720. it('does not trigger an alert when the widgets have no layout and user cancels without changes', async () => {
  721. MockApiClient.addMockResponse({
  722. url: '/organizations/org-slug/dashboards/1/',
  723. body: DashboardFixture(
  724. [
  725. WidgetFixture({
  726. queries: [
  727. {
  728. name: '',
  729. conditions: 'event.type:error',
  730. fields: ['count()'],
  731. aggregates: ['count()'],
  732. columns: [],
  733. orderby: '-count()',
  734. },
  735. ],
  736. title: 'First Widget',
  737. interval: '1d',
  738. id: '1',
  739. layout: null,
  740. }),
  741. ],
  742. {id: '1', title: 'Custom Errors'}
  743. ),
  744. });
  745. render(
  746. <ViewEditDashboard
  747. {...RouteComponentPropsFixture()}
  748. organization={initialData.organization}
  749. params={{orgId: 'org-slug', dashboardId: '1'}}
  750. router={initialData.router}
  751. location={initialData.router.location}
  752. >
  753. {null}
  754. </ViewEditDashboard>,
  755. {router: initialData.router, organization: initialData.organization}
  756. );
  757. await userEvent.click(await screen.findByText('Edit Dashboard'));
  758. await userEvent.click(await screen.findByText('Cancel'));
  759. expect(window.confirm).not.toHaveBeenCalled();
  760. });
  761. it('opens the widget viewer modal using the widget id specified in the url', async () => {
  762. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  763. const widget = WidgetFixture({
  764. queries: [
  765. {
  766. name: '',
  767. conditions: 'event.type:error',
  768. fields: ['count()'],
  769. aggregates: ['count()'],
  770. columns: [],
  771. orderby: '',
  772. },
  773. ],
  774. title: 'First Widget',
  775. interval: '1d',
  776. id: '1',
  777. layout: null,
  778. });
  779. MockApiClient.addMockResponse({
  780. url: '/organizations/org-slug/dashboards/1/',
  781. body: DashboardFixture([widget], {id: '1', title: 'Custom Errors'}),
  782. });
  783. render(
  784. <ViewEditDashboard
  785. {...RouteComponentPropsFixture()}
  786. organization={initialData.organization}
  787. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 1}}
  788. router={initialData.router}
  789. location={{...initialData.router.location, pathname: '/widget/123/'}}
  790. >
  791. {null}
  792. </ViewEditDashboard>,
  793. {router: initialData.router, organization: initialData.organization}
  794. );
  795. await waitFor(() => {
  796. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  797. expect.objectContaining({
  798. organization: initialData.organization,
  799. widget,
  800. onClose: expect.anything(),
  801. })
  802. );
  803. });
  804. });
  805. it('redirects user to dashboard url if widget is not found', async () => {
  806. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  807. MockApiClient.addMockResponse({
  808. url: '/organizations/org-slug/dashboards/1/',
  809. body: DashboardFixture([], {id: '1', title: 'Custom Errors'}),
  810. });
  811. render(
  812. <ViewEditDashboard
  813. {...RouteComponentPropsFixture()}
  814. organization={initialData.organization}
  815. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 123}}
  816. router={initialData.router}
  817. location={{...initialData.router.location, pathname: '/widget/123/'}}
  818. >
  819. {null}
  820. </ViewEditDashboard>,
  821. {router: initialData.router, organization: initialData.organization}
  822. );
  823. expect(await screen.findByText('All Releases')).toBeInTheDocument();
  824. expect(openWidgetViewerModal).not.toHaveBeenCalled();
  825. expect(initialData.router.replace).toHaveBeenCalledWith(
  826. expect.objectContaining({
  827. pathname: '/organizations/org-slug/dashboard/1/',
  828. query: {},
  829. })
  830. );
  831. });
  832. it('saves a new dashboard with the page filters', async () => {
  833. const mockPOST = MockApiClient.addMockResponse({
  834. url: '/organizations/org-slug/dashboards/',
  835. method: 'POST',
  836. body: [],
  837. });
  838. render(
  839. <CreateDashboard
  840. {...RouteComponentPropsFixture()}
  841. organization={initialData.organization}
  842. params={{templateId: undefined}}
  843. router={initialData.router}
  844. location={{
  845. ...initialData.router.location,
  846. query: {
  847. ...initialData.router.location.query,
  848. statsPeriod: '7d',
  849. project: [2],
  850. environment: ['alpha', 'beta'],
  851. },
  852. }}
  853. >
  854. {null}
  855. </CreateDashboard>,
  856. {
  857. router: initialData.router,
  858. organization: initialData.organization,
  859. }
  860. );
  861. await userEvent.click(await screen.findByText('Save and Finish'));
  862. expect(mockPOST).toHaveBeenCalledWith(
  863. '/organizations/org-slug/dashboards/',
  864. expect.objectContaining({
  865. data: expect.objectContaining({
  866. projects: [2],
  867. environment: ['alpha', 'beta'],
  868. period: '7d',
  869. }),
  870. })
  871. );
  872. });
  873. it('saves a template with the page filters', async () => {
  874. const mockPOST = MockApiClient.addMockResponse({
  875. url: '/organizations/org-slug/dashboards/',
  876. method: 'POST',
  877. body: [],
  878. });
  879. render(
  880. <CreateDashboard
  881. {...RouteComponentPropsFixture()}
  882. organization={initialData.organization}
  883. params={{templateId: 'default-template'}}
  884. router={initialData.router}
  885. location={{
  886. ...initialData.router.location,
  887. query: {
  888. ...initialData.router.location.query,
  889. statsPeriod: '7d',
  890. project: [2],
  891. environment: ['alpha', 'beta'],
  892. },
  893. }}
  894. >
  895. {null}
  896. </CreateDashboard>,
  897. {
  898. router: initialData.router,
  899. organization: initialData.organization,
  900. }
  901. );
  902. await userEvent.click(await screen.findByText('Add Dashboard'));
  903. expect(mockPOST).toHaveBeenCalledWith(
  904. '/organizations/org-slug/dashboards/',
  905. expect.objectContaining({
  906. data: expect.objectContaining({
  907. projects: [2],
  908. environment: ['alpha', 'beta'],
  909. period: '7d',
  910. }),
  911. })
  912. );
  913. });
  914. it('does not render save and cancel buttons on templates', async () => {
  915. MockApiClient.addMockResponse({
  916. url: '/organizations/org-slug/releases/',
  917. body: [
  918. ReleaseFixture({
  919. shortVersion: 'sentry-android-shop@1.2.0',
  920. version: 'sentry-android-shop@1.2.0',
  921. }),
  922. ],
  923. });
  924. render(
  925. <CreateDashboard
  926. {...RouteComponentPropsFixture()}
  927. organization={initialData.organization}
  928. params={{templateId: 'default-template'}}
  929. router={initialData.router}
  930. location={initialData.router.location}
  931. >
  932. {null}
  933. </CreateDashboard>,
  934. {
  935. router: initialData.router,
  936. organization: initialData.organization,
  937. }
  938. );
  939. await userEvent.click(await screen.findByText('24H'));
  940. await userEvent.click(screen.getByText('Last 7 days'));
  941. await screen.findByText('7D');
  942. expect(screen.queryByText('Cancel')).not.toBeInTheDocument();
  943. expect(screen.queryByText('Save')).not.toBeInTheDocument();
  944. });
  945. it('opens the widget viewer with saved dashboard filters', async () => {
  946. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  947. MockApiClient.addMockResponse({
  948. url: '/organizations/org-slug/dashboards/1/',
  949. body: DashboardFixture(widgets, {
  950. id: '1',
  951. filters: {release: ['sentry-android-shop@1.2.0']},
  952. }),
  953. });
  954. render(
  955. <ViewEditDashboard
  956. {...RouteComponentPropsFixture()}
  957. organization={initialData.organization}
  958. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 1}}
  959. router={initialData.router}
  960. location={{...initialData.router.location, pathname: '/widget/1/'}}
  961. >
  962. {null}
  963. </ViewEditDashboard>,
  964. {router: initialData.router, organization: initialData.organization}
  965. );
  966. await waitFor(() => {
  967. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  968. expect.objectContaining({
  969. dashboardFilters: {release: ['sentry-android-shop@1.2.0']},
  970. })
  971. );
  972. });
  973. });
  974. it('opens the widget viewer with unsaved dashboard filters', async () => {
  975. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  976. MockApiClient.addMockResponse({
  977. url: '/organizations/org-slug/dashboards/1/',
  978. body: DashboardFixture(widgets, {
  979. id: '1',
  980. filters: {release: ['sentry-android-shop@1.2.0']},
  981. }),
  982. });
  983. render(
  984. <ViewEditDashboard
  985. {...RouteComponentPropsFixture()}
  986. organization={initialData.organization}
  987. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 1}}
  988. router={initialData.router}
  989. location={{
  990. ...initialData.router.location,
  991. pathname: '/widget/1/',
  992. query: {release: ['unsaved-release-filter@1.2.0']},
  993. }}
  994. >
  995. {null}
  996. </ViewEditDashboard>,
  997. {router: initialData.router, organization: initialData.organization}
  998. );
  999. await waitFor(() => {
  1000. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  1001. expect.objectContaining({
  1002. dashboardFilters: {release: ['unsaved-release-filter@1.2.0']},
  1003. })
  1004. );
  1005. });
  1006. });
  1007. it('can save dashboard filters in existing dashboard', async () => {
  1008. MockApiClient.addMockResponse({
  1009. url: '/organizations/org-slug/releases/',
  1010. body: [
  1011. ReleaseFixture({
  1012. shortVersion: 'sentry-android-shop@1.2.0',
  1013. version: 'sentry-android-shop@1.2.0',
  1014. }),
  1015. ],
  1016. });
  1017. const testData = initializeOrg({
  1018. organization: OrganizationFixture({
  1019. features: [
  1020. 'global-views',
  1021. 'dashboards-basic',
  1022. 'dashboards-edit',
  1023. 'discover-query',
  1024. ],
  1025. }),
  1026. router: {
  1027. location: {
  1028. ...LocationFixture(),
  1029. query: {
  1030. statsPeriod: '7d',
  1031. release: ['sentry-android-shop@1.2.0'],
  1032. },
  1033. },
  1034. },
  1035. });
  1036. render(
  1037. <ViewEditDashboard
  1038. {...RouteComponentPropsFixture()}
  1039. organization={testData.organization}
  1040. params={{orgId: 'org-slug', dashboardId: '1'}}
  1041. router={testData.router}
  1042. location={testData.router.location}
  1043. >
  1044. {null}
  1045. </ViewEditDashboard>,
  1046. {router: testData.router, organization: testData.organization}
  1047. );
  1048. await userEvent.click(await screen.findByText('Save'));
  1049. expect(mockPut).toHaveBeenCalledWith(
  1050. '/organizations/org-slug/dashboards/1/',
  1051. expect.objectContaining({
  1052. data: expect.objectContaining({
  1053. period: '7d',
  1054. filters: {release: ['sentry-android-shop@1.2.0']},
  1055. }),
  1056. })
  1057. );
  1058. });
  1059. it('can clear dashboard filters in compact select', async () => {
  1060. MockApiClient.addMockResponse({
  1061. url: '/organizations/org-slug/dashboards/1/',
  1062. body: DashboardFixture(widgets, {
  1063. id: '1',
  1064. title: 'Custom Errors',
  1065. filters: {release: ['sentry-android-shop@1.2.0']},
  1066. }),
  1067. });
  1068. MockApiClient.addMockResponse({
  1069. url: '/organizations/org-slug/releases/',
  1070. body: [
  1071. ReleaseFixture({
  1072. shortVersion: 'sentry-android-shop@1.2.0',
  1073. version: 'sentry-android-shop@1.2.0',
  1074. }),
  1075. ],
  1076. });
  1077. const testData = initializeOrg({
  1078. organization: OrganizationFixture({
  1079. features: [
  1080. 'global-views',
  1081. 'dashboards-basic',
  1082. 'dashboards-edit',
  1083. 'discover-query',
  1084. ],
  1085. }),
  1086. router: {
  1087. location: {
  1088. ...LocationFixture(),
  1089. query: {
  1090. statsPeriod: '7d',
  1091. },
  1092. },
  1093. },
  1094. });
  1095. render(
  1096. <ViewEditDashboard
  1097. {...RouteComponentPropsFixture()}
  1098. organization={testData.organization}
  1099. params={{orgId: 'org-slug', dashboardId: '1'}}
  1100. router={testData.router}
  1101. location={testData.router.location}
  1102. >
  1103. {null}
  1104. </ViewEditDashboard>,
  1105. {router: testData.router, organization: testData.organization}
  1106. );
  1107. await screen.findByText('7D');
  1108. await userEvent.click(await screen.findByText('sentry-android-shop@1.2.0'));
  1109. await userEvent.click(screen.getAllByText('Clear')[0]);
  1110. screen.getByText('All Releases');
  1111. await userEvent.click(document.body);
  1112. await waitFor(() => {
  1113. expect(browserHistory.push).toHaveBeenCalledWith(
  1114. expect.objectContaining({
  1115. query: expect.objectContaining({
  1116. release: '',
  1117. }),
  1118. })
  1119. );
  1120. });
  1121. });
  1122. it('can save absolute time range in existing dashboard', async () => {
  1123. const testData = initializeOrg({
  1124. organization: OrganizationFixture({
  1125. features: [
  1126. 'global-views',
  1127. 'dashboards-basic',
  1128. 'dashboards-edit',
  1129. 'discover-query',
  1130. ],
  1131. }),
  1132. router: {
  1133. location: {
  1134. ...LocationFixture(),
  1135. query: {
  1136. start: '2022-07-14T07:00:00',
  1137. end: '2022-07-19T23:59:59',
  1138. utc: 'true',
  1139. },
  1140. },
  1141. },
  1142. });
  1143. render(
  1144. <ViewEditDashboard
  1145. {...RouteComponentPropsFixture()}
  1146. organization={testData.organization}
  1147. params={{orgId: 'org-slug', dashboardId: '1'}}
  1148. router={testData.router}
  1149. location={testData.router.location}
  1150. >
  1151. {null}
  1152. </ViewEditDashboard>,
  1153. {router: testData.router, organization: testData.organization}
  1154. );
  1155. await userEvent.click(await screen.findByText('Save'));
  1156. expect(mockPut).toHaveBeenCalledWith(
  1157. '/organizations/org-slug/dashboards/1/',
  1158. expect.objectContaining({
  1159. data: expect.objectContaining({
  1160. start: '2022-07-14T07:00:00.000',
  1161. end: '2022-07-19T23:59:59.000',
  1162. utc: true,
  1163. }),
  1164. })
  1165. );
  1166. });
  1167. it('can clear dashboard filters in existing dashboard', async () => {
  1168. MockApiClient.addMockResponse({
  1169. url: '/organizations/org-slug/releases/',
  1170. body: [
  1171. ReleaseFixture({
  1172. shortVersion: 'sentry-android-shop@1.2.0',
  1173. version: 'sentry-android-shop@1.2.0',
  1174. }),
  1175. ],
  1176. });
  1177. const testData = initializeOrg({
  1178. organization: OrganizationFixture({
  1179. features: [
  1180. 'global-views',
  1181. 'dashboards-basic',
  1182. 'dashboards-edit',
  1183. 'discover-query',
  1184. ],
  1185. }),
  1186. router: {
  1187. location: {
  1188. ...LocationFixture(),
  1189. query: {
  1190. statsPeriod: '7d',
  1191. environment: ['alpha', 'beta'],
  1192. },
  1193. },
  1194. },
  1195. });
  1196. render(
  1197. <ViewEditDashboard
  1198. {...RouteComponentPropsFixture()}
  1199. organization={testData.organization}
  1200. params={{orgId: 'org-slug', dashboardId: '1'}}
  1201. router={testData.router}
  1202. location={testData.router.location}
  1203. >
  1204. {null}
  1205. </ViewEditDashboard>,
  1206. {router: testData.router, organization: testData.organization}
  1207. );
  1208. await screen.findByText('7D');
  1209. await userEvent.click(await screen.findByText('All Releases'));
  1210. await userEvent.click(screen.getByText('sentry-android-shop@1.2.0'));
  1211. await userEvent.keyboard('{Escape}');
  1212. await userEvent.click(screen.getByText('Cancel'));
  1213. screen.getByText('All Releases');
  1214. expect(browserHistory.replace).toHaveBeenCalledWith(
  1215. expect.objectContaining({
  1216. query: expect.objectContaining({
  1217. project: undefined,
  1218. statsPeriod: undefined,
  1219. environment: undefined,
  1220. }),
  1221. })
  1222. );
  1223. });
  1224. it('disables the Edit Dashboard button when there are unsaved filters', async () => {
  1225. MockApiClient.addMockResponse({
  1226. url: '/organizations/org-slug/releases/',
  1227. body: [
  1228. ReleaseFixture({
  1229. shortVersion: 'sentry-android-shop@1.2.0',
  1230. version: 'sentry-android-shop@1.2.0',
  1231. }),
  1232. ],
  1233. });
  1234. const testData = initializeOrg({
  1235. organization: OrganizationFixture({
  1236. features: [
  1237. 'global-views',
  1238. 'dashboards-basic',
  1239. 'dashboards-edit',
  1240. 'discover-basic',
  1241. 'discover-query',
  1242. ],
  1243. }),
  1244. router: {
  1245. location: {
  1246. ...LocationFixture(),
  1247. query: {
  1248. statsPeriod: '7d',
  1249. environment: ['alpha', 'beta'],
  1250. },
  1251. },
  1252. },
  1253. });
  1254. render(
  1255. <ViewEditDashboard
  1256. {...RouteComponentPropsFixture()}
  1257. organization={testData.organization}
  1258. params={{orgId: 'org-slug', dashboardId: '1'}}
  1259. router={testData.router}
  1260. location={testData.router.location}
  1261. >
  1262. {null}
  1263. </ViewEditDashboard>,
  1264. {router: testData.router, organization: testData.organization}
  1265. );
  1266. expect(await screen.findByText('Save')).toBeInTheDocument();
  1267. expect(screen.getByText('Cancel')).toBeInTheDocument();
  1268. expect(screen.getByRole('button', {name: 'Edit Dashboard'})).toBeDisabled();
  1269. });
  1270. it('ignores the order of selection of page filters to render unsaved filters', async () => {
  1271. const testProjects = [
  1272. ProjectFixture({id: '1', name: 'first', environments: ['alpha', 'beta']}),
  1273. ProjectFixture({id: '2', name: 'second', environments: ['alpha', 'beta']}),
  1274. ];
  1275. act(() => ProjectsStore.loadInitialData(testProjects));
  1276. MockApiClient.addMockResponse({
  1277. url: '/organizations/org-slug/projects/',
  1278. body: testProjects,
  1279. });
  1280. MockApiClient.addMockResponse({
  1281. url: '/organizations/org-slug/dashboards/1/',
  1282. body: DashboardFixture(widgets, {
  1283. id: '1',
  1284. title: 'Custom Errors',
  1285. filters: {},
  1286. environment: ['alpha', 'beta'],
  1287. }),
  1288. });
  1289. const testData = initializeOrg({
  1290. organization: OrganizationFixture({
  1291. features: [
  1292. 'global-views',
  1293. 'dashboards-basic',
  1294. 'dashboards-edit',
  1295. 'discover-query',
  1296. ],
  1297. }),
  1298. router: {
  1299. location: {
  1300. ...LocationFixture(),
  1301. query: {
  1302. environment: ['beta', 'alpha'], // Reversed order from saved dashboard
  1303. },
  1304. },
  1305. },
  1306. });
  1307. render(
  1308. <ViewEditDashboard
  1309. {...RouteComponentPropsFixture()}
  1310. organization={testData.organization}
  1311. params={{orgId: 'org-slug', dashboardId: '1'}}
  1312. router={testData.router}
  1313. location={testData.router.location}
  1314. >
  1315. {null}
  1316. </ViewEditDashboard>,
  1317. {router: testData.router, organization: testData.organization}
  1318. );
  1319. await waitFor(() => expect(screen.queryAllByText('Loading\u2026')).toEqual([]));
  1320. await userEvent.click(screen.getByRole('button', {name: 'All Envs'}));
  1321. expect(screen.getByRole('row', {name: 'alpha'})).toHaveAttribute(
  1322. 'aria-selected',
  1323. 'true'
  1324. );
  1325. expect(screen.getByRole('row', {name: 'beta'})).toHaveAttribute(
  1326. 'aria-selected',
  1327. 'true'
  1328. );
  1329. // Save and Cancel should not appear because alpha, beta is the same as beta, alpha
  1330. expect(screen.queryByText('Save')).not.toBeInTheDocument();
  1331. expect(screen.queryByText('Cancel')).not.toBeInTheDocument();
  1332. });
  1333. it('uses releases from the URL query params', async function () {
  1334. const testData = initializeOrg({
  1335. organization: OrganizationFixture({
  1336. features: [
  1337. 'global-views',
  1338. 'dashboards-basic',
  1339. 'dashboards-edit',
  1340. 'discover-query',
  1341. ],
  1342. }),
  1343. router: {
  1344. location: {
  1345. ...LocationFixture(),
  1346. query: {
  1347. release: ['not-selected-1'],
  1348. },
  1349. },
  1350. },
  1351. });
  1352. render(
  1353. <ViewEditDashboard
  1354. {...RouteComponentPropsFixture()}
  1355. organization={testData.organization}
  1356. params={{orgId: 'org-slug', dashboardId: '1'}}
  1357. router={testData.router}
  1358. location={testData.router.location}
  1359. >
  1360. {null}
  1361. </ViewEditDashboard>,
  1362. {router: testData.router, organization: testData.organization}
  1363. );
  1364. await screen.findByText(/not-selected-1/);
  1365. screen.getByText('Save');
  1366. screen.getByText('Cancel');
  1367. });
  1368. it('resets release in URL params', async function () {
  1369. MockApiClient.addMockResponse({
  1370. url: '/organizations/org-slug/dashboards/1/',
  1371. body: DashboardFixture(widgets, {
  1372. id: '1',
  1373. title: 'Custom Errors',
  1374. filters: {
  1375. release: ['abc'],
  1376. },
  1377. }),
  1378. });
  1379. const testData = initializeOrg({
  1380. organization: OrganizationFixture({
  1381. features: [
  1382. 'global-views',
  1383. 'dashboards-basic',
  1384. 'dashboards-edit',
  1385. 'discover-query',
  1386. ],
  1387. }),
  1388. router: {
  1389. location: {
  1390. ...LocationFixture(),
  1391. query: {
  1392. release: ['not-selected-1'],
  1393. },
  1394. },
  1395. },
  1396. });
  1397. render(
  1398. <ViewEditDashboard
  1399. {...RouteComponentPropsFixture()}
  1400. organization={testData.organization}
  1401. params={{orgId: 'org-slug', dashboardId: '1'}}
  1402. router={testData.router}
  1403. location={testData.router.location}
  1404. >
  1405. {null}
  1406. </ViewEditDashboard>,
  1407. {router: testData.router, organization: testData.organization}
  1408. );
  1409. await screen.findByText(/not-selected-1/);
  1410. await userEvent.click(screen.getByText('Cancel'));
  1411. // release isn't used in the redirect
  1412. expect(browserHistory.replace).toHaveBeenCalledWith(
  1413. expect.objectContaining({
  1414. query: {
  1415. end: undefined,
  1416. environment: undefined,
  1417. project: undefined,
  1418. start: undefined,
  1419. statsPeriod: undefined,
  1420. utc: undefined,
  1421. },
  1422. })
  1423. );
  1424. });
  1425. it('reflects selections in the release filter in the query params', async function () {
  1426. MockApiClient.addMockResponse({
  1427. url: '/organizations/org-slug/releases/',
  1428. body: [
  1429. ReleaseFixture({
  1430. shortVersion: 'sentry-android-shop@1.2.0',
  1431. version: 'sentry-android-shop@1.2.0',
  1432. }),
  1433. ],
  1434. });
  1435. const testData = initializeOrg({
  1436. organization: OrganizationFixture({
  1437. features: [
  1438. 'global-views',
  1439. 'dashboards-basic',
  1440. 'dashboards-edit',
  1441. 'discover-query',
  1442. ],
  1443. }),
  1444. router: {
  1445. location: LocationFixture(),
  1446. },
  1447. });
  1448. render(
  1449. <ViewEditDashboard
  1450. {...RouteComponentPropsFixture()}
  1451. organization={testData.organization}
  1452. params={{orgId: 'org-slug', dashboardId: '1'}}
  1453. router={testData.router}
  1454. location={testData.router.location}
  1455. >
  1456. {null}
  1457. </ViewEditDashboard>,
  1458. {router: testData.router, organization: testData.organization}
  1459. );
  1460. await userEvent.click(await screen.findByText('All Releases'));
  1461. await userEvent.click(screen.getByText('sentry-android-shop@1.2.0'));
  1462. await userEvent.click(document.body);
  1463. await waitFor(() => {
  1464. expect(browserHistory.push).toHaveBeenCalledWith(
  1465. expect.objectContaining({
  1466. query: expect.objectContaining({
  1467. release: ['sentry-android-shop@1.2.0'],
  1468. }),
  1469. })
  1470. );
  1471. });
  1472. });
  1473. it('persists release selections made during search requests that do not appear in default query', async function () {
  1474. // Default response
  1475. MockApiClient.addMockResponse({
  1476. url: '/organizations/org-slug/releases/',
  1477. body: [
  1478. ReleaseFixture({
  1479. shortVersion: 'sentry-android-shop@1.2.0',
  1480. version: 'sentry-android-shop@1.2.0',
  1481. }),
  1482. ],
  1483. });
  1484. // Mocked search results
  1485. MockApiClient.addMockResponse({
  1486. url: '/organizations/org-slug/releases/',
  1487. body: [
  1488. ReleaseFixture({
  1489. id: '9',
  1490. shortVersion: 'search-result',
  1491. version: 'search-result',
  1492. }),
  1493. ],
  1494. match: [MockApiClient.matchData({query: 's'})],
  1495. });
  1496. const testData = initializeOrg({
  1497. organization: OrganizationFixture({
  1498. features: [
  1499. 'global-views',
  1500. 'dashboards-basic',
  1501. 'dashboards-edit',
  1502. 'discover-basic',
  1503. 'discover-query',
  1504. ],
  1505. }),
  1506. router: {
  1507. location: LocationFixture(),
  1508. },
  1509. });
  1510. render(
  1511. <ViewEditDashboard
  1512. {...RouteComponentPropsFixture()}
  1513. organization={testData.organization}
  1514. params={{orgId: 'org-slug', dashboardId: '1'}}
  1515. router={testData.router}
  1516. location={testData.router.location}
  1517. >
  1518. {null}
  1519. </ViewEditDashboard>,
  1520. {router: testData.router, organization: testData.organization}
  1521. );
  1522. await userEvent.click(await screen.findByText('All Releases'));
  1523. await userEvent.type(screen.getAllByPlaceholderText('Search\u2026')[2], 's');
  1524. await userEvent.click(await screen.findByRole('option', {name: 'search-result'}));
  1525. // Validate that after search is cleared, search result still appears
  1526. expect(await screen.findByText('Latest Release(s)')).toBeInTheDocument();
  1527. expect(screen.getByRole('option', {name: 'search-result'})).toBeInTheDocument();
  1528. });
  1529. });
  1530. });