detail.spec.jsx 45 KB

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