overview.spec.jsx 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885
  1. import {browserHistory} from 'react-router';
  2. import cloneDeep from 'lodash/cloneDeep';
  3. import range from 'lodash/range';
  4. import {mountWithTheme, shallow} from 'sentry-test/enzyme';
  5. import {initializeOrg} from 'sentry-test/initializeOrg';
  6. import {act} from 'sentry-test/reactTestingLibrary';
  7. import {triggerPress} from 'sentry-test/utils';
  8. import StreamGroup from 'sentry/components/stream/group';
  9. import GroupStore from 'sentry/stores/groupStore';
  10. import ProjectsStore from 'sentry/stores/projectsStore';
  11. import TagStore from 'sentry/stores/tagStore';
  12. import * as parseLinkHeader from 'sentry/utils/parseLinkHeader';
  13. import IssueListWithStores, {IssueListOverview} from 'sentry/views/issueList/overview';
  14. import {OrganizationContext} from 'sentry/views/organizationContext';
  15. // Mock <IssueListSidebar> and <IssueListActions>
  16. jest.mock('sentry/views/issueList/sidebar', () => jest.fn(() => null));
  17. jest.mock('sentry/views/issueList/actions', () => jest.fn(() => null));
  18. jest.mock('sentry/components/stream/group', () => jest.fn(() => null));
  19. jest.mock('sentry/views/issueList/noGroupsHandler/congratsRobots', () =>
  20. jest.fn(() => null)
  21. );
  22. const DEFAULT_LINKS_HEADER =
  23. '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575731:0:1>; rel="previous"; results="false"; cursor="1443575731:0:1", ' +
  24. '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575000:0:0>; rel="next"; results="true"; cursor="1443575000:0:0"';
  25. describe('IssueList', function () {
  26. let wrapper;
  27. let props;
  28. let organization;
  29. let project;
  30. let group;
  31. let groupStats;
  32. let savedSearch;
  33. let mountWithThemeAndOrg;
  34. let fetchTagsRequest;
  35. let fetchMembersRequest;
  36. const api = new MockApiClient();
  37. const parseLinkHeaderSpy = jest.spyOn(parseLinkHeader, 'default');
  38. beforeEach(function () {
  39. // The tests fail because we have a "component update was not wrapped in act" error.
  40. // It should be safe to ignore this error, but we should remove the mock once we move to react testing library
  41. // eslint-disable-next-line no-console
  42. jest.spyOn(console, 'error').mockImplementation(jest.fn());
  43. MockApiClient.clearMockResponses();
  44. project = TestStubs.ProjectDetails({
  45. id: '3559',
  46. name: 'Foo Project',
  47. slug: 'project-slug',
  48. firstEvent: true,
  49. });
  50. organization = TestStubs.Organization({
  51. id: '1337',
  52. slug: 'org-slug',
  53. access: ['releases'],
  54. features: [],
  55. projects: [project],
  56. });
  57. savedSearch = TestStubs.Search({
  58. id: '789',
  59. query: 'is:unresolved TypeError',
  60. sort: 'date',
  61. name: 'Unresolved TypeErrors',
  62. projectId: project.id,
  63. });
  64. group = TestStubs.Group({project});
  65. MockApiClient.addMockResponse({
  66. url: '/organizations/org-slug/issues/',
  67. body: [group],
  68. headers: {
  69. Link: DEFAULT_LINKS_HEADER,
  70. },
  71. });
  72. groupStats = TestStubs.GroupStats();
  73. MockApiClient.addMockResponse({
  74. url: '/organizations/org-slug/issues-stats/',
  75. body: [groupStats],
  76. });
  77. MockApiClient.addMockResponse({
  78. url: '/organizations/org-slug/searches/',
  79. body: [savedSearch],
  80. });
  81. MockApiClient.addMockResponse({
  82. url: '/organizations/org-slug/recent-searches/',
  83. body: [],
  84. });
  85. MockApiClient.addMockResponse({
  86. url: '/organizations/org-slug/recent-searches/',
  87. method: 'POST',
  88. body: [],
  89. });
  90. MockApiClient.addMockResponse({
  91. url: '/organizations/org-slug/issues-count/',
  92. method: 'GET',
  93. body: [{}],
  94. });
  95. MockApiClient.addMockResponse({
  96. url: '/organizations/org-slug/processingissues/',
  97. method: 'GET',
  98. body: [
  99. {
  100. project: 'test-project',
  101. numIssues: 1,
  102. hasIssues: true,
  103. lastSeen: '2019-01-16T15:39:11.081Z',
  104. },
  105. ],
  106. });
  107. const tags = TestStubs.Tags();
  108. fetchTagsRequest = MockApiClient.addMockResponse({
  109. url: '/organizations/org-slug/tags/',
  110. method: 'GET',
  111. body: tags,
  112. });
  113. fetchMembersRequest = MockApiClient.addMockResponse({
  114. url: '/organizations/org-slug/users/',
  115. method: 'GET',
  116. body: [TestStubs.Member({projects: [project.slug]})],
  117. });
  118. MockApiClient.addMockResponse({
  119. url: '/organizations/org-slug/sent-first-event/',
  120. body: {sentFirstEvent: true},
  121. });
  122. MockApiClient.addMockResponse({
  123. url: '/organizations/org-slug/projects/',
  124. body: [project],
  125. });
  126. TagStore.init();
  127. mountWithThemeAndOrg = (component, opts) =>
  128. mountWithTheme(component, {
  129. ...opts,
  130. wrappingComponent: ({children}) => (
  131. <OrganizationContext.Provider value={organization}>
  132. {children}
  133. </OrganizationContext.Provider>
  134. ),
  135. });
  136. props = {
  137. api,
  138. savedSearchLoading: false,
  139. savedSearches: [savedSearch],
  140. useOrgSavedSearches: true,
  141. selection: {
  142. projects: [parseInt(organization.projects[0].id, 10)],
  143. environments: [],
  144. datetime: {period: '14d'},
  145. },
  146. location: {query: {query: 'is:unresolved'}, search: 'query=is:unresolved'},
  147. params: {orgId: organization.slug},
  148. organization,
  149. tags: tags.reduce((acc, tag) => {
  150. acc[tag.key] = tag;
  151. return acc;
  152. }),
  153. };
  154. });
  155. afterEach(function () {
  156. jest.clearAllMocks();
  157. MockApiClient.clearMockResponses();
  158. if (wrapper) {
  159. wrapper.unmount();
  160. }
  161. wrapper = null;
  162. });
  163. describe('withStores and feature flags', function () {
  164. const {router, routerContext} = initializeOrg({
  165. organization: {
  166. features: ['global-views'],
  167. slug: 'org-slug',
  168. },
  169. router: {
  170. location: {query: {}, search: ''},
  171. params: {orgId: 'org-slug'},
  172. },
  173. });
  174. const defaultProps = {};
  175. let savedSearchesRequest;
  176. let recentSearchesRequest;
  177. let issuesRequest;
  178. /* helpers */
  179. const getSavedSearchTitle = w => w.find('SavedSearchTab ButtonLabel').text().trim();
  180. const getSearchBarValue = w =>
  181. w.find('SmartSearchBarContainer textarea').prop('value').trim();
  182. const createWrapper = ({params, location, ...p} = {}) => {
  183. const newRouter = {
  184. ...router,
  185. params: {
  186. ...router.params,
  187. ...params,
  188. },
  189. location: {
  190. ...router.location,
  191. ...location,
  192. },
  193. };
  194. wrapper = mountWithThemeAndOrg(
  195. <IssueListWithStores {...newRouter} {...defaultProps} {...p} />,
  196. routerContext
  197. );
  198. };
  199. beforeEach(function () {
  200. StreamGroup.mockClear();
  201. recentSearchesRequest = MockApiClient.addMockResponse({
  202. url: '/organizations/org-slug/recent-searches/',
  203. method: 'GET',
  204. body: [],
  205. });
  206. savedSearchesRequest = MockApiClient.addMockResponse({
  207. url: '/organizations/org-slug/searches/',
  208. body: [savedSearch],
  209. });
  210. issuesRequest = MockApiClient.addMockResponse({
  211. url: '/organizations/org-slug/issues/',
  212. body: [group],
  213. headers: {
  214. Link: DEFAULT_LINKS_HEADER,
  215. },
  216. });
  217. });
  218. it('loads group rows with default query (no pinned queries, and no query in URL)', async function () {
  219. createWrapper();
  220. // Loading saved searches
  221. expect(savedSearchesRequest).toHaveBeenCalledTimes(1);
  222. // Update stores with saved searches
  223. await tick();
  224. await tick();
  225. wrapper.update();
  226. wrapper.find('SmartSearchBar textarea').simulate('click');
  227. // auxillary requests being made
  228. expect(recentSearchesRequest).toHaveBeenCalledTimes(1);
  229. expect(fetchTagsRequest).toHaveBeenCalledTimes(1);
  230. expect(fetchMembersRequest).toHaveBeenCalledTimes(1);
  231. // primary /issues/ request
  232. expect(issuesRequest).toHaveBeenCalledWith(
  233. expect.anything(),
  234. expect.objectContaining({
  235. // Should be called with default query
  236. data: expect.stringContaining('is%3Aunresolved'),
  237. })
  238. );
  239. expect(getSearchBarValue(wrapper)).toBe('is:unresolved');
  240. // Saved search not active since is:unresolved is a tab
  241. expect(getSavedSearchTitle(wrapper)).toBe('Saved Searches');
  242. // This is mocked
  243. expect(StreamGroup).toHaveBeenCalled();
  244. });
  245. it('loads with query in URL and pinned queries', async function () {
  246. savedSearchesRequest = MockApiClient.addMockResponse({
  247. url: '/organizations/org-slug/searches/',
  248. body: [
  249. savedSearch,
  250. TestStubs.Search({
  251. id: '123',
  252. name: 'My Pinned Search',
  253. isPinned: true,
  254. query: 'is:resolved',
  255. }),
  256. ],
  257. });
  258. createWrapper({
  259. location: {
  260. query: {
  261. query: 'level:foo',
  262. },
  263. },
  264. });
  265. // Update stores with saved searches
  266. await tick();
  267. await tick();
  268. wrapper.update();
  269. // Main /issues/ request
  270. expect(issuesRequest).toHaveBeenCalledWith(
  271. expect.anything(),
  272. expect.objectContaining({
  273. // Should be called with default query
  274. data: expect.stringContaining('level%3Afoo'),
  275. })
  276. );
  277. expect(getSearchBarValue(wrapper)).toBe('level:foo');
  278. // Custom search
  279. expect(getSavedSearchTitle(wrapper)).toBe('Custom Search');
  280. });
  281. it('loads with a pinned saved query', async function () {
  282. savedSearchesRequest = MockApiClient.addMockResponse({
  283. url: '/organizations/org-slug/searches/',
  284. body: [
  285. savedSearch,
  286. TestStubs.Search({
  287. id: '123',
  288. name: 'Org Custom',
  289. isPinned: true,
  290. isGlobal: false,
  291. isOrgCustom: true,
  292. query: 'is:resolved',
  293. }),
  294. ],
  295. });
  296. createWrapper();
  297. await tick();
  298. await tick();
  299. wrapper.update();
  300. expect(issuesRequest).toHaveBeenCalledWith(
  301. expect.anything(),
  302. expect.objectContaining({
  303. // Should be called with default query
  304. data: expect.stringContaining('is%3Aresolved'),
  305. })
  306. );
  307. expect(getSearchBarValue(wrapper)).toBe('is:resolved');
  308. // Organization saved search selector should have default saved search selected
  309. expect(getSavedSearchTitle(wrapper)).toBe('Org Custom');
  310. });
  311. it('loads with a pinned custom query', async function () {
  312. savedSearchesRequest = MockApiClient.addMockResponse({
  313. url: '/organizations/org-slug/searches/',
  314. body: [
  315. savedSearch,
  316. TestStubs.Search({
  317. id: '123',
  318. name: 'My Pinned Search',
  319. isPinned: true,
  320. isGlobal: false,
  321. isOrgCustom: false,
  322. query: 'is:resolved',
  323. }),
  324. ],
  325. });
  326. createWrapper();
  327. await tick();
  328. await tick();
  329. wrapper.update();
  330. expect(issuesRequest).toHaveBeenCalledWith(
  331. expect.anything(),
  332. expect.objectContaining({
  333. // Should be called with default query
  334. data: expect.stringContaining('is%3Aresolved'),
  335. })
  336. );
  337. expect(getSearchBarValue(wrapper)).toBe('is:resolved');
  338. // Organization saved search selector should have default saved search selected
  339. expect(getSavedSearchTitle(wrapper)).toBe('My Pinned Search');
  340. });
  341. it('loads with a saved query', async function () {
  342. savedSearchesRequest = MockApiClient.addMockResponse({
  343. url: '/organizations/org-slug/searches/',
  344. body: [
  345. TestStubs.Search({
  346. id: '123',
  347. name: 'Assigned to Me',
  348. isPinned: false,
  349. isGlobal: true,
  350. query: 'assigned:me',
  351. sort: 'priority',
  352. projectId: null,
  353. type: 0,
  354. }),
  355. ],
  356. });
  357. createWrapper({params: {searchId: '123'}});
  358. await tick();
  359. await tick();
  360. wrapper.update();
  361. expect(issuesRequest).toHaveBeenCalledWith(
  362. expect.anything(),
  363. expect.objectContaining({
  364. // Should be called with default query
  365. data:
  366. expect.stringContaining('assigned%3Ame') &&
  367. expect.stringContaining('sort=priority'),
  368. })
  369. );
  370. expect(getSearchBarValue(wrapper)).toBe('assigned:me');
  371. // Organization saved search selector should have default saved search selected
  372. expect(getSavedSearchTitle(wrapper)).toBe('Assigned to Me');
  373. });
  374. it('loads with a query in URL', async function () {
  375. savedSearchesRequest = MockApiClient.addMockResponse({
  376. url: '/organizations/org-slug/searches/',
  377. body: [
  378. TestStubs.Search({
  379. id: '123',
  380. name: 'Assigned to Me',
  381. isPinned: false,
  382. isGlobal: true,
  383. query: 'assigned:me',
  384. projectId: null,
  385. type: 0,
  386. }),
  387. ],
  388. });
  389. createWrapper({location: {query: {query: 'level:error'}}});
  390. await tick();
  391. await tick();
  392. wrapper.update();
  393. expect(issuesRequest).toHaveBeenCalledWith(
  394. expect.anything(),
  395. expect.objectContaining({
  396. // Should be called with default query
  397. data: expect.stringContaining('level%3Aerror'),
  398. })
  399. );
  400. expect(getSearchBarValue(wrapper)).toBe('level:error');
  401. // Organization saved search selector should have default saved search selected
  402. expect(getSavedSearchTitle(wrapper)).toBe('Custom Search');
  403. });
  404. it('loads with an empty query in URL', async function () {
  405. savedSearchesRequest = MockApiClient.addMockResponse({
  406. url: '/organizations/org-slug/searches/',
  407. body: [
  408. TestStubs.Search({
  409. id: '123',
  410. name: 'My Pinned Search',
  411. isPinned: true,
  412. isGlobal: false,
  413. isOrgCustom: false,
  414. query: 'is:resolved',
  415. }),
  416. ],
  417. });
  418. createWrapper({location: {query: {query: undefined}}});
  419. await tick();
  420. await tick();
  421. wrapper.update();
  422. expect(issuesRequest).toHaveBeenCalledWith(
  423. expect.anything(),
  424. expect.objectContaining({
  425. // Should be called with empty query
  426. data: expect.stringContaining(''),
  427. })
  428. );
  429. expect(getSearchBarValue(wrapper)).toBe('is:resolved');
  430. // Organization saved search selector should have default saved search selected
  431. expect(getSavedSearchTitle(wrapper)).toBe('My Pinned Search');
  432. });
  433. it('selects a saved search', async function () {
  434. const localSavedSearch = {...savedSearch, projectId: null};
  435. savedSearchesRequest = MockApiClient.addMockResponse({
  436. url: '/organizations/org-slug/searches/',
  437. body: [localSavedSearch],
  438. });
  439. createWrapper();
  440. await tick();
  441. await tick();
  442. wrapper.update();
  443. await act(async () => {
  444. triggerPress(wrapper.find('SavedSearchTab StyledDropdownTrigger'));
  445. await tick();
  446. wrapper.update();
  447. });
  448. wrapper.find('Option').last().simulate('click');
  449. expect(browserHistory.push).toHaveBeenLastCalledWith(
  450. expect.objectContaining({
  451. pathname: '/organizations/org-slug/issues/searches/789/',
  452. })
  453. );
  454. });
  455. it('clears a saved search when a custom one is entered', async function () {
  456. savedSearchesRequest = MockApiClient.addMockResponse({
  457. url: '/organizations/org-slug/searches/',
  458. body: [
  459. savedSearch,
  460. TestStubs.Search({
  461. id: '123',
  462. name: 'Pinned search',
  463. isPinned: true,
  464. isGlobal: false,
  465. isOrgCustom: true,
  466. query: 'is:resolved',
  467. }),
  468. ],
  469. });
  470. createWrapper();
  471. await tick();
  472. await tick();
  473. wrapper.update();
  474. // Update the search textarea
  475. wrapper
  476. .find('IssueListFilters SmartSearchBar textarea')
  477. .simulate('change', {target: {value: 'dogs'}});
  478. // Submit the form
  479. wrapper.find('IssueListFilters SmartSearchBar form').simulate('submit');
  480. wrapper.update();
  481. expect(browserHistory.push).toHaveBeenLastCalledWith(
  482. expect.objectContaining({
  483. pathname: '/organizations/org-slug/issues/',
  484. query: {
  485. environment: [],
  486. project: [],
  487. query: 'dogs',
  488. statsPeriod: '14d',
  489. },
  490. })
  491. );
  492. });
  493. it('pins and unpins a custom query', async function () {
  494. savedSearchesRequest = MockApiClient.addMockResponse({
  495. url: '/organizations/org-slug/searches/',
  496. body: [savedSearch],
  497. });
  498. createWrapper();
  499. await tick();
  500. await tick();
  501. wrapper.update();
  502. const createPin = MockApiClient.addMockResponse({
  503. url: '/organizations/org-slug/pinned-searches/',
  504. method: 'PUT',
  505. body: {
  506. ...savedSearch,
  507. id: '666',
  508. name: 'My Pinned Search',
  509. query: 'assigned:me level:fatal',
  510. sort: 'date',
  511. isPinned: true,
  512. },
  513. });
  514. const deletePin = MockApiClient.addMockResponse({
  515. url: '/organizations/org-slug/pinned-searches/',
  516. method: 'DELETE',
  517. });
  518. wrapper
  519. .find('SmartSearchBar textarea')
  520. .simulate('change', {target: {value: 'assigned:me level:fatal'}});
  521. wrapper.find('SmartSearchBar form').simulate('submit');
  522. expect(browserHistory.push.mock.calls[0][0]).toEqual(
  523. expect.objectContaining({
  524. query: expect.objectContaining({
  525. query: 'assigned:me level:fatal',
  526. }),
  527. })
  528. );
  529. await tick();
  530. wrapper.setProps({
  531. location: {
  532. ...router.location,
  533. query: {
  534. query: 'assigned:me level:fatal',
  535. },
  536. },
  537. });
  538. expect(getSavedSearchTitle(wrapper)).toBe('Custom Search');
  539. wrapper.find('Button[aria-label="Pin this search"] button').simulate('click');
  540. expect(createPin).toHaveBeenCalled();
  541. await tick();
  542. wrapper.update();
  543. expect(browserHistory.push).toHaveBeenLastCalledWith(
  544. expect.objectContaining({
  545. pathname: '/organizations/org-slug/issues/searches/666/',
  546. query: {},
  547. search: '',
  548. })
  549. );
  550. wrapper.setProps({
  551. params: {
  552. ...router.params,
  553. searchId: '666',
  554. },
  555. });
  556. await tick();
  557. wrapper.update();
  558. expect(getSavedSearchTitle(wrapper)).toBe('My Pinned Search');
  559. wrapper.find('Button[aria-label="Unpin this search"] button').simulate('click');
  560. expect(deletePin).toHaveBeenCalled();
  561. await tick();
  562. wrapper.update();
  563. expect(browserHistory.push).toHaveBeenLastCalledWith(
  564. expect.objectContaining({
  565. pathname: '/organizations/org-slug/issues/',
  566. query: {
  567. query: 'assigned:me level:fatal',
  568. sort: 'date',
  569. },
  570. })
  571. );
  572. });
  573. it('pins and unpins a saved query', async function () {
  574. const assignedToMe = TestStubs.Search({
  575. id: '234',
  576. name: 'Assigned to Me',
  577. isPinned: false,
  578. isGlobal: true,
  579. query: 'assigned:me',
  580. sort: 'date',
  581. projectId: null,
  582. type: 0,
  583. });
  584. savedSearchesRequest = MockApiClient.addMockResponse({
  585. url: '/organizations/org-slug/searches/',
  586. body: [savedSearch, assignedToMe],
  587. });
  588. createWrapper();
  589. await tick();
  590. await tick();
  591. wrapper.update();
  592. let createPin = MockApiClient.addMockResponse({
  593. url: '/organizations/org-slug/pinned-searches/',
  594. method: 'PUT',
  595. body: {
  596. ...savedSearch,
  597. isPinned: true,
  598. },
  599. });
  600. await act(async () => {
  601. triggerPress(wrapper.find('SavedSearchTab StyledDropdownTrigger'));
  602. await tick();
  603. wrapper.update();
  604. });
  605. wrapper.find('Option').first().simulate('click');
  606. await tick();
  607. expect(browserHistory.push).toHaveBeenLastCalledWith(
  608. expect.objectContaining({
  609. pathname: '/organizations/org-slug/issues/searches/789/',
  610. query: {
  611. environment: [],
  612. project: ['3559'],
  613. statsPeriod: '14d',
  614. sort: 'date',
  615. },
  616. })
  617. );
  618. wrapper.setProps({
  619. params: {
  620. ...router.params,
  621. searchId: '789',
  622. },
  623. });
  624. expect(getSavedSearchTitle(wrapper)).toBe('Unresolved TypeErrors');
  625. wrapper.find('Button[aria-label="Pin this search"] button').simulate('click');
  626. expect(createPin).toHaveBeenCalled();
  627. await tick();
  628. wrapper.update();
  629. expect(browserHistory.push).toHaveBeenLastCalledWith(
  630. expect.objectContaining({
  631. pathname: '/organizations/org-slug/issues/searches/789/',
  632. })
  633. );
  634. wrapper.setProps({
  635. params: {
  636. ...router.params,
  637. searchId: '789',
  638. },
  639. });
  640. await tick();
  641. wrapper.update();
  642. expect(getSavedSearchTitle(wrapper)).toBe('Unresolved TypeErrors');
  643. // Select other saved search
  644. await act(async () => {
  645. triggerPress(wrapper.find('SavedSearchTab StyledDropdownTrigger'));
  646. await tick();
  647. wrapper.update();
  648. });
  649. wrapper.find('Option').last().simulate('click');
  650. expect(browserHistory.push).toHaveBeenLastCalledWith(
  651. expect.objectContaining({
  652. pathname: '/organizations/org-slug/issues/searches/234/',
  653. query: {
  654. project: [],
  655. environment: [],
  656. statsPeriod: '14d',
  657. sort: 'date',
  658. },
  659. })
  660. );
  661. wrapper.setProps({
  662. params: {
  663. ...router.params,
  664. searchId: '234',
  665. },
  666. });
  667. expect(getSavedSearchTitle(wrapper)).toBe('Assigned to Me');
  668. createPin = MockApiClient.addMockResponse({
  669. url: '/organizations/org-slug/pinned-searches/',
  670. method: 'PUT',
  671. body: {
  672. ...assignedToMe,
  673. isPinned: true,
  674. },
  675. });
  676. wrapper.find('Button[aria-label="Pin this search"] button').simulate('click');
  677. expect(createPin).toHaveBeenCalled();
  678. await tick();
  679. wrapper.update();
  680. expect(browserHistory.push).toHaveBeenLastCalledWith(
  681. expect.objectContaining({
  682. pathname: '/organizations/org-slug/issues/searches/234/',
  683. })
  684. );
  685. wrapper.setProps({
  686. params: {
  687. ...router.params,
  688. searchId: '234',
  689. },
  690. });
  691. await tick();
  692. wrapper.update();
  693. expect(getSavedSearchTitle(wrapper)).toBe('Assigned to Me');
  694. });
  695. it('pinning and unpinning searches should keep project selected', async function () {
  696. savedSearchesRequest = MockApiClient.addMockResponse({
  697. url: '/organizations/org-slug/searches/',
  698. body: [savedSearch],
  699. });
  700. createWrapper({
  701. selection: {
  702. projects: [123],
  703. environments: ['prod'],
  704. datetime: {},
  705. },
  706. location: {query: {project: ['123'], environment: ['prod']}},
  707. });
  708. await tick();
  709. await tick();
  710. wrapper.update();
  711. const deletePin = MockApiClient.addMockResponse({
  712. url: '/organizations/org-slug/pinned-searches/',
  713. method: 'DELETE',
  714. });
  715. const createPin = MockApiClient.addMockResponse({
  716. url: '/organizations/org-slug/pinned-searches/',
  717. method: 'PUT',
  718. body: {
  719. ...savedSearch,
  720. id: '666',
  721. name: 'My Pinned Search',
  722. query: 'assigned:me level:fatal',
  723. sort: 'date',
  724. isPinned: true,
  725. },
  726. });
  727. wrapper
  728. .find('SmartSearchBar textarea')
  729. .simulate('change', {target: {value: 'assigned:me level:fatal'}});
  730. wrapper.find('SmartSearchBar form').simulate('submit');
  731. await tick();
  732. expect(browserHistory.push).toHaveBeenLastCalledWith(
  733. expect.objectContaining({
  734. query: expect.objectContaining({
  735. project: [123],
  736. environment: ['prod'],
  737. query: 'assigned:me level:fatal',
  738. }),
  739. })
  740. );
  741. const newRouter = {
  742. ...router,
  743. location: {
  744. ...router.location,
  745. query: {
  746. ...router.location.query,
  747. project: [123],
  748. environment: ['prod'],
  749. query: 'assigned:me level:fatal',
  750. },
  751. },
  752. };
  753. wrapper.setProps({...newRouter, router: newRouter});
  754. wrapper.setContext({router: newRouter});
  755. wrapper.update();
  756. wrapper.find('Button[aria-label="Pin this search"] button').simulate('click');
  757. expect(createPin).toHaveBeenCalled();
  758. await tick();
  759. wrapper.update();
  760. expect(browserHistory.push).toHaveBeenLastCalledWith(
  761. expect.objectContaining({
  762. pathname: '/organizations/org-slug/issues/searches/666/',
  763. query: expect.objectContaining({
  764. project: [123],
  765. environment: ['prod'],
  766. query: 'assigned:me level:fatal',
  767. }),
  768. })
  769. );
  770. wrapper.setProps({
  771. params: {
  772. ...router.params,
  773. searchId: '666',
  774. },
  775. });
  776. await tick();
  777. wrapper.update();
  778. wrapper.find('Button[aria-label="Unpin this search"] button').simulate('click');
  779. expect(deletePin).toHaveBeenCalled();
  780. await tick();
  781. wrapper.update();
  782. expect(browserHistory.push).toHaveBeenLastCalledWith(
  783. expect.objectContaining({
  784. pathname: '/organizations/org-slug/issues/',
  785. query: expect.objectContaining({
  786. project: [123],
  787. environment: ['prod'],
  788. query: 'assigned:me level:fatal',
  789. }),
  790. })
  791. );
  792. });
  793. it.todo('saves a new query');
  794. it.todo('loads pinned search when invalid saved search id is accessed');
  795. it('does not allow pagination to "previous" while on first page and resets cursors when navigating back to initial page', async function () {
  796. let pushArgs;
  797. createWrapper();
  798. await tick();
  799. await tick();
  800. wrapper.update();
  801. expect(wrapper.find('Pagination Button').first().prop('disabled')).toBe(true);
  802. issuesRequest = MockApiClient.addMockResponse({
  803. url: '/organizations/org-slug/issues/',
  804. body: [group],
  805. headers: {
  806. Link: '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575000:0:0>; rel="previous"; results="true"; cursor="1443575000:0:1", <http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443574000:0:0>; rel="next"; results="true"; cursor="1443574000:0:0"',
  807. },
  808. });
  809. // Click next
  810. wrapper.find('Pagination Button').last().simulate('click');
  811. await tick();
  812. pushArgs = {
  813. pathname: '/organizations/org-slug/issues/',
  814. query: {
  815. cursor: '1443575000:0:0',
  816. page: 1,
  817. environment: [],
  818. project: [],
  819. query: 'is:unresolved',
  820. statsPeriod: '14d',
  821. },
  822. };
  823. expect(browserHistory.push).toHaveBeenLastCalledWith(pushArgs);
  824. wrapper.setProps({location: pushArgs});
  825. expect(wrapper.find('Pagination Button').first().prop('disabled')).toBe(false);
  826. // Click next again
  827. wrapper.find('Pagination Button').last().simulate('click');
  828. await tick();
  829. pushArgs = {
  830. pathname: '/organizations/org-slug/issues/',
  831. query: {
  832. cursor: '1443574000:0:0',
  833. page: 2,
  834. environment: [],
  835. project: [],
  836. query: 'is:unresolved',
  837. statsPeriod: '14d',
  838. },
  839. };
  840. expect(browserHistory.push).toHaveBeenLastCalledWith(pushArgs);
  841. wrapper.setProps({location: pushArgs});
  842. // Click previous
  843. wrapper.find('Pagination Button').first().simulate('click');
  844. await tick();
  845. pushArgs = {
  846. pathname: '/organizations/org-slug/issues/',
  847. query: {
  848. cursor: '1443575000:0:1',
  849. page: 1,
  850. environment: [],
  851. project: [],
  852. query: 'is:unresolved',
  853. statsPeriod: '14d',
  854. },
  855. };
  856. expect(browserHistory.push).toHaveBeenLastCalledWith(pushArgs);
  857. wrapper.setProps({location: pushArgs});
  858. // Click previous back to initial page
  859. wrapper.find('Pagination Button').first().simulate('click');
  860. await tick();
  861. // cursor is undefined because "prev" cursor is === initial "next" cursor
  862. expect(browserHistory.push).toHaveBeenLastCalledWith({
  863. pathname: '/organizations/org-slug/issues/',
  864. query: {
  865. cursor: undefined,
  866. environment: [],
  867. page: undefined,
  868. project: [],
  869. query: 'is:unresolved',
  870. statsPeriod: '14d',
  871. },
  872. });
  873. });
  874. });
  875. describe('transitionTo', function () {
  876. let instance;
  877. beforeEach(function () {
  878. wrapper = shallow(<IssueListOverview {...props} />);
  879. instance = wrapper.instance();
  880. });
  881. it('transitions to query updates', function () {
  882. instance.transitionTo({query: 'is:ignored'});
  883. expect(browserHistory.push).toHaveBeenCalledWith({
  884. pathname: '/organizations/org-slug/issues/',
  885. query: {
  886. environment: [],
  887. project: [parseInt(project.id, 10)],
  888. query: 'is:ignored',
  889. statsPeriod: '14d',
  890. },
  891. });
  892. });
  893. it('transitions to cursor with project-less saved search', function () {
  894. savedSearch = {
  895. id: 123,
  896. projectId: null,
  897. query: 'foo:bar',
  898. };
  899. instance.transitionTo({cursor: '1554756114000:0:0'}, savedSearch);
  900. // should keep the current project selection as we're going to the next page.
  901. expect(browserHistory.push).toHaveBeenCalledWith({
  902. pathname: '/organizations/org-slug/issues/searches/123/',
  903. query: {
  904. environment: [],
  905. project: [parseInt(project.id, 10)],
  906. cursor: '1554756114000:0:0',
  907. statsPeriod: '14d',
  908. },
  909. });
  910. });
  911. it('transitions to cursor with project saved search', function () {
  912. savedSearch = {
  913. id: 123,
  914. projectId: 999,
  915. query: 'foo:bar',
  916. };
  917. instance.transitionTo({cursor: '1554756114000:0:0'}, savedSearch);
  918. // should keep the current project selection as we're going to the next page.
  919. expect(browserHistory.push).toHaveBeenCalledWith({
  920. pathname: '/organizations/org-slug/issues/searches/123/',
  921. query: {
  922. environment: [],
  923. project: [parseInt(project.id, 10)],
  924. cursor: '1554756114000:0:0',
  925. statsPeriod: '14d',
  926. },
  927. });
  928. });
  929. it('transitions to saved search that has a projectId', function () {
  930. savedSearch = {
  931. id: 123,
  932. projectId: 99,
  933. query: 'foo:bar',
  934. };
  935. instance.transitionTo(undefined, savedSearch);
  936. expect(browserHistory.push).toHaveBeenCalledWith({
  937. pathname: '/organizations/org-slug/issues/searches/123/',
  938. query: {
  939. environment: [],
  940. project: [savedSearch.projectId],
  941. statsPeriod: '14d',
  942. },
  943. });
  944. });
  945. it('transitions to saved search with a sort', function () {
  946. savedSearch = {
  947. id: 123,
  948. project: null,
  949. query: 'foo:bar',
  950. sort: 'freq',
  951. };
  952. instance.transitionTo(undefined, savedSearch);
  953. expect(browserHistory.push).toHaveBeenCalledWith({
  954. pathname: '/organizations/org-slug/issues/searches/123/',
  955. query: {
  956. environment: [],
  957. project: [parseInt(project.id, 10)],
  958. statsPeriod: '14d',
  959. sort: savedSearch.sort,
  960. },
  961. });
  962. });
  963. it('goes to all projects when using a basic saved search and global-views feature', function () {
  964. organization.features = ['global-views'];
  965. savedSearch = {
  966. id: 1,
  967. project: null,
  968. query: 'is:unresolved',
  969. };
  970. instance.transitionTo(undefined, savedSearch);
  971. expect(browserHistory.push).toHaveBeenCalledWith({
  972. pathname: '/organizations/org-slug/issues/searches/1/',
  973. query: {
  974. project: [parseInt(project.id, 10)],
  975. environment: [],
  976. statsPeriod: '14d',
  977. },
  978. });
  979. });
  980. it('retains project selection when using a basic saved search and no global-views feature', function () {
  981. organization.features = [];
  982. savedSearch = {
  983. id: 1,
  984. projectId: null,
  985. query: 'is:unresolved',
  986. };
  987. instance.transitionTo(undefined, savedSearch);
  988. expect(browserHistory.push).toHaveBeenCalledWith({
  989. pathname: '/organizations/org-slug/issues/searches/1/',
  990. query: {
  991. environment: [],
  992. project: props.selection.projects,
  993. statsPeriod: '14d',
  994. },
  995. });
  996. });
  997. });
  998. describe('getEndpointParams', function () {
  999. beforeEach(function () {
  1000. wrapper = shallow(<IssueListOverview {...props} />);
  1001. });
  1002. it('omits defaults', function () {
  1003. wrapper.setProps({
  1004. location: {
  1005. query: {
  1006. sort: 'date',
  1007. groupStatsPeriod: '24h',
  1008. },
  1009. },
  1010. });
  1011. const value = wrapper.instance().getEndpointParams();
  1012. expect(value.groupStatsPeriod).toBeUndefined();
  1013. expect(value.sort).toBeUndefined();
  1014. });
  1015. it('uses saved search data', function () {
  1016. const value = wrapper.instance().getEndpointParams();
  1017. expect(value.query).toEqual('is:unresolved');
  1018. expect(value.project).toEqual([parseInt(savedSearch.projectId, 10)]);
  1019. });
  1020. });
  1021. describe('componentDidMount', function () {
  1022. beforeEach(function () {
  1023. wrapper = shallow(<IssueListOverview {...props} />);
  1024. });
  1025. it('fetches tags and sets state', async function () {
  1026. const instance = wrapper.instance();
  1027. await instance.componentDidMount();
  1028. expect(fetchTagsRequest).toHaveBeenCalled();
  1029. expect(instance.state.tagsLoading).toBeFalsy();
  1030. });
  1031. it('fetches members and sets state', async function () {
  1032. const instance = wrapper.instance();
  1033. await instance.componentDidMount();
  1034. wrapper.update();
  1035. expect(fetchMembersRequest).toHaveBeenCalled();
  1036. const members = instance.state.memberList;
  1037. // Spot check the resulting structure as we munge it a bit.
  1038. expect(members).toBeTruthy();
  1039. expect(members[project.slug]).toBeTruthy();
  1040. expect(members[project.slug][0].email).toBeTruthy();
  1041. });
  1042. it('fetches groups when there is no searchid', async function () {
  1043. await wrapper.instance().componentDidMount();
  1044. });
  1045. });
  1046. describe('componentDidUpdate fetching groups', function () {
  1047. let fetchDataMock;
  1048. beforeEach(function () {
  1049. fetchDataMock = MockApiClient.addMockResponse({
  1050. url: '/organizations/org-slug/issues/',
  1051. body: [group],
  1052. headers: {
  1053. Link: DEFAULT_LINKS_HEADER,
  1054. },
  1055. });
  1056. fetchDataMock.mockReset();
  1057. wrapper = shallow(<IssueListOverview {...props} />);
  1058. });
  1059. it('fetches data on selection change', function () {
  1060. const selection = {projects: [99], environments: [], datetime: {period: '24h'}};
  1061. wrapper.setProps({selection, foo: 'bar'});
  1062. expect(fetchDataMock).toHaveBeenCalled();
  1063. });
  1064. it('fetches data on savedSearch change', function () {
  1065. savedSearch = {id: '1', query: 'is:resolved'};
  1066. wrapper.setProps({savedSearch});
  1067. wrapper.update();
  1068. expect(fetchDataMock).toHaveBeenCalled();
  1069. });
  1070. it('fetches data on location change', async function () {
  1071. const queryAttrs = ['query', 'sort', 'statsPeriod', 'cursor', 'groupStatsPeriod'];
  1072. const location = cloneDeep(props.location);
  1073. for (const [i, attr] of queryAttrs.entries()) {
  1074. // reclone each iteration so that only one property changes.
  1075. const newLocation = cloneDeep(location);
  1076. newLocation.query[attr] = 'newValue';
  1077. wrapper.setProps({location: newLocation});
  1078. await tick();
  1079. wrapper.update();
  1080. // Each property change after the first will actually cause two new
  1081. // fetchData calls, one from the property change and another from a
  1082. // change in this.state.issuesLoading going from false to true.
  1083. expect(fetchDataMock).toHaveBeenCalledTimes(2 * i + 1);
  1084. }
  1085. });
  1086. it('uses correct statsPeriod when fetching issues list and no datetime given', function () {
  1087. const selection = {projects: [99], environments: [], datetime: {}};
  1088. wrapper.setProps({selection, foo: 'bar'});
  1089. expect(fetchDataMock).toHaveBeenLastCalledWith(
  1090. '/organizations/org-slug/issues/',
  1091. expect.objectContaining({
  1092. data: 'collapse=stats&expand=owners&expand=inbox&limit=25&project=99&query=is%3Aunresolved&shortIdLookup=1&statsPeriod=14d',
  1093. })
  1094. );
  1095. });
  1096. });
  1097. describe('componentDidUpdate fetching members', function () {
  1098. beforeEach(function () {
  1099. wrapper = shallow(<IssueListOverview {...props} />);
  1100. wrapper.instance().fetchData = jest.fn();
  1101. });
  1102. it('fetches memberlist on project change', function () {
  1103. // Called during componentDidMount
  1104. expect(fetchMembersRequest).toHaveBeenCalledTimes(1);
  1105. const selection = {
  1106. projects: [99],
  1107. environments: [],
  1108. datetime: {period: '24h'},
  1109. };
  1110. wrapper.setProps({selection});
  1111. wrapper.update();
  1112. expect(fetchMembersRequest).toHaveBeenCalledTimes(2);
  1113. });
  1114. });
  1115. describe('componentDidUpdate fetching tags', function () {
  1116. beforeEach(function () {
  1117. wrapper = shallow(<IssueListOverview {...props} />);
  1118. wrapper.instance().fetchData = jest.fn();
  1119. });
  1120. it('fetches tags on project change', function () {
  1121. // Called during componentDidMount
  1122. expect(fetchTagsRequest).toHaveBeenCalledTimes(1);
  1123. const selection = {
  1124. projects: [99],
  1125. environments: [],
  1126. datetime: {period: '24h'},
  1127. };
  1128. wrapper.setProps({selection});
  1129. wrapper.update();
  1130. expect(fetchTagsRequest).toHaveBeenCalledTimes(2);
  1131. });
  1132. });
  1133. describe('processingIssues', function () {
  1134. beforeEach(function () {
  1135. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />);
  1136. });
  1137. it('fetches and displays processing issues', function () {
  1138. const instance = wrapper.instance();
  1139. instance.componentDidMount();
  1140. wrapper.update();
  1141. GroupStore.add([group]);
  1142. wrapper.setState({
  1143. groupIds: ['1'],
  1144. loading: false,
  1145. });
  1146. const issues = wrapper.find('ProcessingIssueList');
  1147. expect(issues).toHaveLength(1);
  1148. });
  1149. });
  1150. describe('render states', function () {
  1151. it('displays the loading icon', function () {
  1152. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />);
  1153. wrapper.setState({savedSearchLoading: true});
  1154. expect(wrapper.find('LoadingIndicator')).toHaveLength(1);
  1155. });
  1156. it('displays an error', function () {
  1157. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />);
  1158. wrapper.setState({
  1159. error: 'Things broke',
  1160. savedSearchLoading: false,
  1161. issuesLoading: false,
  1162. });
  1163. const error = wrapper.find('LoadingError');
  1164. expect(error).toHaveLength(1);
  1165. expect(error.props().message).toEqual('Things broke');
  1166. });
  1167. it('displays congrats robots animation with only is:unresolved query', async function () {
  1168. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />);
  1169. wrapper.setState({
  1170. savedSearchLoading: false,
  1171. issuesLoading: false,
  1172. error: false,
  1173. groupIds: [],
  1174. });
  1175. await tick();
  1176. wrapper.update();
  1177. expect(wrapper.find('NoUnresolvedIssues').exists()).toBe(true);
  1178. });
  1179. it('displays an empty resultset with is:unresolved and level:error query', async function () {
  1180. const errorsOnlyQuery = {
  1181. ...props,
  1182. location: {
  1183. query: {query: 'is:unresolved level:error'},
  1184. },
  1185. };
  1186. wrapper = mountWithThemeAndOrg(<IssueListOverview {...errorsOnlyQuery} />);
  1187. wrapper.setState({
  1188. savedSearchLoading: false,
  1189. issuesLoading: false,
  1190. error: false,
  1191. groupIds: [],
  1192. fetchingSentFirstEvent: false,
  1193. sentFirstEvent: true,
  1194. });
  1195. await tick();
  1196. wrapper.update();
  1197. expect(wrapper.find('EmptyStateWarning').exists()).toBe(true);
  1198. });
  1199. it('displays an empty resultset with has:browser query', async function () {
  1200. const hasBrowserQuery = {
  1201. ...props,
  1202. location: {
  1203. query: {query: 'has:browser'},
  1204. },
  1205. };
  1206. wrapper = mountWithThemeAndOrg(<IssueListOverview {...hasBrowserQuery} />);
  1207. wrapper.setState({
  1208. savedSearchLoading: false,
  1209. issuesLoading: false,
  1210. error: false,
  1211. groupIds: [],
  1212. fetchingSentFirstEvent: false,
  1213. sentFirstEvent: true,
  1214. });
  1215. await tick();
  1216. wrapper.update();
  1217. expect(wrapper.find('EmptyStateWarning').exists()).toBe(true);
  1218. });
  1219. });
  1220. describe('Error Robot', function () {
  1221. const createWrapper = moreProps => {
  1222. const defaultProps = {
  1223. ...props,
  1224. savedSearchLoading: false,
  1225. useOrgSavedSearches: true,
  1226. selection: {
  1227. projects: [],
  1228. environments: [],
  1229. datetime: {period: '14d'},
  1230. },
  1231. location: {query: {query: 'is:unresolved'}, search: 'query=is:unresolved'},
  1232. params: {orgId: organization.slug},
  1233. organization: TestStubs.Organization({
  1234. projects: [],
  1235. }),
  1236. ...moreProps,
  1237. };
  1238. const localWrapper = mountWithThemeAndOrg(<IssueListOverview {...defaultProps} />);
  1239. localWrapper.setState({
  1240. error: false,
  1241. issuesLoading: false,
  1242. groupIds: [],
  1243. });
  1244. return localWrapper;
  1245. };
  1246. it('displays when no projects selected and all projects user is member of, does not have first event', async function () {
  1247. const projects = [
  1248. TestStubs.Project({
  1249. id: '1',
  1250. slug: 'foo',
  1251. isMember: true,
  1252. firstEvent: false,
  1253. }),
  1254. TestStubs.Project({
  1255. id: '2',
  1256. slug: 'bar',
  1257. isMember: true,
  1258. firstEvent: false,
  1259. }),
  1260. TestStubs.Project({
  1261. id: '3',
  1262. slug: 'baz',
  1263. isMember: true,
  1264. firstEvent: false,
  1265. }),
  1266. ];
  1267. MockApiClient.addMockResponse({
  1268. url: '/organizations/org-slug/sent-first-event/',
  1269. query: {
  1270. is_member: true,
  1271. },
  1272. body: {sentFirstEvent: false},
  1273. });
  1274. MockApiClient.addMockResponse({
  1275. url: '/organizations/org-slug/projects/',
  1276. body: projects,
  1277. });
  1278. MockApiClient.addMockResponse({
  1279. url: '/projects/org-slug/foo/issues/',
  1280. body: [],
  1281. });
  1282. wrapper = createWrapper({
  1283. organization: TestStubs.Organization({
  1284. projects,
  1285. }),
  1286. });
  1287. await tick();
  1288. wrapper.update();
  1289. expect(wrapper.find('ErrorRobot')).toHaveLength(1);
  1290. });
  1291. it('does not display when no projects selected and any projects have a first event', async function () {
  1292. const projects = [
  1293. TestStubs.Project({
  1294. id: '1',
  1295. slug: 'foo',
  1296. isMember: true,
  1297. firstEvent: false,
  1298. }),
  1299. TestStubs.Project({
  1300. id: '2',
  1301. slug: 'bar',
  1302. isMember: true,
  1303. firstEvent: true,
  1304. }),
  1305. TestStubs.Project({
  1306. id: '3',
  1307. slug: 'baz',
  1308. isMember: true,
  1309. firstEvent: false,
  1310. }),
  1311. ];
  1312. MockApiClient.addMockResponse({
  1313. url: '/organizations/org-slug/sent-first-event/',
  1314. query: {
  1315. is_member: true,
  1316. },
  1317. body: {sentFirstEvent: true},
  1318. });
  1319. MockApiClient.addMockResponse({
  1320. url: '/organizations/org-slug/projects/',
  1321. body: projects,
  1322. });
  1323. wrapper = createWrapper({
  1324. organization: TestStubs.Organization({
  1325. projects,
  1326. }),
  1327. });
  1328. await tick();
  1329. wrapper.update();
  1330. expect(wrapper.find('ErrorRobot')).toHaveLength(0);
  1331. });
  1332. it('displays when all selected projects do not have first event', async function () {
  1333. const projects = [
  1334. TestStubs.Project({
  1335. id: '1',
  1336. slug: 'foo',
  1337. isMember: true,
  1338. firstEvent: false,
  1339. }),
  1340. TestStubs.Project({
  1341. id: '2',
  1342. slug: 'bar',
  1343. isMember: true,
  1344. firstEvent: false,
  1345. }),
  1346. TestStubs.Project({
  1347. id: '3',
  1348. slug: 'baz',
  1349. isMember: true,
  1350. firstEvent: false,
  1351. }),
  1352. ];
  1353. MockApiClient.addMockResponse({
  1354. url: '/organizations/org-slug/sent-first-event/',
  1355. query: {
  1356. project: [1, 2],
  1357. },
  1358. body: {sentFirstEvent: false},
  1359. });
  1360. MockApiClient.addMockResponse({
  1361. url: '/organizations/org-slug/projects/',
  1362. body: projects,
  1363. });
  1364. MockApiClient.addMockResponse({
  1365. url: '/projects/org-slug/foo/issues/',
  1366. body: [],
  1367. });
  1368. wrapper = createWrapper({
  1369. selection: {
  1370. projects: [1, 2],
  1371. environments: [],
  1372. datetime: {period: '14d'},
  1373. },
  1374. organization: TestStubs.Organization({
  1375. projects,
  1376. }),
  1377. });
  1378. await tick();
  1379. wrapper.update();
  1380. expect(wrapper.find('ErrorRobot')).toHaveLength(1);
  1381. });
  1382. it('does not display when any selected projects have first event', function () {
  1383. const projects = [
  1384. TestStubs.Project({
  1385. id: '1',
  1386. slug: 'foo',
  1387. isMember: true,
  1388. firstEvent: false,
  1389. }),
  1390. TestStubs.Project({
  1391. id: '2',
  1392. slug: 'bar',
  1393. isMember: true,
  1394. firstEvent: true,
  1395. }),
  1396. TestStubs.Project({
  1397. id: '3',
  1398. slug: 'baz',
  1399. isMember: true,
  1400. firstEvent: true,
  1401. }),
  1402. ];
  1403. MockApiClient.addMockResponse({
  1404. url: '/organizations/org-slug/sent-first-event/',
  1405. query: {
  1406. project: [1, 2],
  1407. },
  1408. body: {sentFirstEvent: true},
  1409. });
  1410. MockApiClient.addMockResponse({
  1411. url: '/organizations/org-slug/projects/',
  1412. body: projects,
  1413. });
  1414. wrapper = createWrapper({
  1415. selection: {
  1416. projects: [1, 2],
  1417. environments: [],
  1418. datetime: {period: '14d'},
  1419. },
  1420. organization: TestStubs.Organization({
  1421. projects,
  1422. }),
  1423. });
  1424. expect(wrapper.find('ErrorRobot')).toHaveLength(0);
  1425. });
  1426. });
  1427. it('displays a count that represents the current page', function () {
  1428. parseLinkHeaderSpy.mockReturnValue({
  1429. next: {
  1430. results: true,
  1431. },
  1432. previous: {
  1433. results: false,
  1434. },
  1435. });
  1436. props = {
  1437. ...props,
  1438. location: {
  1439. query: {
  1440. cursor: 'some cursor',
  1441. page: 0,
  1442. },
  1443. },
  1444. };
  1445. const {routerContext} = initializeOrg();
  1446. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />, routerContext);
  1447. wrapper.setState({
  1448. groupIds: range(0, 25).map(String),
  1449. queryCount: 500,
  1450. queryMaxCount: 1000,
  1451. pageLinks: DEFAULT_LINKS_HEADER,
  1452. });
  1453. const paginationCaption = wrapper.find('PaginationCaption');
  1454. expect(paginationCaption.text()).toBe('Showing 25 of 500 issues');
  1455. parseLinkHeaderSpy.mockReturnValue({
  1456. next: {
  1457. results: true,
  1458. },
  1459. previous: {
  1460. results: true,
  1461. },
  1462. });
  1463. wrapper.setProps({
  1464. location: {
  1465. query: {
  1466. cursor: 'some cursor',
  1467. page: 1,
  1468. },
  1469. },
  1470. });
  1471. expect(paginationCaption.text()).toBe('Showing 50 of 500 issues');
  1472. expect(wrapper.find('IssueListHeader').exists()).toBeTruthy();
  1473. });
  1474. it('displays a count that makes sense based on the current page', function () {
  1475. parseLinkHeaderSpy.mockReturnValue({
  1476. next: {
  1477. // Is at last page according to the cursor
  1478. results: false,
  1479. },
  1480. previous: {
  1481. results: true,
  1482. },
  1483. });
  1484. props = {
  1485. ...props,
  1486. location: {
  1487. query: {
  1488. cursor: 'some cursor',
  1489. page: 3,
  1490. },
  1491. },
  1492. };
  1493. const {routerContext} = initializeOrg();
  1494. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />, routerContext);
  1495. wrapper.setState({
  1496. groupIds: range(0, 25).map(String),
  1497. queryCount: 500,
  1498. queryMaxCount: 1000,
  1499. pageLinks: DEFAULT_LINKS_HEADER,
  1500. });
  1501. const paginationCaption = wrapper.find('PaginationCaption');
  1502. expect(paginationCaption.text()).toBe('Showing 500 of 500 issues');
  1503. parseLinkHeaderSpy.mockReturnValue({
  1504. next: {
  1505. results: true,
  1506. },
  1507. previous: {
  1508. // Is at first page according to cursor
  1509. results: false,
  1510. },
  1511. });
  1512. wrapper.setProps({
  1513. location: {
  1514. query: {
  1515. cursor: 'some cursor',
  1516. page: 2,
  1517. },
  1518. },
  1519. });
  1520. expect(paginationCaption.text()).toBe('Showing 25 of 500 issues');
  1521. expect(wrapper.find('IssueListHeader').exists()).toBeTruthy();
  1522. });
  1523. it('displays a count based on items removed', function () {
  1524. parseLinkHeaderSpy.mockReturnValue({
  1525. next: {
  1526. results: true,
  1527. },
  1528. previous: {
  1529. results: true,
  1530. },
  1531. });
  1532. props = {
  1533. ...props,
  1534. location: {
  1535. query: {
  1536. cursor: 'some cursor',
  1537. page: 1,
  1538. },
  1539. },
  1540. };
  1541. const {routerContext} = initializeOrg();
  1542. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />, routerContext);
  1543. wrapper.setState({
  1544. groupIds: range(0, 25).map(String),
  1545. queryCount: 75,
  1546. itemsRemoved: 1,
  1547. queryMaxCount: 1000,
  1548. pageLinks: DEFAULT_LINKS_HEADER,
  1549. });
  1550. const paginationCaption = wrapper.find('PaginationCaption');
  1551. // 2nd page subtracts the one removed
  1552. expect(paginationCaption.text()).toBe('Showing 49 of 74 issues');
  1553. });
  1554. describe('with relative change feature', function () {
  1555. it('defaults to larger graph selection', function () {
  1556. organization.features = ['issue-list-trend-sort'];
  1557. props.location = {
  1558. query: {query: 'is:unresolved', sort: 'trend'},
  1559. search: 'query=is:unresolved',
  1560. };
  1561. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />);
  1562. expect(wrapper.instance().getGroupStatsPeriod()).toBe('auto');
  1563. });
  1564. });
  1565. describe('project low priority queue alert', function () {
  1566. const {routerContext} = initializeOrg();
  1567. beforeEach(function () {
  1568. act(() => ProjectsStore.reset());
  1569. });
  1570. it('does not render alert', function () {
  1571. act(() => ProjectsStore.loadInitialData([project]));
  1572. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />, routerContext);
  1573. const eventProcessingAlert = wrapper.find('StyledGlobalEventProcessingAlert');
  1574. expect(eventProcessingAlert.exists()).toBe(true);
  1575. expect(eventProcessingAlert.isEmptyRender()).toBe(true);
  1576. });
  1577. describe('renders alert', function () {
  1578. it('for one project', function () {
  1579. act(() =>
  1580. ProjectsStore.loadInitialData([
  1581. {...project, eventProcessing: {symbolicationDegraded: true}},
  1582. ])
  1583. );
  1584. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />, routerContext);
  1585. const eventProcessingAlert = wrapper.find('StyledGlobalEventProcessingAlert');
  1586. expect(eventProcessingAlert.exists()).toBe(true);
  1587. expect(eventProcessingAlert.isEmptyRender()).toBe(false);
  1588. expect(eventProcessingAlert.text()).toBe(
  1589. 'Event Processing for this project is currently degraded. Events may appear with larger delays than usual or get dropped. Please check the Status page for a potential outage.'
  1590. );
  1591. });
  1592. it('for multiple projects', function () {
  1593. const projectBar = TestStubs.ProjectDetails({
  1594. id: '3560',
  1595. name: 'Bar Project',
  1596. slug: 'project-slug-bar',
  1597. });
  1598. act(() =>
  1599. ProjectsStore.loadInitialData([
  1600. {
  1601. ...project,
  1602. slug: 'project-slug',
  1603. eventProcessing: {symbolicationDegraded: true},
  1604. },
  1605. {
  1606. ...projectBar,
  1607. slug: 'project-slug-bar',
  1608. eventProcessing: {symbolicationDegraded: true},
  1609. },
  1610. ])
  1611. );
  1612. wrapper = mountWithThemeAndOrg(
  1613. <IssueListOverview
  1614. {...props}
  1615. selection={{
  1616. ...props.selection,
  1617. projects: [Number(project.id), Number(projectBar.id)],
  1618. }}
  1619. />,
  1620. routerContext
  1621. );
  1622. const eventProcessingAlert = wrapper.find('StyledGlobalEventProcessingAlert');
  1623. expect(eventProcessingAlert.exists()).toBe(true);
  1624. expect(eventProcessingAlert.isEmptyRender()).toBe(false);
  1625. expect(eventProcessingAlert.text()).toBe(
  1626. `Event Processing for the ${project.slug}, ${projectBar.slug} projects is currently degraded. Events may appear with larger delays than usual or get dropped. Please check the Status page for a potential outage.`
  1627. );
  1628. });
  1629. });
  1630. });
  1631. });