detail.spec.tsx 65 KB

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