detail.spec.tsx 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075
  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 {TeamFixture} from 'sentry-fixture/team';
  8. import {UserFixture} from 'sentry-fixture/user';
  9. import {WidgetFixture} from 'sentry-fixture/widget';
  10. import {initializeOrg} from 'sentry-test/initializeOrg';
  11. import {
  12. act,
  13. render,
  14. screen,
  15. userEvent,
  16. waitFor,
  17. within,
  18. } from 'sentry-test/reactTestingLibrary';
  19. import * as modals from 'sentry/actionCreators/modal';
  20. import ConfigStore from 'sentry/stores/configStore';
  21. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  22. import ProjectsStore from 'sentry/stores/projectsStore';
  23. import TeamStore from 'sentry/stores/teamStore';
  24. import {browserHistory} from 'sentry/utils/browserHistory';
  25. import CreateDashboard from 'sentry/views/dashboards/create';
  26. import {handleUpdateDashboardSplit} from 'sentry/views/dashboards/detail';
  27. import EditAccessSelector from 'sentry/views/dashboards/editAccessSelector';
  28. import * as types from 'sentry/views/dashboards/types';
  29. import ViewEditDashboard from 'sentry/views/dashboards/view';
  30. import {OrganizationContext} from 'sentry/views/organizationContext';
  31. describe('Dashboards > Detail', function () {
  32. const organization = OrganizationFixture({
  33. features: ['global-views', 'dashboards-basic', 'dashboards-edit', 'discover-query'],
  34. });
  35. const projects = [ProjectFixture()];
  36. describe('prebuilt dashboards', function () {
  37. let initialData;
  38. beforeEach(function () {
  39. act(() => ProjectsStore.loadInitialData(projects));
  40. initialData = initializeOrg({organization});
  41. MockApiClient.addMockResponse({
  42. url: '/organizations/org-slug/tags/',
  43. body: [],
  44. });
  45. MockApiClient.addMockResponse({
  46. url: '/organizations/org-slug/projects/',
  47. body: [ProjectFixture()],
  48. });
  49. MockApiClient.addMockResponse({
  50. url: '/organizations/org-slug/dashboards/',
  51. body: [
  52. DashboardFixture([], {id: 'default-overview', title: 'Default'}),
  53. DashboardFixture([], {id: '1', title: 'Custom Errors'}),
  54. ],
  55. });
  56. MockApiClient.addMockResponse({
  57. url: '/organizations/org-slug/dashboards/default-overview/',
  58. body: DashboardFixture([], {id: 'default-overview', title: 'Default'}),
  59. });
  60. MockApiClient.addMockResponse({
  61. url: '/organizations/org-slug/dashboards/1/visit/',
  62. method: 'POST',
  63. body: [],
  64. statusCode: 200,
  65. });
  66. MockApiClient.addMockResponse({
  67. url: '/organizations/org-slug/users/',
  68. method: 'GET',
  69. body: [],
  70. });
  71. MockApiClient.addMockResponse({
  72. url: '/organizations/org-slug/sdk-updates/',
  73. body: [],
  74. });
  75. MockApiClient.addMockResponse({
  76. url: '/organizations/org-slug/prompts-activity/',
  77. body: {},
  78. });
  79. MockApiClient.addMockResponse({
  80. url: '/organizations/org-slug/events/',
  81. method: 'GET',
  82. body: [],
  83. });
  84. MockApiClient.addMockResponse({
  85. url: '/organizations/org-slug/events-stats/',
  86. body: {data: []},
  87. });
  88. MockApiClient.addMockResponse({
  89. method: 'GET',
  90. url: '/organizations/org-slug/issues/',
  91. body: [],
  92. });
  93. MockApiClient.addMockResponse({
  94. url: '/organizations/org-slug/releases/',
  95. body: [],
  96. });
  97. MockApiClient.addMockResponse({
  98. url: '/organizations/org-slug/releases/stats/',
  99. body: [],
  100. });
  101. MockApiClient.addMockResponse({
  102. url: '/organizations/org-slug/metrics/meta/',
  103. body: [],
  104. });
  105. });
  106. afterEach(function () {
  107. MockApiClient.clearMockResponses();
  108. });
  109. it('assigns unique IDs to all widgets so grid keys are unique', async function () {
  110. MockApiClient.addMockResponse({
  111. url: '/organizations/org-slug/events-stats/',
  112. body: {data: []},
  113. });
  114. MockApiClient.addMockResponse({
  115. url: '/organizations/org-slug/dashboards/default-overview/',
  116. body: DashboardFixture(
  117. [
  118. WidgetFixture({
  119. queries: [
  120. {
  121. name: '',
  122. conditions: 'event.type:error',
  123. fields: ['count()'],
  124. aggregates: ['count()'],
  125. columns: [],
  126. orderby: '-count()',
  127. },
  128. ],
  129. title: 'Default Widget 1',
  130. interval: '1d',
  131. }),
  132. WidgetFixture({
  133. queries: [
  134. {
  135. name: '',
  136. conditions: 'event.type:transaction',
  137. fields: ['count()'],
  138. aggregates: ['count()'],
  139. columns: [],
  140. orderby: '-count()',
  141. },
  142. ],
  143. title: 'Default Widget 2',
  144. interval: '1d',
  145. }),
  146. ],
  147. {id: 'default-overview', title: 'Default'}
  148. ),
  149. });
  150. initialData = initializeOrg({
  151. organization: OrganizationFixture({
  152. features: ['global-views', 'dashboards-basic', 'discover-query'],
  153. }),
  154. });
  155. render(
  156. <OrganizationContext.Provider value={initialData.organization}>
  157. <ViewEditDashboard
  158. {...RouteComponentPropsFixture()}
  159. organization={initialData.organization}
  160. params={{orgId: 'org-slug', dashboardId: 'default-overview'}}
  161. router={initialData.router}
  162. location={initialData.router.location}
  163. >
  164. {null}
  165. </ViewEditDashboard>
  166. </OrganizationContext.Provider>,
  167. {router: initialData.router}
  168. );
  169. expect(await screen.findByText('Default Widget 1')).toBeInTheDocument();
  170. expect(screen.getByText('Default Widget 2')).toBeInTheDocument();
  171. });
  172. it('opens the widget viewer modal in a prebuilt dashboard using the widget id specified in the url', async () => {
  173. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  174. render(
  175. <CreateDashboard
  176. {...RouteComponentPropsFixture()}
  177. organization={initialData.organization}
  178. params={{templateId: 'default-template', widgetId: '2'}}
  179. router={initialData.router}
  180. location={{...initialData.router.location, pathname: '/widget/2/'}}
  181. >
  182. {null}
  183. </CreateDashboard>,
  184. {router: initialData.router, organization: initialData.organization}
  185. );
  186. await waitFor(() => {
  187. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  188. expect.objectContaining({
  189. organization: initialData.organization,
  190. widget: expect.objectContaining({
  191. displayType: 'line',
  192. interval: '5m',
  193. queries: [
  194. {
  195. aggregates: ['count()'],
  196. columns: [],
  197. conditions: '!event.type:transaction',
  198. fields: ['count()'],
  199. name: 'Events',
  200. orderby: 'count()',
  201. },
  202. ],
  203. title: 'Events',
  204. widgetType: types.WidgetType.DISCOVER,
  205. }),
  206. onClose: expect.anything(),
  207. })
  208. );
  209. });
  210. });
  211. });
  212. describe('custom dashboards', function () {
  213. let initialData, widgets, mockVisit, mockPut;
  214. beforeEach(function () {
  215. window.confirm = jest.fn();
  216. initialData = initializeOrg({
  217. organization,
  218. router: {
  219. location: LocationFixture(),
  220. },
  221. });
  222. PageFiltersStore.init();
  223. PageFiltersStore.onInitializeUrlState(
  224. {
  225. projects: [],
  226. environments: [],
  227. datetime: {start: null, end: null, period: '14d', utc: null},
  228. },
  229. new Set()
  230. );
  231. widgets = [
  232. WidgetFixture({
  233. queries: [
  234. {
  235. name: '',
  236. conditions: 'event.type:error',
  237. fields: ['count()'],
  238. columns: [],
  239. aggregates: ['count()'],
  240. orderby: '-count()',
  241. },
  242. ],
  243. title: 'Errors',
  244. interval: '1d',
  245. widgetType: types.WidgetType.DISCOVER,
  246. id: '1',
  247. }),
  248. WidgetFixture({
  249. queries: [
  250. {
  251. name: '',
  252. conditions: 'event.type:transaction',
  253. fields: ['count()'],
  254. columns: [],
  255. aggregates: ['count()'],
  256. orderby: '-count()',
  257. },
  258. ],
  259. title: 'Transactions',
  260. interval: '1d',
  261. widgetType: types.WidgetType.DISCOVER,
  262. id: '2',
  263. }),
  264. WidgetFixture({
  265. queries: [
  266. {
  267. name: '',
  268. conditions: 'event.type:transaction transaction:/api/cats',
  269. fields: ['p50()'],
  270. columns: [],
  271. aggregates: ['p50()'],
  272. orderby: '-p50()',
  273. },
  274. ],
  275. title: 'p50 of /api/cats',
  276. interval: '1d',
  277. id: '3',
  278. }),
  279. ];
  280. mockVisit = MockApiClient.addMockResponse({
  281. url: '/organizations/org-slug/dashboards/1/visit/',
  282. method: 'POST',
  283. body: [],
  284. statusCode: 200,
  285. });
  286. MockApiClient.addMockResponse({
  287. url: '/organizations/org-slug/tags/',
  288. body: [],
  289. });
  290. MockApiClient.addMockResponse({
  291. url: '/organizations/org-slug/projects/',
  292. body: [ProjectFixture()],
  293. });
  294. MockApiClient.addMockResponse({
  295. url: '/organizations/org-slug/dashboards/',
  296. body: [
  297. {
  298. ...DashboardFixture([], {
  299. id: 'default-overview',
  300. title: 'Default',
  301. }),
  302. widgetDisplay: ['area'],
  303. },
  304. {
  305. ...DashboardFixture([], {
  306. id: '1',
  307. title: 'Custom Errors',
  308. }),
  309. widgetDisplay: ['area'],
  310. },
  311. ],
  312. });
  313. MockApiClient.addMockResponse({
  314. url: '/organizations/org-slug/dashboards/1/',
  315. body: DashboardFixture(widgets, {
  316. id: '1',
  317. title: 'Custom Errors',
  318. filters: {},
  319. createdBy: UserFixture({id: '1'}),
  320. }),
  321. });
  322. mockPut = MockApiClient.addMockResponse({
  323. url: '/organizations/org-slug/dashboards/1/',
  324. method: 'PUT',
  325. body: DashboardFixture(widgets, {id: '1', title: 'Custom Errors'}),
  326. });
  327. MockApiClient.addMockResponse({
  328. url: '/organizations/org-slug/events-stats/',
  329. body: {data: []},
  330. });
  331. MockApiClient.addMockResponse({
  332. method: 'POST',
  333. url: '/organizations/org-slug/dashboards/widgets/',
  334. body: [],
  335. });
  336. MockApiClient.addMockResponse({
  337. method: 'GET',
  338. url: '/organizations/org-slug/recent-searches/',
  339. body: [],
  340. });
  341. MockApiClient.addMockResponse({
  342. method: 'GET',
  343. url: '/organizations/org-slug/issues/',
  344. body: [],
  345. });
  346. MockApiClient.addMockResponse({
  347. url: '/organizations/org-slug/events/',
  348. method: 'GET',
  349. body: [],
  350. });
  351. MockApiClient.addMockResponse({
  352. url: '/organizations/org-slug/users/',
  353. method: 'GET',
  354. body: [],
  355. });
  356. MockApiClient.addMockResponse({
  357. url: '/organizations/org-slug/releases/',
  358. body: [],
  359. });
  360. MockApiClient.addMockResponse({
  361. url: '/organizations/org-slug/releases/stats/',
  362. body: [],
  363. });
  364. MockApiClient.addMockResponse({
  365. url: '/organizations/org-slug/sdk-updates/',
  366. body: [],
  367. });
  368. MockApiClient.addMockResponse({
  369. url: '/organizations/org-slug/prompts-activity/',
  370. body: {},
  371. });
  372. MockApiClient.addMockResponse({
  373. url: '/organizations/org-slug/metrics/meta/',
  374. body: [],
  375. });
  376. });
  377. afterEach(function () {
  378. MockApiClient.clearMockResponses();
  379. jest.clearAllMocks();
  380. });
  381. it('can remove widgets', async function () {
  382. const updateMock = MockApiClient.addMockResponse({
  383. url: '/organizations/org-slug/dashboards/1/',
  384. method: 'PUT',
  385. body: DashboardFixture([widgets[0]], {id: '1', title: 'Custom Errors'}),
  386. });
  387. render(
  388. <OrganizationContext.Provider value={initialData.organization}>
  389. <ViewEditDashboard
  390. {...RouteComponentPropsFixture()}
  391. organization={initialData.organization}
  392. params={{orgId: 'org-slug', dashboardId: '1'}}
  393. router={initialData.router}
  394. location={initialData.router.location}
  395. >
  396. {null}
  397. </ViewEditDashboard>
  398. </OrganizationContext.Provider>,
  399. {router: initialData.router}
  400. );
  401. await waitFor(() => expect(mockVisit).toHaveBeenCalledTimes(1));
  402. // Enter edit mode.
  403. await userEvent.click(screen.getByRole('button', {name: 'Edit Dashboard'}));
  404. // Remove the second and third widgets
  405. await userEvent.click(
  406. (await screen.findAllByRole('button', {name: 'Delete Widget'}))[1]
  407. );
  408. await userEvent.click(
  409. (await screen.findAllByRole('button', {name: 'Delete Widget'}))[1]
  410. );
  411. // Save changes
  412. await userEvent.click(screen.getByRole('button', {name: 'Save and Finish'}));
  413. expect(updateMock).toHaveBeenCalled();
  414. expect(updateMock).toHaveBeenCalledWith(
  415. '/organizations/org-slug/dashboards/1/',
  416. expect.objectContaining({
  417. data: expect.objectContaining({
  418. title: 'Custom Errors',
  419. widgets: [expect.objectContaining(widgets[0])],
  420. }),
  421. })
  422. );
  423. // Visit should not be called again on dashboard update
  424. expect(mockVisit).toHaveBeenCalledTimes(1);
  425. });
  426. it('appends dashboard-level filters to series request', async function () {
  427. MockApiClient.addMockResponse({
  428. url: '/organizations/org-slug/dashboards/1/',
  429. body: DashboardFixture(widgets, {
  430. id: '1',
  431. title: 'Custom Errors',
  432. filters: {release: ['abc@1.2.0']},
  433. }),
  434. });
  435. const mock = MockApiClient.addMockResponse({
  436. url: '/organizations/org-slug/events-stats/',
  437. body: [],
  438. });
  439. render(
  440. <OrganizationContext.Provider value={initialData.organization}>
  441. <ViewEditDashboard
  442. {...RouteComponentPropsFixture()}
  443. organization={initialData.organization}
  444. params={{orgId: 'org-slug', dashboardId: '1'}}
  445. router={initialData.router}
  446. location={initialData.router.location}
  447. >
  448. {null}
  449. </ViewEditDashboard>
  450. </OrganizationContext.Provider>,
  451. {router: initialData.router}
  452. );
  453. await waitFor(() =>
  454. expect(mock).toHaveBeenLastCalledWith(
  455. '/organizations/org-slug/events-stats/',
  456. expect.objectContaining({
  457. query: expect.objectContaining({
  458. query:
  459. '(event.type:transaction transaction:/api/cats) release:"abc@1.2.0" ',
  460. }),
  461. })
  462. )
  463. );
  464. });
  465. it('shows add widget option', async function () {
  466. render(
  467. <OrganizationContext.Provider value={initialData.organization}>
  468. <ViewEditDashboard
  469. {...RouteComponentPropsFixture()}
  470. organization={initialData.organization}
  471. params={{orgId: 'org-slug', dashboardId: '1'}}
  472. router={initialData.router}
  473. location={initialData.router.location}
  474. >
  475. {null}
  476. </ViewEditDashboard>
  477. </OrganizationContext.Provider>,
  478. {router: initialData.router}
  479. );
  480. // Enter edit mode.
  481. await userEvent.click(screen.getByRole('button', {name: 'Edit Dashboard'}));
  482. expect(await screen.findByRole('button', {name: 'Add widget'})).toBeInTheDocument();
  483. });
  484. it('shows add widget option with dataset selector flag', async function () {
  485. initialData = initializeOrg({
  486. organization: OrganizationFixture({
  487. features: [
  488. 'global-views',
  489. 'dashboards-basic',
  490. 'dashboards-edit',
  491. 'discover-query',
  492. 'custom-metrics',
  493. 'performance-discover-dataset-selector',
  494. ],
  495. }),
  496. });
  497. render(
  498. <OrganizationContext.Provider value={initialData.organization}>
  499. <ViewEditDashboard
  500. {...RouteComponentPropsFixture()}
  501. organization={initialData.organization}
  502. params={{orgId: 'org-slug', dashboardId: '1'}}
  503. router={initialData.router}
  504. location={initialData.router.location}
  505. >
  506. {null}
  507. </ViewEditDashboard>
  508. </OrganizationContext.Provider>,
  509. {router: initialData.router}
  510. );
  511. await userEvent.click(screen.getAllByText('Add Widget')[0]);
  512. const menuOptions = await screen.findAllByTestId('menu-list-item-label');
  513. expect(menuOptions.map(e => e.textContent)).toEqual([
  514. 'Errors',
  515. 'Transactions',
  516. 'Issues',
  517. 'Releases',
  518. 'Metrics',
  519. ]);
  520. });
  521. it('shows add widget option without dataset selector flag', async function () {
  522. initialData = initializeOrg({
  523. organization: OrganizationFixture({
  524. features: [
  525. 'global-views',
  526. 'dashboards-basic',
  527. 'dashboards-edit',
  528. 'discover-query',
  529. 'custom-metrics',
  530. ],
  531. }),
  532. });
  533. render(
  534. <OrganizationContext.Provider value={initialData.organization}>
  535. <ViewEditDashboard
  536. {...RouteComponentPropsFixture()}
  537. organization={initialData.organization}
  538. params={{orgId: 'org-slug', dashboardId: '1'}}
  539. router={initialData.router}
  540. location={initialData.router.location}
  541. >
  542. {null}
  543. </ViewEditDashboard>
  544. </OrganizationContext.Provider>,
  545. {router: initialData.router}
  546. );
  547. await userEvent.click(screen.getAllByText('Add Widget')[0]);
  548. const menuOptions = await screen.findAllByTestId('menu-list-item-label');
  549. expect(menuOptions.map(e => e.textContent)).toEqual([
  550. 'Errors and Transactions',
  551. 'Issues',
  552. 'Releases',
  553. 'Metrics',
  554. ]);
  555. });
  556. it('shows top level release filter', async function () {
  557. const mockReleases = MockApiClient.addMockResponse({
  558. url: '/organizations/org-slug/releases/',
  559. body: [ReleaseFixture()],
  560. });
  561. initialData = initializeOrg({
  562. organization: OrganizationFixture({
  563. features: [
  564. 'global-views',
  565. 'dashboards-basic',
  566. 'dashboards-edit',
  567. 'discover-query',
  568. ],
  569. }),
  570. });
  571. render(
  572. <OrganizationContext.Provider value={initialData.organization}>
  573. <ViewEditDashboard
  574. {...RouteComponentPropsFixture()}
  575. organization={initialData.organization}
  576. params={{orgId: 'org-slug', dashboardId: '1'}}
  577. router={initialData.router}
  578. location={initialData.router.location}
  579. >
  580. {null}
  581. </ViewEditDashboard>
  582. </OrganizationContext.Provider>,
  583. {router: initialData.router}
  584. );
  585. expect(await screen.findByText('All Releases')).toBeInTheDocument();
  586. expect(mockReleases).toHaveBeenCalledTimes(2); // Called once when PageFiltersStore is initialized
  587. });
  588. it('hides add widget option', async function () {
  589. // @ts-expect-error this is assigning to readonly property...
  590. types.MAX_WIDGETS = 1;
  591. render(
  592. <OrganizationContext.Provider value={initialData.organization}>
  593. <ViewEditDashboard
  594. {...RouteComponentPropsFixture()}
  595. organization={initialData.organization}
  596. params={{orgId: 'org-slug', dashboardId: '1'}}
  597. router={initialData.router}
  598. location={initialData.router.location}
  599. >
  600. {null}
  601. </ViewEditDashboard>
  602. </OrganizationContext.Provider>,
  603. {router: initialData.router}
  604. );
  605. // Enter edit mode.
  606. await userEvent.click(await screen.findByRole('button', {name: 'Edit Dashboard'}));
  607. expect(screen.queryByRole('button', {name: 'Add widget'})).not.toBeInTheDocument();
  608. });
  609. it('renders successfully if more widgets than stored layouts', async function () {
  610. // A case where someone has async added widgets to a dashboard
  611. MockApiClient.addMockResponse({
  612. url: '/organizations/org-slug/dashboards/1/',
  613. body: DashboardFixture(
  614. [
  615. WidgetFixture({
  616. queries: [
  617. {
  618. name: '',
  619. conditions: 'event.type:error',
  620. fields: ['count()'],
  621. aggregates: ['count()'],
  622. columns: [],
  623. orderby: '-count()',
  624. },
  625. ],
  626. title: 'First Widget',
  627. interval: '1d',
  628. id: '1',
  629. layout: {x: 0, y: 0, w: 2, h: 6, minH: 0},
  630. }),
  631. WidgetFixture({
  632. queries: [
  633. {
  634. name: '',
  635. conditions: 'event.type:error',
  636. fields: ['count()'],
  637. aggregates: ['count()'],
  638. columns: [],
  639. orderby: '-count()',
  640. },
  641. ],
  642. title: 'Second Widget',
  643. interval: '1d',
  644. id: '2',
  645. }),
  646. ],
  647. {id: '1', title: 'Custom Errors'}
  648. ),
  649. });
  650. render(
  651. <ViewEditDashboard
  652. {...RouteComponentPropsFixture()}
  653. organization={initialData.organization}
  654. params={{orgId: 'org-slug', dashboardId: '1'}}
  655. router={initialData.router}
  656. location={initialData.router.location}
  657. >
  658. {null}
  659. </ViewEditDashboard>,
  660. {router: initialData.router, organization: initialData.organization}
  661. );
  662. expect(await screen.findByText('First Widget')).toBeInTheDocument();
  663. expect(await screen.findByText('Second Widget')).toBeInTheDocument();
  664. });
  665. it('does not trigger request if layout not updated', async () => {
  666. MockApiClient.addMockResponse({
  667. url: '/organizations/org-slug/dashboards/1/',
  668. body: DashboardFixture(
  669. [
  670. WidgetFixture({
  671. queries: [
  672. {
  673. name: '',
  674. conditions: 'event.type:error',
  675. fields: ['count()'],
  676. aggregates: ['count()'],
  677. columns: [],
  678. orderby: '-count()',
  679. },
  680. ],
  681. title: 'First Widget',
  682. interval: '1d',
  683. id: '1',
  684. layout: {x: 0, y: 0, w: 2, h: 6, minH: 0},
  685. }),
  686. ],
  687. {id: '1', title: 'Custom Errors'}
  688. ),
  689. });
  690. render(
  691. <ViewEditDashboard
  692. {...RouteComponentPropsFixture()}
  693. organization={initialData.organization}
  694. params={{orgId: 'org-slug', dashboardId: '1'}}
  695. router={initialData.router}
  696. location={initialData.router.location}
  697. >
  698. {null}
  699. </ViewEditDashboard>,
  700. {router: initialData.router, organization: initialData.organization}
  701. );
  702. await userEvent.click(await screen.findByText('Edit Dashboard'));
  703. await userEvent.click(await screen.findByText('Save and Finish'));
  704. expect(screen.getByText('Edit Dashboard')).toBeInTheDocument();
  705. expect(mockPut).not.toHaveBeenCalled();
  706. });
  707. it('renders the custom resize handler for a widget', async () => {
  708. MockApiClient.addMockResponse({
  709. url: '/organizations/org-slug/dashboards/1/',
  710. body: DashboardFixture(
  711. [
  712. WidgetFixture({
  713. queries: [
  714. {
  715. name: '',
  716. conditions: 'event.type:error',
  717. fields: ['count()'],
  718. aggregates: ['count()'],
  719. columns: [],
  720. orderby: '-count()',
  721. },
  722. ],
  723. title: 'First Widget',
  724. interval: '1d',
  725. id: '1',
  726. layout: {x: 0, y: 0, w: 2, h: 6, minH: 0},
  727. }),
  728. ],
  729. {id: '1', title: 'Custom Errors'}
  730. ),
  731. });
  732. render(
  733. <ViewEditDashboard
  734. {...RouteComponentPropsFixture()}
  735. organization={initialData.organization}
  736. params={{orgId: 'org-slug', dashboardId: '1'}}
  737. router={initialData.router}
  738. location={initialData.router.location}
  739. >
  740. {null}
  741. </ViewEditDashboard>,
  742. {router: initialData.router, organization: initialData.organization}
  743. );
  744. await userEvent.click(await screen.findByText('Edit Dashboard'));
  745. const widget = (await screen.findByText('First Widget')).closest(
  746. '.react-grid-item'
  747. ) as HTMLElement;
  748. const resizeHandle = within(widget).getByTestId('custom-resize-handle');
  749. expect(resizeHandle).toBeVisible();
  750. });
  751. it('does not trigger an alert when the widgets have no layout and user cancels without changes', async () => {
  752. MockApiClient.addMockResponse({
  753. url: '/organizations/org-slug/dashboards/1/',
  754. body: DashboardFixture(
  755. [
  756. WidgetFixture({
  757. queries: [
  758. {
  759. name: '',
  760. conditions: 'event.type:error',
  761. fields: ['count()'],
  762. aggregates: ['count()'],
  763. columns: [],
  764. orderby: '-count()',
  765. },
  766. ],
  767. title: 'First Widget',
  768. interval: '1d',
  769. id: '1',
  770. layout: null,
  771. }),
  772. ],
  773. {id: '1', title: 'Custom Errors'}
  774. ),
  775. });
  776. render(
  777. <ViewEditDashboard
  778. {...RouteComponentPropsFixture()}
  779. organization={initialData.organization}
  780. params={{orgId: 'org-slug', dashboardId: '1'}}
  781. router={initialData.router}
  782. location={initialData.router.location}
  783. >
  784. {null}
  785. </ViewEditDashboard>,
  786. {router: initialData.router, organization: initialData.organization}
  787. );
  788. await userEvent.click(await screen.findByText('Edit Dashboard'));
  789. await userEvent.click(await screen.findByText('Cancel'));
  790. expect(window.confirm).not.toHaveBeenCalled();
  791. });
  792. it('opens the widget viewer modal using the widget id specified in the url', async () => {
  793. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  794. const widget = WidgetFixture({
  795. queries: [
  796. {
  797. name: '',
  798. conditions: 'event.type:error',
  799. fields: ['count()'],
  800. aggregates: ['count()'],
  801. columns: [],
  802. orderby: '',
  803. },
  804. ],
  805. title: 'First Widget',
  806. interval: '1d',
  807. id: '1',
  808. layout: null,
  809. });
  810. MockApiClient.addMockResponse({
  811. url: '/organizations/org-slug/dashboards/1/',
  812. body: DashboardFixture([widget], {id: '1', title: 'Custom Errors'}),
  813. });
  814. render(
  815. <ViewEditDashboard
  816. {...RouteComponentPropsFixture()}
  817. organization={initialData.organization}
  818. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 1}}
  819. router={initialData.router}
  820. location={{...initialData.router.location, pathname: '/widget/123/'}}
  821. >
  822. {null}
  823. </ViewEditDashboard>,
  824. {router: initialData.router, organization: initialData.organization}
  825. );
  826. await waitFor(() => {
  827. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  828. expect.objectContaining({
  829. organization: initialData.organization,
  830. widget,
  831. onClose: expect.anything(),
  832. })
  833. );
  834. });
  835. });
  836. it('redirects user to dashboard url if widget is not found', async () => {
  837. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  838. MockApiClient.addMockResponse({
  839. url: '/organizations/org-slug/dashboards/1/',
  840. body: DashboardFixture([], {id: '1', title: 'Custom Errors'}),
  841. });
  842. render(
  843. <ViewEditDashboard
  844. {...RouteComponentPropsFixture()}
  845. organization={initialData.organization}
  846. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 123}}
  847. router={initialData.router}
  848. location={{...initialData.router.location, pathname: '/widget/123/'}}
  849. >
  850. {null}
  851. </ViewEditDashboard>,
  852. {router: initialData.router, organization: initialData.organization}
  853. );
  854. expect(await screen.findByText('All Releases')).toBeInTheDocument();
  855. expect(openWidgetViewerModal).not.toHaveBeenCalled();
  856. expect(initialData.router.replace).toHaveBeenCalledWith(
  857. expect.objectContaining({
  858. pathname: '/organizations/org-slug/dashboard/1/',
  859. query: {},
  860. })
  861. );
  862. });
  863. it('saves a new dashboard with the page filters', async () => {
  864. const mockPOST = MockApiClient.addMockResponse({
  865. url: '/organizations/org-slug/dashboards/',
  866. method: 'POST',
  867. body: [],
  868. });
  869. render(
  870. <CreateDashboard
  871. {...RouteComponentPropsFixture()}
  872. organization={initialData.organization}
  873. params={{templateId: undefined}}
  874. router={initialData.router}
  875. location={{
  876. ...initialData.router.location,
  877. query: {
  878. ...initialData.router.location.query,
  879. statsPeriod: '7d',
  880. project: [2],
  881. environment: ['alpha', 'beta'],
  882. },
  883. }}
  884. >
  885. {null}
  886. </CreateDashboard>,
  887. {
  888. router: initialData.router,
  889. organization: initialData.organization,
  890. }
  891. );
  892. await userEvent.click(await screen.findByText('Save and Finish'));
  893. expect(mockPOST).toHaveBeenCalledWith(
  894. '/organizations/org-slug/dashboards/',
  895. expect.objectContaining({
  896. data: expect.objectContaining({
  897. projects: [2],
  898. environment: ['alpha', 'beta'],
  899. period: '7d',
  900. }),
  901. })
  902. );
  903. });
  904. it('saves a template with the page filters', async () => {
  905. const mockPOST = MockApiClient.addMockResponse({
  906. url: '/organizations/org-slug/dashboards/',
  907. method: 'POST',
  908. body: [],
  909. });
  910. render(
  911. <CreateDashboard
  912. {...RouteComponentPropsFixture()}
  913. organization={initialData.organization}
  914. params={{templateId: 'default-template'}}
  915. router={initialData.router}
  916. location={{
  917. ...initialData.router.location,
  918. query: {
  919. ...initialData.router.location.query,
  920. statsPeriod: '7d',
  921. project: [2],
  922. environment: ['alpha', 'beta'],
  923. },
  924. }}
  925. >
  926. {null}
  927. </CreateDashboard>,
  928. {
  929. router: initialData.router,
  930. organization: initialData.organization,
  931. }
  932. );
  933. await userEvent.click(await screen.findByText('Add Dashboard'));
  934. expect(mockPOST).toHaveBeenCalledWith(
  935. '/organizations/org-slug/dashboards/',
  936. expect.objectContaining({
  937. data: expect.objectContaining({
  938. projects: [2],
  939. environment: ['alpha', 'beta'],
  940. period: '7d',
  941. }),
  942. })
  943. );
  944. });
  945. it('does not render save and cancel buttons on templates', async () => {
  946. MockApiClient.addMockResponse({
  947. url: '/organizations/org-slug/releases/',
  948. body: [
  949. ReleaseFixture({
  950. shortVersion: 'sentry-android-shop@1.2.0',
  951. version: 'sentry-android-shop@1.2.0',
  952. }),
  953. ],
  954. });
  955. render(
  956. <CreateDashboard
  957. {...RouteComponentPropsFixture()}
  958. organization={initialData.organization}
  959. params={{templateId: 'default-template'}}
  960. router={initialData.router}
  961. location={initialData.router.location}
  962. >
  963. {null}
  964. </CreateDashboard>,
  965. {
  966. router: initialData.router,
  967. organization: initialData.organization,
  968. }
  969. );
  970. await userEvent.click(await screen.findByText('24H'));
  971. await userEvent.click(screen.getByText('Last 7 days'));
  972. await screen.findByText('7D');
  973. expect(screen.queryByText('Cancel')).not.toBeInTheDocument();
  974. expect(screen.queryByText('Save')).not.toBeInTheDocument();
  975. });
  976. it('opens the widget viewer with saved dashboard filters', async () => {
  977. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  978. MockApiClient.addMockResponse({
  979. url: '/organizations/org-slug/dashboards/1/',
  980. body: DashboardFixture(widgets, {
  981. id: '1',
  982. filters: {release: ['sentry-android-shop@1.2.0']},
  983. }),
  984. });
  985. render(
  986. <ViewEditDashboard
  987. {...RouteComponentPropsFixture()}
  988. organization={initialData.organization}
  989. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 1}}
  990. router={initialData.router}
  991. location={{...initialData.router.location, pathname: '/widget/1/'}}
  992. >
  993. {null}
  994. </ViewEditDashboard>,
  995. {router: initialData.router, organization: initialData.organization}
  996. );
  997. await waitFor(() => {
  998. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  999. expect.objectContaining({
  1000. dashboardFilters: {release: ['sentry-android-shop@1.2.0']},
  1001. })
  1002. );
  1003. });
  1004. });
  1005. it('opens the widget viewer with unsaved dashboard filters', async () => {
  1006. const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
  1007. MockApiClient.addMockResponse({
  1008. url: '/organizations/org-slug/dashboards/1/',
  1009. body: DashboardFixture(widgets, {
  1010. id: '1',
  1011. filters: {release: ['sentry-android-shop@1.2.0']},
  1012. }),
  1013. });
  1014. render(
  1015. <ViewEditDashboard
  1016. {...RouteComponentPropsFixture()}
  1017. organization={initialData.organization}
  1018. params={{orgId: 'org-slug', dashboardId: '1', widgetId: 1}}
  1019. router={initialData.router}
  1020. location={{
  1021. ...initialData.router.location,
  1022. pathname: '/widget/1/',
  1023. query: {release: ['unsaved-release-filter@1.2.0']},
  1024. }}
  1025. >
  1026. {null}
  1027. </ViewEditDashboard>,
  1028. {router: initialData.router, organization: initialData.organization}
  1029. );
  1030. await waitFor(() => {
  1031. expect(openWidgetViewerModal).toHaveBeenCalledWith(
  1032. expect.objectContaining({
  1033. dashboardFilters: {release: ['unsaved-release-filter@1.2.0']},
  1034. })
  1035. );
  1036. });
  1037. });
  1038. it('can save dashboard filters in existing dashboard', async () => {
  1039. MockApiClient.addMockResponse({
  1040. url: '/organizations/org-slug/releases/',
  1041. body: [
  1042. ReleaseFixture({
  1043. shortVersion: 'sentry-android-shop@1.2.0',
  1044. version: 'sentry-android-shop@1.2.0',
  1045. }),
  1046. ],
  1047. });
  1048. const testData = initializeOrg({
  1049. organization: OrganizationFixture({
  1050. features: [
  1051. 'global-views',
  1052. 'dashboards-basic',
  1053. 'dashboards-edit',
  1054. 'discover-query',
  1055. ],
  1056. }),
  1057. router: {
  1058. location: {
  1059. ...LocationFixture(),
  1060. query: {
  1061. statsPeriod: '7d',
  1062. release: ['sentry-android-shop@1.2.0'],
  1063. },
  1064. },
  1065. },
  1066. });
  1067. render(
  1068. <ViewEditDashboard
  1069. {...RouteComponentPropsFixture()}
  1070. organization={testData.organization}
  1071. params={{orgId: 'org-slug', dashboardId: '1'}}
  1072. router={testData.router}
  1073. location={testData.router.location}
  1074. >
  1075. {null}
  1076. </ViewEditDashboard>,
  1077. {router: testData.router, organization: testData.organization}
  1078. );
  1079. await userEvent.click(await screen.findByText('Save'));
  1080. expect(mockPut).toHaveBeenCalledWith(
  1081. '/organizations/org-slug/dashboards/1/',
  1082. expect.objectContaining({
  1083. data: expect.objectContaining({
  1084. period: '7d',
  1085. filters: {release: ['sentry-android-shop@1.2.0']},
  1086. }),
  1087. })
  1088. );
  1089. });
  1090. it('can clear dashboard filters in compact select', async () => {
  1091. MockApiClient.addMockResponse({
  1092. url: '/organizations/org-slug/dashboards/1/',
  1093. body: DashboardFixture(widgets, {
  1094. id: '1',
  1095. title: 'Custom Errors',
  1096. filters: {release: ['sentry-android-shop@1.2.0']},
  1097. }),
  1098. });
  1099. MockApiClient.addMockResponse({
  1100. url: '/organizations/org-slug/releases/',
  1101. body: [
  1102. ReleaseFixture({
  1103. shortVersion: 'sentry-android-shop@1.2.0',
  1104. version: 'sentry-android-shop@1.2.0',
  1105. }),
  1106. ],
  1107. });
  1108. const testData = initializeOrg({
  1109. organization: OrganizationFixture({
  1110. features: [
  1111. 'global-views',
  1112. 'dashboards-basic',
  1113. 'dashboards-edit',
  1114. 'discover-query',
  1115. ],
  1116. }),
  1117. router: {
  1118. location: {
  1119. ...LocationFixture(),
  1120. query: {
  1121. statsPeriod: '7d',
  1122. },
  1123. },
  1124. },
  1125. });
  1126. render(
  1127. <ViewEditDashboard
  1128. {...RouteComponentPropsFixture()}
  1129. organization={testData.organization}
  1130. params={{orgId: 'org-slug', dashboardId: '1'}}
  1131. router={testData.router}
  1132. location={testData.router.location}
  1133. >
  1134. {null}
  1135. </ViewEditDashboard>,
  1136. {router: testData.router, organization: testData.organization}
  1137. );
  1138. await screen.findByText('7D');
  1139. await userEvent.click(await screen.findByText('sentry-android-shop@1.2.0'));
  1140. await userEvent.click(screen.getAllByText('Clear')[0]);
  1141. screen.getByText('All Releases');
  1142. await userEvent.click(document.body);
  1143. await waitFor(() => {
  1144. expect(browserHistory.push).toHaveBeenCalledWith(
  1145. expect.objectContaining({
  1146. query: expect.objectContaining({
  1147. release: '',
  1148. }),
  1149. })
  1150. );
  1151. });
  1152. });
  1153. it('can save absolute time range in existing dashboard', async () => {
  1154. const testData = initializeOrg({
  1155. organization: OrganizationFixture({
  1156. features: [
  1157. 'global-views',
  1158. 'dashboards-basic',
  1159. 'dashboards-edit',
  1160. 'discover-query',
  1161. ],
  1162. }),
  1163. router: {
  1164. location: {
  1165. ...LocationFixture(),
  1166. query: {
  1167. start: '2022-07-14T07:00:00',
  1168. end: '2022-07-19T23:59:59',
  1169. utc: 'true',
  1170. },
  1171. },
  1172. },
  1173. });
  1174. render(
  1175. <ViewEditDashboard
  1176. {...RouteComponentPropsFixture()}
  1177. organization={testData.organization}
  1178. params={{orgId: 'org-slug', dashboardId: '1'}}
  1179. router={testData.router}
  1180. location={testData.router.location}
  1181. >
  1182. {null}
  1183. </ViewEditDashboard>,
  1184. {router: testData.router, organization: testData.organization}
  1185. );
  1186. await userEvent.click(await screen.findByText('Save'));
  1187. expect(mockPut).toHaveBeenCalledWith(
  1188. '/organizations/org-slug/dashboards/1/',
  1189. expect.objectContaining({
  1190. data: expect.objectContaining({
  1191. start: '2022-07-14T07:00:00.000',
  1192. end: '2022-07-19T23:59:59.000',
  1193. utc: true,
  1194. }),
  1195. })
  1196. );
  1197. });
  1198. it('can clear dashboard filters in existing dashboard', async () => {
  1199. MockApiClient.addMockResponse({
  1200. url: '/organizations/org-slug/releases/',
  1201. body: [
  1202. ReleaseFixture({
  1203. shortVersion: 'sentry-android-shop@1.2.0',
  1204. version: 'sentry-android-shop@1.2.0',
  1205. }),
  1206. ],
  1207. });
  1208. const testData = initializeOrg({
  1209. organization: OrganizationFixture({
  1210. features: [
  1211. 'global-views',
  1212. 'dashboards-basic',
  1213. 'dashboards-edit',
  1214. 'discover-query',
  1215. ],
  1216. }),
  1217. router: {
  1218. location: {
  1219. ...LocationFixture(),
  1220. query: {
  1221. statsPeriod: '7d',
  1222. environment: ['alpha', 'beta'],
  1223. },
  1224. },
  1225. },
  1226. });
  1227. render(
  1228. <ViewEditDashboard
  1229. {...RouteComponentPropsFixture()}
  1230. organization={testData.organization}
  1231. params={{orgId: 'org-slug', dashboardId: '1'}}
  1232. router={testData.router}
  1233. location={testData.router.location}
  1234. >
  1235. {null}
  1236. </ViewEditDashboard>,
  1237. {router: testData.router, organization: testData.organization}
  1238. );
  1239. await screen.findByText('7D');
  1240. await userEvent.click(await screen.findByText('All Releases'));
  1241. await userEvent.click(screen.getByText('sentry-android-shop@1.2.0'));
  1242. await userEvent.keyboard('{Escape}');
  1243. await userEvent.click(screen.getByText('Cancel'));
  1244. screen.getByText('All Releases');
  1245. expect(browserHistory.replace).toHaveBeenCalledWith(
  1246. expect.objectContaining({
  1247. query: expect.objectContaining({
  1248. project: undefined,
  1249. statsPeriod: undefined,
  1250. environment: undefined,
  1251. }),
  1252. })
  1253. );
  1254. });
  1255. it('disables the Edit Dashboard button when there are unsaved filters', async () => {
  1256. MockApiClient.addMockResponse({
  1257. url: '/organizations/org-slug/releases/',
  1258. body: [
  1259. ReleaseFixture({
  1260. shortVersion: 'sentry-android-shop@1.2.0',
  1261. version: 'sentry-android-shop@1.2.0',
  1262. }),
  1263. ],
  1264. });
  1265. const testData = initializeOrg({
  1266. organization: OrganizationFixture({
  1267. features: [
  1268. 'global-views',
  1269. 'dashboards-basic',
  1270. 'dashboards-edit',
  1271. 'discover-basic',
  1272. 'discover-query',
  1273. ],
  1274. }),
  1275. router: {
  1276. location: {
  1277. ...LocationFixture(),
  1278. query: {
  1279. statsPeriod: '7d',
  1280. environment: ['alpha', 'beta'],
  1281. },
  1282. },
  1283. },
  1284. });
  1285. render(
  1286. <ViewEditDashboard
  1287. {...RouteComponentPropsFixture()}
  1288. organization={testData.organization}
  1289. params={{orgId: 'org-slug', dashboardId: '1'}}
  1290. router={testData.router}
  1291. location={testData.router.location}
  1292. >
  1293. {null}
  1294. </ViewEditDashboard>,
  1295. {router: testData.router, organization: testData.organization}
  1296. );
  1297. expect(await screen.findByText('Save')).toBeInTheDocument();
  1298. expect(screen.getByText('Cancel')).toBeInTheDocument();
  1299. expect(screen.getByRole('button', {name: 'Edit Dashboard'})).toBeDisabled();
  1300. });
  1301. it('ignores the order of selection of page filters to render unsaved filters', async () => {
  1302. const testProjects = [
  1303. ProjectFixture({id: '1', name: 'first', environments: ['alpha', 'beta']}),
  1304. ProjectFixture({id: '2', name: 'second', environments: ['alpha', 'beta']}),
  1305. ];
  1306. act(() => ProjectsStore.loadInitialData(testProjects));
  1307. MockApiClient.addMockResponse({
  1308. url: '/organizations/org-slug/projects/',
  1309. body: testProjects,
  1310. });
  1311. MockApiClient.addMockResponse({
  1312. url: '/organizations/org-slug/dashboards/1/',
  1313. body: DashboardFixture(widgets, {
  1314. id: '1',
  1315. title: 'Custom Errors',
  1316. filters: {},
  1317. environment: ['alpha', 'beta'],
  1318. }),
  1319. });
  1320. const testData = initializeOrg({
  1321. organization: OrganizationFixture({
  1322. features: [
  1323. 'global-views',
  1324. 'dashboards-basic',
  1325. 'dashboards-edit',
  1326. 'discover-query',
  1327. ],
  1328. }),
  1329. router: {
  1330. location: {
  1331. ...LocationFixture(),
  1332. query: {
  1333. environment: ['beta', 'alpha'], // Reversed order from saved dashboard
  1334. },
  1335. },
  1336. },
  1337. });
  1338. render(
  1339. <ViewEditDashboard
  1340. {...RouteComponentPropsFixture()}
  1341. organization={testData.organization}
  1342. params={{orgId: 'org-slug', dashboardId: '1'}}
  1343. router={testData.router}
  1344. location={testData.router.location}
  1345. >
  1346. {null}
  1347. </ViewEditDashboard>,
  1348. {router: testData.router, organization: testData.organization}
  1349. );
  1350. await waitFor(() => expect(screen.queryAllByText('Loading\u2026')).toEqual([]));
  1351. await userEvent.click(screen.getByRole('button', {name: 'All Envs'}));
  1352. expect(screen.getByRole('row', {name: 'alpha'})).toHaveAttribute(
  1353. 'aria-selected',
  1354. 'true'
  1355. );
  1356. expect(screen.getByRole('row', {name: 'beta'})).toHaveAttribute(
  1357. 'aria-selected',
  1358. 'true'
  1359. );
  1360. // Save and Cancel should not appear because alpha, beta is the same as beta, alpha
  1361. expect(screen.queryByText('Save')).not.toBeInTheDocument();
  1362. expect(screen.queryByText('Cancel')).not.toBeInTheDocument();
  1363. });
  1364. it('uses releases from the URL query params', async function () {
  1365. const testData = initializeOrg({
  1366. organization: OrganizationFixture({
  1367. features: [
  1368. 'global-views',
  1369. 'dashboards-basic',
  1370. 'dashboards-edit',
  1371. 'discover-query',
  1372. ],
  1373. }),
  1374. router: {
  1375. location: {
  1376. ...LocationFixture(),
  1377. query: {
  1378. release: ['not-selected-1'],
  1379. },
  1380. },
  1381. },
  1382. });
  1383. render(
  1384. <ViewEditDashboard
  1385. {...RouteComponentPropsFixture()}
  1386. organization={testData.organization}
  1387. params={{orgId: 'org-slug', dashboardId: '1'}}
  1388. router={testData.router}
  1389. location={testData.router.location}
  1390. >
  1391. {null}
  1392. </ViewEditDashboard>,
  1393. {router: testData.router, organization: testData.organization}
  1394. );
  1395. await screen.findByText(/not-selected-1/);
  1396. screen.getByText('Save');
  1397. screen.getByText('Cancel');
  1398. });
  1399. it('resets release in URL params', async function () {
  1400. MockApiClient.addMockResponse({
  1401. url: '/organizations/org-slug/dashboards/1/',
  1402. body: DashboardFixture(widgets, {
  1403. id: '1',
  1404. title: 'Custom Errors',
  1405. filters: {
  1406. release: ['abc'],
  1407. },
  1408. }),
  1409. });
  1410. const testData = initializeOrg({
  1411. organization: OrganizationFixture({
  1412. features: [
  1413. 'global-views',
  1414. 'dashboards-basic',
  1415. 'dashboards-edit',
  1416. 'discover-query',
  1417. ],
  1418. }),
  1419. router: {
  1420. location: {
  1421. ...LocationFixture(),
  1422. query: {
  1423. release: ['not-selected-1'],
  1424. },
  1425. },
  1426. },
  1427. });
  1428. render(
  1429. <ViewEditDashboard
  1430. {...RouteComponentPropsFixture()}
  1431. organization={testData.organization}
  1432. params={{orgId: 'org-slug', dashboardId: '1'}}
  1433. router={testData.router}
  1434. location={testData.router.location}
  1435. >
  1436. {null}
  1437. </ViewEditDashboard>,
  1438. {router: testData.router, organization: testData.organization}
  1439. );
  1440. await screen.findByText(/not-selected-1/);
  1441. await userEvent.click(screen.getByText('Cancel'));
  1442. // release isn't used in the redirect
  1443. expect(browserHistory.replace).toHaveBeenCalledWith(
  1444. expect.objectContaining({
  1445. query: {
  1446. end: undefined,
  1447. environment: undefined,
  1448. project: undefined,
  1449. start: undefined,
  1450. statsPeriod: undefined,
  1451. utc: undefined,
  1452. },
  1453. })
  1454. );
  1455. });
  1456. it('reflects selections in the release filter in the query params', async function () {
  1457. MockApiClient.addMockResponse({
  1458. url: '/organizations/org-slug/releases/',
  1459. body: [
  1460. ReleaseFixture({
  1461. shortVersion: 'sentry-android-shop@1.2.0',
  1462. version: 'sentry-android-shop@1.2.0',
  1463. }),
  1464. ],
  1465. });
  1466. const testData = initializeOrg({
  1467. organization: OrganizationFixture({
  1468. features: [
  1469. 'global-views',
  1470. 'dashboards-basic',
  1471. 'dashboards-edit',
  1472. 'discover-query',
  1473. ],
  1474. }),
  1475. router: {
  1476. location: LocationFixture(),
  1477. },
  1478. });
  1479. render(
  1480. <ViewEditDashboard
  1481. {...RouteComponentPropsFixture()}
  1482. organization={testData.organization}
  1483. params={{orgId: 'org-slug', dashboardId: '1'}}
  1484. router={testData.router}
  1485. location={testData.router.location}
  1486. >
  1487. {null}
  1488. </ViewEditDashboard>,
  1489. {router: testData.router, organization: testData.organization}
  1490. );
  1491. await userEvent.click(await screen.findByText('All Releases'));
  1492. await userEvent.click(screen.getByText('sentry-android-shop@1.2.0'));
  1493. await userEvent.click(document.body);
  1494. await waitFor(() => {
  1495. expect(browserHistory.push).toHaveBeenCalledWith(
  1496. expect.objectContaining({
  1497. query: expect.objectContaining({
  1498. release: ['sentry-android-shop@1.2.0'],
  1499. }),
  1500. })
  1501. );
  1502. });
  1503. });
  1504. it('persists release selections made during search requests that do not appear in default query', async function () {
  1505. // Default response
  1506. MockApiClient.addMockResponse({
  1507. url: '/organizations/org-slug/releases/',
  1508. body: [
  1509. ReleaseFixture({
  1510. shortVersion: 'sentry-android-shop@1.2.0',
  1511. version: 'sentry-android-shop@1.2.0',
  1512. }),
  1513. ],
  1514. });
  1515. // Mocked search results
  1516. MockApiClient.addMockResponse({
  1517. url: '/organizations/org-slug/releases/',
  1518. body: [
  1519. ReleaseFixture({
  1520. id: '9',
  1521. shortVersion: 'search-result',
  1522. version: 'search-result',
  1523. }),
  1524. ],
  1525. match: [MockApiClient.matchData({query: 's'})],
  1526. });
  1527. const testData = initializeOrg({
  1528. organization: OrganizationFixture({
  1529. features: [
  1530. 'global-views',
  1531. 'dashboards-basic',
  1532. 'dashboards-edit',
  1533. 'discover-basic',
  1534. 'discover-query',
  1535. ],
  1536. }),
  1537. router: {
  1538. location: LocationFixture(),
  1539. },
  1540. });
  1541. render(
  1542. <ViewEditDashboard
  1543. {...RouteComponentPropsFixture()}
  1544. organization={testData.organization}
  1545. params={{orgId: 'org-slug', dashboardId: '1'}}
  1546. router={testData.router}
  1547. location={testData.router.location}
  1548. >
  1549. {null}
  1550. </ViewEditDashboard>,
  1551. {router: testData.router, organization: testData.organization}
  1552. );
  1553. await userEvent.click(await screen.findByText('All Releases'));
  1554. await userEvent.type(screen.getAllByPlaceholderText('Search\u2026')[2], 's');
  1555. await userEvent.click(await screen.findByRole('option', {name: 'search-result'}));
  1556. // Validate that after search is cleared, search result still appears
  1557. expect(await screen.findByText('Latest Release(s)')).toBeInTheDocument();
  1558. expect(screen.getByRole('option', {name: 'search-result'})).toBeInTheDocument();
  1559. });
  1560. it('renders edit access selector', async function () {
  1561. render(
  1562. <EditAccessSelector
  1563. dashboard={DashboardFixture([], {id: '1', title: 'Custom Errors'})}
  1564. onChangeEditAccess={jest.fn()}
  1565. />,
  1566. {
  1567. router: initialData.router,
  1568. organization: {
  1569. features: ['dashboards-edit-access'],
  1570. ...initialData.organization,
  1571. },
  1572. }
  1573. );
  1574. await userEvent.click(await screen.findByText('Edit Access:'));
  1575. expect(screen.getByText('Creator')).toBeInTheDocument();
  1576. expect(screen.getByText('All users')).toBeInTheDocument();
  1577. });
  1578. it('creates and updates new permissions for dashboard with no edit perms initialized', async function () {
  1579. const mockPUT = MockApiClient.addMockResponse({
  1580. url: '/organizations/org-slug/dashboards/1/',
  1581. method: 'PUT',
  1582. body: DashboardFixture([], {id: '1', title: 'Custom Errors'}),
  1583. });
  1584. render(
  1585. <ViewEditDashboard
  1586. {...RouteComponentPropsFixture()}
  1587. organization={{
  1588. ...initialData.organization,
  1589. features: ['dashboards-edit-access', ...initialData.organization.features],
  1590. }}
  1591. params={{orgId: 'org-slug', dashboardId: '1'}}
  1592. router={initialData.router}
  1593. location={initialData.router.location}
  1594. >
  1595. {null}
  1596. </ViewEditDashboard>,
  1597. {
  1598. router: initialData.router,
  1599. organization: {
  1600. features: ['dashboards-edit-access', ...initialData.organization.features],
  1601. },
  1602. }
  1603. );
  1604. await userEvent.click(await screen.findByText('Edit Access:'));
  1605. // deselects 'All users' so only creator has edit access
  1606. expect(await screen.findByText('All users')).toBeEnabled();
  1607. expect(await screen.findByRole('option', {name: 'All users'})).toHaveAttribute(
  1608. 'aria-selected',
  1609. 'true'
  1610. );
  1611. await userEvent.click(screen.getByRole('option', {name: 'All users'}));
  1612. expect(await screen.findByRole('option', {name: 'All users'})).toHaveAttribute(
  1613. 'aria-selected',
  1614. 'false'
  1615. );
  1616. await userEvent.click(await screen.findByText('Save Changes'));
  1617. await waitFor(() => {
  1618. expect(mockPUT).toHaveBeenCalledTimes(1);
  1619. expect(mockPUT).toHaveBeenCalledWith(
  1620. '/organizations/org-slug/dashboards/1/',
  1621. expect.objectContaining({
  1622. data: expect.objectContaining({
  1623. permissions: {isEditableByEveryone: false, teamsWithEditAccess: []},
  1624. }),
  1625. })
  1626. );
  1627. });
  1628. });
  1629. it('creator can update permissions for dashboard', async function () {
  1630. const mockPUT = MockApiClient.addMockResponse({
  1631. url: '/organizations/org-slug/dashboards/1/',
  1632. method: 'PUT',
  1633. body: DashboardFixture([], {id: '1', title: 'Custom Errors'}),
  1634. });
  1635. MockApiClient.addMockResponse({
  1636. url: '/organizations/org-slug/dashboards/1/',
  1637. body: DashboardFixture([], {
  1638. id: '1',
  1639. title: 'Custom Errors',
  1640. createdBy: UserFixture({id: '781629'}),
  1641. permissions: {isEditableByEveryone: false},
  1642. }),
  1643. });
  1644. const currentUser = UserFixture({id: '781629'});
  1645. ConfigStore.set('user', currentUser);
  1646. render(
  1647. <ViewEditDashboard
  1648. {...RouteComponentPropsFixture()}
  1649. organization={{
  1650. ...initialData.organization,
  1651. features: ['dashboards-edit-access', ...initialData.organization.features],
  1652. }}
  1653. params={{orgId: 'org-slug', dashboardId: '1'}}
  1654. router={initialData.router}
  1655. location={initialData.router.location}
  1656. >
  1657. {null}
  1658. </ViewEditDashboard>,
  1659. {
  1660. router: initialData.router,
  1661. organization: {
  1662. features: ['dashboards-edit-access', ...initialData.organization.features],
  1663. },
  1664. }
  1665. );
  1666. await userEvent.click(await screen.findByText('Edit Access:'));
  1667. // selects 'All users' so everyone has edit access
  1668. expect(await screen.findByText('All users')).toBeEnabled();
  1669. expect(await screen.findByRole('option', {name: 'All users'})).toHaveAttribute(
  1670. 'aria-selected',
  1671. 'false'
  1672. );
  1673. await userEvent.click(screen.getByRole('option', {name: 'All users'}));
  1674. expect(await screen.findByRole('option', {name: 'All users'})).toHaveAttribute(
  1675. 'aria-selected',
  1676. 'true'
  1677. );
  1678. await userEvent.click(await screen.findByText('Save Changes'));
  1679. await waitFor(() => {
  1680. expect(mockPUT).toHaveBeenCalledTimes(1);
  1681. expect(mockPUT).toHaveBeenCalledWith(
  1682. '/organizations/org-slug/dashboards/1/',
  1683. expect.objectContaining({
  1684. data: expect.objectContaining({
  1685. permissions: {isEditableByEveryone: true, teamsWithEditAccess: []},
  1686. }),
  1687. })
  1688. );
  1689. });
  1690. });
  1691. it('creator can update permissions with teams for dashboard', async function () {
  1692. const mockPUT = MockApiClient.addMockResponse({
  1693. url: '/organizations/org-slug/dashboards/1/',
  1694. method: 'PUT',
  1695. body: DashboardFixture([], {id: '1', title: 'Custom Errors'}),
  1696. });
  1697. MockApiClient.addMockResponse({
  1698. url: '/organizations/org-slug/dashboards/1/',
  1699. body: DashboardFixture([], {
  1700. id: '1',
  1701. title: 'Custom Errors',
  1702. createdBy: UserFixture({id: '781629'}),
  1703. permissions: {isEditableByEveryone: false},
  1704. }),
  1705. });
  1706. const currentUser = UserFixture({id: '781629'});
  1707. ConfigStore.set('user', currentUser);
  1708. const teamData = [
  1709. {
  1710. id: '1',
  1711. slug: 'team1',
  1712. name: 'Team 1',
  1713. },
  1714. {
  1715. id: '2',
  1716. slug: 'team2',
  1717. name: 'Team 2',
  1718. },
  1719. {
  1720. id: '3',
  1721. slug: 'team3',
  1722. name: 'Team 3',
  1723. },
  1724. ];
  1725. const teams = teamData.map(data => TeamFixture(data));
  1726. TeamStore.loadInitialData(teams);
  1727. render(
  1728. <ViewEditDashboard
  1729. {...RouteComponentPropsFixture()}
  1730. organization={{
  1731. ...initialData.organization,
  1732. features: ['dashboards-edit-access', ...initialData.organization.features],
  1733. }}
  1734. params={{orgId: 'org-slug', dashboardId: '1'}}
  1735. router={initialData.router}
  1736. location={initialData.router.location}
  1737. >
  1738. {null}
  1739. </ViewEditDashboard>,
  1740. {
  1741. router: initialData.router,
  1742. organization: {
  1743. features: ['dashboards-edit-access', ...initialData.organization.features],
  1744. },
  1745. }
  1746. );
  1747. await userEvent.click(await screen.findByText('Edit Access:'));
  1748. expect(await screen.findByText('All users')).toBeEnabled();
  1749. expect(await screen.findByRole('option', {name: 'All users'})).toHaveAttribute(
  1750. 'aria-selected',
  1751. 'false'
  1752. );
  1753. await userEvent.click(screen.getByRole('option', {name: '#team1'}));
  1754. await userEvent.click(screen.getByRole('option', {name: '#team2'}));
  1755. await userEvent.click(await screen.findByText('Save Changes'));
  1756. await waitFor(() => {
  1757. expect(mockPUT).toHaveBeenCalledTimes(1);
  1758. expect(mockPUT).toHaveBeenCalledWith(
  1759. '/organizations/org-slug/dashboards/1/',
  1760. expect.objectContaining({
  1761. data: expect.objectContaining({
  1762. permissions: {isEditableByEveryone: false, teamsWithEditAccess: [1, 2]},
  1763. }),
  1764. })
  1765. );
  1766. });
  1767. });
  1768. it('disables edit dashboard and add widget button if user cannot edit dashboard', async function () {
  1769. MockApiClient.addMockResponse({
  1770. url: '/organizations/org-slug/dashboards/',
  1771. body: [
  1772. DashboardFixture([], {
  1773. id: '1',
  1774. title: 'Custom Errors',
  1775. createdBy: UserFixture({id: '238900'}),
  1776. permissions: {isEditableByEveryone: false},
  1777. }),
  1778. ],
  1779. });
  1780. MockApiClient.addMockResponse({
  1781. url: '/organizations/org-slug/dashboards/1/',
  1782. body: DashboardFixture([], {
  1783. id: '1',
  1784. title: 'Custom Errors',
  1785. createdBy: UserFixture({id: '238900'}),
  1786. permissions: {isEditableByEveryone: false},
  1787. }),
  1788. });
  1789. const currentUser = UserFixture({id: '781629', isSuperuser: false});
  1790. ConfigStore.set('user', currentUser);
  1791. render(
  1792. <ViewEditDashboard
  1793. {...RouteComponentPropsFixture()}
  1794. organization={{
  1795. ...initialData.organization,
  1796. features: ['dashboards-edit-access', ...initialData.organization.features],
  1797. access: ['org:read'],
  1798. }}
  1799. params={{orgId: 'org-slug', dashboardId: '1'}}
  1800. router={initialData.router}
  1801. location={initialData.router.location}
  1802. >
  1803. {null}
  1804. </ViewEditDashboard>,
  1805. {
  1806. router: initialData.router,
  1807. organization: {
  1808. features: ['dashboards-edit-access', ...initialData.organization.features],
  1809. access: ['org:read'],
  1810. },
  1811. }
  1812. );
  1813. await screen.findByText('Edit Access:');
  1814. expect(screen.getByRole('button', {name: 'Edit Dashboard'})).toBeDisabled();
  1815. expect(screen.getByRole('button', {name: 'Add Widget'})).toBeDisabled();
  1816. });
  1817. it('disables widget edit, duplicate, and delete button when user does not have edit perms', async function () {
  1818. const widget = {
  1819. displayType: types.DisplayType.TABLE,
  1820. interval: '1d',
  1821. queries: [
  1822. {
  1823. name: 'Test Widget',
  1824. fields: ['count()', 'count_unique(user)', 'epm()', 'project'],
  1825. columns: ['project'],
  1826. aggregates: ['count()', 'count_unique(user)', 'epm()'],
  1827. conditions: '',
  1828. orderby: '',
  1829. },
  1830. ],
  1831. title: 'Transactions',
  1832. id: '1',
  1833. widgetType: types.WidgetType.DISCOVER,
  1834. };
  1835. const mockDashboard = DashboardFixture([widget], {
  1836. id: '1',
  1837. title: 'Custom Errors',
  1838. createdBy: UserFixture({id: '238900'}),
  1839. permissions: {isEditableByEveryone: false},
  1840. });
  1841. MockApiClient.addMockResponse({
  1842. url: '/organizations/org-slug/dashboards/',
  1843. body: mockDashboard,
  1844. });
  1845. MockApiClient.addMockResponse({
  1846. url: '/organizations/org-slug/dashboards/1/',
  1847. body: mockDashboard,
  1848. });
  1849. const currentUser = UserFixture({id: '781629'});
  1850. ConfigStore.set('user', currentUser);
  1851. render(
  1852. <ViewEditDashboard
  1853. {...RouteComponentPropsFixture()}
  1854. organization={{
  1855. ...initialData.organization,
  1856. features: ['dashboards-edit-access', ...initialData.organization.features],
  1857. access: ['org:read'],
  1858. }}
  1859. params={{orgId: 'org-slug', dashboardId: '1'}}
  1860. router={initialData.router}
  1861. location={initialData.router.location}
  1862. >
  1863. {null}
  1864. </ViewEditDashboard>,
  1865. {
  1866. router: initialData.router,
  1867. organization: {
  1868. features: ['dashboards-edit-access', ...initialData.organization.features],
  1869. access: ['org:read'],
  1870. },
  1871. }
  1872. );
  1873. await screen.findByText('Edit Access:');
  1874. expect(screen.getByRole('button', {name: 'Edit Dashboard'})).toBeDisabled();
  1875. expect(screen.getByRole('button', {name: 'Add Widget'})).toBeDisabled();
  1876. await userEvent.click(await screen.findByLabelText('Widget actions'));
  1877. expect(
  1878. screen.getByRole('menuitemradio', {name: 'Duplicate Widget'})
  1879. ).toHaveAttribute('aria-disabled', 'true');
  1880. expect(screen.getByRole('menuitemradio', {name: 'Delete Widget'})).toHaveAttribute(
  1881. 'aria-disabled',
  1882. 'true'
  1883. );
  1884. expect(screen.getByRole('menuitemradio', {name: 'Edit Widget'})).toHaveAttribute(
  1885. 'aria-disabled',
  1886. 'true'
  1887. );
  1888. });
  1889. describe('discover split', function () {
  1890. it('calls the dashboard callbacks with the correct widgetType for discover split', function () {
  1891. const widget = {
  1892. displayType: types.DisplayType.TABLE,
  1893. interval: '1d',
  1894. queries: [
  1895. {
  1896. name: 'Test Widget',
  1897. fields: ['count()', 'count_unique(user)', 'epm()', 'project'],
  1898. columns: ['project'],
  1899. aggregates: ['count()', 'count_unique(user)', 'epm()'],
  1900. conditions: '',
  1901. orderby: '',
  1902. },
  1903. ],
  1904. title: 'Transactions',
  1905. id: '1',
  1906. widgetType: types.WidgetType.DISCOVER,
  1907. };
  1908. const mockDashboard = DashboardFixture([widget], {
  1909. id: '1',
  1910. title: 'Custom Errors',
  1911. });
  1912. const mockModifiedDashboard = DashboardFixture([widget], {
  1913. id: '1',
  1914. title: 'Custom Errors',
  1915. });
  1916. const mockOnDashboardUpdate = jest.fn();
  1917. const mockStateSetter = jest
  1918. .fn()
  1919. .mockImplementation(fn => fn({modifiedDashboard: mockModifiedDashboard}));
  1920. handleUpdateDashboardSplit({
  1921. widgetId: '1',
  1922. splitDecision: types.WidgetType.ERRORS,
  1923. dashboard: mockDashboard,
  1924. modifiedDashboard: mockModifiedDashboard,
  1925. onDashboardUpdate: mockOnDashboardUpdate,
  1926. stateSetter: mockStateSetter,
  1927. });
  1928. expect(mockOnDashboardUpdate).toHaveBeenCalledWith({
  1929. ...mockDashboard,
  1930. widgets: [{...widget, widgetType: types.WidgetType.ERRORS}],
  1931. });
  1932. expect(mockStateSetter).toHaveReturnedWith({
  1933. modifiedDashboard: {
  1934. ...mockModifiedDashboard,
  1935. widgets: [{...widget, widgetType: types.WidgetType.ERRORS}],
  1936. },
  1937. });
  1938. });
  1939. });
  1940. });
  1941. });