overview.spec.jsx 55 KB

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