overviewFc.spec.tsx 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. import merge from 'lodash/merge';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {GroupStatsFixture} from 'sentry-fixture/groupStats';
  4. import {LocationFixture} from 'sentry-fixture/locationFixture';
  5. import {MemberFixture} from 'sentry-fixture/member';
  6. import {OrganizationFixture} from 'sentry-fixture/organization';
  7. import {ProjectFixture} from 'sentry-fixture/project';
  8. import {RouterFixture} from 'sentry-fixture/routerFixture';
  9. import {SearchFixture} from 'sentry-fixture/search';
  10. import {TagsFixture} from 'sentry-fixture/tags';
  11. import {initializeOrg} from 'sentry-test/initializeOrg';
  12. import {
  13. act,
  14. render,
  15. screen,
  16. userEvent,
  17. waitFor,
  18. waitForElementToBeRemoved,
  19. } from 'sentry-test/reactTestingLibrary';
  20. import {textWithMarkupMatcher} from 'sentry-test/utils';
  21. import StreamGroup from 'sentry/components/stream/group';
  22. import {DEFAULT_QUERY} from 'sentry/constants';
  23. import ProjectsStore from 'sentry/stores/projectsStore';
  24. import TagStore from 'sentry/stores/tagStore';
  25. import {SavedSearchVisibility} from 'sentry/types/group';
  26. import localStorageWrapper from 'sentry/utils/localStorage';
  27. import * as parseLinkHeader from 'sentry/utils/parseLinkHeader';
  28. import IssueListWithStores, {
  29. IssueListOverviewFc as IssueListOverview,
  30. } from 'sentry/views/issueList/overviewFc';
  31. // Mock <IssueListActions>
  32. jest.mock('sentry/views/issueList/actions', () => jest.fn(() => null));
  33. jest.mock('sentry/components/stream/group', () => jest.fn(() => null));
  34. const DEFAULT_LINKS_HEADER =
  35. '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575731:0:1>; rel="previous"; results="false"; cursor="1443575731:0:1", ' +
  36. '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575000:0:0>; rel="next"; results="true"; cursor="1443575000:0:0"';
  37. const project = ProjectFixture({
  38. id: '3559',
  39. name: 'Foo Project',
  40. slug: 'project-slug',
  41. firstEvent: new Date().toISOString(),
  42. });
  43. const {organization, projects, router} = initializeOrg({
  44. organization: {
  45. id: '1337',
  46. slug: 'org-slug',
  47. features: ['global-views'],
  48. access: [],
  49. },
  50. router: {
  51. location: {query: {}, search: ''},
  52. params: {},
  53. },
  54. projects: [project],
  55. });
  56. const routerProps = {
  57. params: router.params,
  58. location: router.location,
  59. };
  60. function getSearchInput() {
  61. const input = screen.getAllByRole('combobox', {name: 'Add a search term'}).at(-1);
  62. expect(input).toBeInTheDocument();
  63. return input!;
  64. }
  65. describe('IssueList', function () {
  66. let props: any;
  67. const tags = TagsFixture();
  68. const group = GroupFixture({project});
  69. const groupStats = GroupStatsFixture();
  70. const savedSearch = SearchFixture({
  71. id: '789',
  72. query: 'is:unresolved TypeError',
  73. sort: 'date',
  74. name: 'Unresolved TypeErrors',
  75. });
  76. let fetchMembersRequest: jest.Mock;
  77. const api = new MockApiClient();
  78. const parseLinkHeaderSpy = jest.spyOn(parseLinkHeader, 'default');
  79. beforeEach(function () {
  80. // The tests fail because we have a "component update was not wrapped in act" error.
  81. // It should be safe to ignore this error, but we should remove the mock once we move to react testing library
  82. jest.spyOn(console, 'error').mockImplementation(jest.fn());
  83. Object.defineProperty(Element.prototype, 'clientWidth', {value: 1000});
  84. MockApiClient.addMockResponse({
  85. url: '/organizations/org-slug/issues/',
  86. body: [group],
  87. headers: {
  88. Link: DEFAULT_LINKS_HEADER,
  89. },
  90. });
  91. MockApiClient.addMockResponse({
  92. url: '/organizations/org-slug/issues-stats/',
  93. body: [groupStats],
  94. });
  95. MockApiClient.addMockResponse({
  96. url: '/organizations/org-slug/searches/',
  97. body: [savedSearch],
  98. });
  99. MockApiClient.addMockResponse({
  100. url: '/organizations/org-slug/recent-searches/',
  101. body: [],
  102. });
  103. MockApiClient.addMockResponse({
  104. url: '/organizations/org-slug/recent-searches/',
  105. method: 'POST',
  106. body: [],
  107. });
  108. MockApiClient.addMockResponse({
  109. url: '/organizations/org-slug/issues-count/',
  110. method: 'GET',
  111. body: [{}],
  112. });
  113. MockApiClient.addMockResponse({
  114. url: '/organizations/org-slug/processingissues/',
  115. method: 'GET',
  116. body: [
  117. {
  118. project: 'test-project',
  119. numIssues: 1,
  120. hasIssues: true,
  121. lastSeen: '2019-01-16T15:39:11.081Z',
  122. },
  123. ],
  124. });
  125. MockApiClient.addMockResponse({
  126. url: '/organizations/org-slug/tags/',
  127. method: 'GET',
  128. body: tags,
  129. });
  130. fetchMembersRequest = MockApiClient.addMockResponse({
  131. url: '/organizations/org-slug/users/',
  132. method: 'GET',
  133. body: [MemberFixture({projects: [project.slug]})],
  134. });
  135. MockApiClient.addMockResponse({
  136. url: '/organizations/org-slug/sent-first-event/',
  137. body: {sentFirstEvent: true},
  138. });
  139. MockApiClient.addMockResponse({
  140. url: '/organizations/org-slug/projects/',
  141. body: [project],
  142. });
  143. TagStore.init?.();
  144. props = {
  145. api,
  146. savedSearchLoading: false,
  147. savedSearches: [savedSearch],
  148. useOrgSavedSearches: true,
  149. selection: {
  150. projects: [parseInt(projects[0]!.id, 10)],
  151. environments: [],
  152. datetime: {period: '14d'},
  153. },
  154. location: {query: {query: DEFAULT_QUERY}, search: `query=${DEFAULT_QUERY}`},
  155. params: {},
  156. organization,
  157. tags: tags.reduce<Record<string, (typeof tags)[number]>>((acc, tag) => {
  158. acc[tag.key] = tag;
  159. return acc;
  160. }, {}),
  161. };
  162. });
  163. afterEach(function () {
  164. jest.clearAllMocks();
  165. MockApiClient.clearMockResponses();
  166. localStorageWrapper.clear();
  167. });
  168. describe('withStores and feature flags', function () {
  169. let issuesRequest: jest.Mock;
  170. beforeEach(function () {
  171. jest.mocked(StreamGroup).mockClear();
  172. MockApiClient.addMockResponse({
  173. url: '/organizations/org-slug/recent-searches/',
  174. method: 'GET',
  175. body: [],
  176. });
  177. MockApiClient.addMockResponse({
  178. url: '/organizations/org-slug/searches/',
  179. body: [savedSearch],
  180. });
  181. issuesRequest = MockApiClient.addMockResponse({
  182. url: '/organizations/org-slug/issues/',
  183. body: [group],
  184. headers: {
  185. Link: DEFAULT_LINKS_HEADER,
  186. },
  187. });
  188. });
  189. it('loads group rows with default query (no pinned queries, async and no query in URL)', async function () {
  190. render(<IssueListWithStores {...routerProps} />, {router, organization});
  191. await screen.findByRole('grid', {name: 'Create a search query'});
  192. expect(screen.getByRole('row', {name: 'is:unresolved'})).toBeInTheDocument();
  193. expect(screen.getByRole('button', {name: /custom search/i})).toBeInTheDocument();
  194. // primary /issues/ request
  195. await waitFor(() => {
  196. expect(issuesRequest).toHaveBeenCalledWith(
  197. expect.anything(),
  198. expect.objectContaining({
  199. // Should not be called with a "query" param, endpoint will find the default query itself
  200. data: expect.not.stringContaining('query'),
  201. })
  202. );
  203. });
  204. expect(issuesRequest).toHaveBeenCalledTimes(1);
  205. });
  206. it('loads with query in URL and pinned queries', async function () {
  207. MockApiClient.addMockResponse({
  208. url: '/organizations/org-slug/searches/',
  209. body: [
  210. savedSearch,
  211. SearchFixture({
  212. id: '123',
  213. name: 'My Pinned Search',
  214. isPinned: true,
  215. query: 'is:resolved',
  216. }),
  217. ],
  218. });
  219. const location = LocationFixture({query: {query: 'level:foo'}});
  220. render(<IssueListWithStores {...merge({}, routerProps, {location})} />, {
  221. router: {location},
  222. organization,
  223. });
  224. await waitFor(() => {
  225. // Main /issues/ request
  226. expect(issuesRequest).toHaveBeenCalledWith(
  227. expect.anything(),
  228. expect.objectContaining({
  229. // Should be called with default query
  230. data: expect.stringContaining('level%3Afoo'),
  231. })
  232. );
  233. });
  234. expect(screen.getByRole('row', {name: 'level:foo'})).toBeInTheDocument();
  235. // Tab shows "custom search"
  236. expect(screen.getByRole('button', {name: 'Custom Search'})).toBeInTheDocument();
  237. });
  238. it('loads with a saved query', async function () {
  239. MockApiClient.addMockResponse({
  240. url: '/organizations/org-slug/searches/',
  241. body: [
  242. SearchFixture({
  243. id: '123',
  244. name: 'Assigned to Me',
  245. isPinned: false,
  246. isGlobal: true,
  247. query: 'assigned:me',
  248. sort: 'trends',
  249. type: 0,
  250. }),
  251. ],
  252. });
  253. const localRouter = {params: {searchId: '123'}};
  254. render(<IssueListWithStores {...merge({}, routerProps, localRouter)} />, {
  255. router: localRouter,
  256. organization,
  257. });
  258. await waitFor(() => {
  259. expect(issuesRequest).toHaveBeenCalledWith(
  260. expect.anything(),
  261. expect.objectContaining({
  262. data: expect.stringContaining('searchId=123'),
  263. })
  264. );
  265. });
  266. expect(screen.getByRole('row', {name: 'assigned:me'})).toBeInTheDocument();
  267. // Organization saved search selector should have default saved search selected
  268. expect(screen.getByRole('button', {name: 'Assigned to Me'})).toBeInTheDocument();
  269. });
  270. it('loads with a query in URL', async function () {
  271. MockApiClient.addMockResponse({
  272. url: '/organizations/org-slug/searches/',
  273. body: [
  274. SearchFixture({
  275. id: '123',
  276. name: 'Assigned to Me',
  277. isPinned: false,
  278. isGlobal: true,
  279. query: 'assigned:me',
  280. type: 0,
  281. }),
  282. ],
  283. });
  284. const localRouter = {location: {query: {query: 'level:error'}}};
  285. render(<IssueListWithStores {...merge({}, routerProps, localRouter)} />, {
  286. router,
  287. organization,
  288. });
  289. await waitFor(() => {
  290. expect(issuesRequest).toHaveBeenCalledWith(
  291. expect.anything(),
  292. expect.objectContaining({
  293. // Should be called with default query
  294. data: expect.stringContaining('level%3Aerror'),
  295. })
  296. );
  297. });
  298. expect(screen.getByRole('row', {name: 'level:error'})).toBeInTheDocument();
  299. // Organization saved search selector should have default saved search selected
  300. expect(screen.getByRole('button', {name: 'Custom Search'})).toBeInTheDocument();
  301. });
  302. it('loads with an empty query in URL', async function () {
  303. MockApiClient.addMockResponse({
  304. url: '/organizations/org-slug/searches/',
  305. body: [
  306. SearchFixture({
  307. id: '123',
  308. name: 'My Pinned Search',
  309. isPinned: true,
  310. isGlobal: false,
  311. query: 'is:resolved',
  312. }),
  313. ],
  314. });
  315. render(
  316. <IssueListWithStores
  317. {...merge({}, routerProps, {location: {query: {query: undefined}}})}
  318. />,
  319. {router, organization}
  320. );
  321. await waitFor(() => {
  322. expect(issuesRequest).toHaveBeenCalledWith(
  323. expect.anything(),
  324. expect.objectContaining({
  325. // Should be called with empty query
  326. data: expect.stringContaining(''),
  327. })
  328. );
  329. });
  330. expect(screen.getByRole('row', {name: 'is:resolved'})).toBeInTheDocument();
  331. // Organization saved search selector should have default saved search selected
  332. expect(screen.getByRole('button', {name: 'My Default Search'})).toBeInTheDocument();
  333. });
  334. it('caches the search results', async function () {
  335. issuesRequest = MockApiClient.addMockResponse({
  336. url: '/organizations/org-slug/issues/',
  337. body: [...new Array(25)].map((_, i) => ({id: i})),
  338. headers: {
  339. Link: DEFAULT_LINKS_HEADER,
  340. 'X-Hits': '500',
  341. 'X-Max-Hits': '1000',
  342. },
  343. });
  344. const defaultProps = {
  345. ...props,
  346. ...routerProps,
  347. useOrgSavedSearches: true,
  348. selection: {
  349. projects: [],
  350. environments: [],
  351. datetime: {period: '14d'},
  352. },
  353. organization: OrganizationFixture({
  354. features: ['issue-stream-performance'],
  355. }),
  356. };
  357. const {unmount} = render(<IssueListWithStores {...defaultProps} />, {
  358. router,
  359. organization: defaultProps.organization,
  360. });
  361. expect(
  362. await screen.findByText(textWithMarkupMatcher('1-25 of 500'))
  363. ).toBeInTheDocument();
  364. expect(issuesRequest).toHaveBeenCalledTimes(1);
  365. unmount();
  366. // Mount component again, getting from cache
  367. render(<IssueListWithStores {...defaultProps} />, {
  368. router,
  369. organization: defaultProps.organization,
  370. });
  371. expect(
  372. await screen.findByText(textWithMarkupMatcher('1-25 of 500'))
  373. ).toBeInTheDocument();
  374. expect(issuesRequest).toHaveBeenCalledTimes(1);
  375. });
  376. it('1 search', async function () {
  377. const localSavedSearch = {...savedSearch, projectId: null};
  378. MockApiClient.addMockResponse({
  379. url: '/organizations/org-slug/searches/',
  380. body: [localSavedSearch],
  381. });
  382. render(<IssueListWithStores {...routerProps} />, {
  383. router,
  384. organization,
  385. });
  386. await userEvent.click(await screen.findByRole('button', {name: /custom search/i}));
  387. await userEvent.click(screen.getByRole('button', {name: localSavedSearch.name}));
  388. expect(router.push).toHaveBeenLastCalledWith(
  389. expect.objectContaining({
  390. pathname: '/organizations/org-slug/issues/searches/789/',
  391. })
  392. );
  393. });
  394. it('clears a saved search when a custom one is entered', async function () {
  395. MockApiClient.addMockResponse({
  396. url: '/organizations/org-slug/searches/',
  397. body: [
  398. savedSearch,
  399. SearchFixture({
  400. id: '123',
  401. name: 'Pinned search',
  402. isPinned: true,
  403. isGlobal: false,
  404. query: 'is:resolved',
  405. }),
  406. ],
  407. });
  408. render(<IssueListWithStores {...routerProps} />, {
  409. router,
  410. organization,
  411. });
  412. await screen.findByRole('grid', {name: 'Create a search query'});
  413. await userEvent.click(screen.getByRole('button', {name: 'Clear search query'}));
  414. await userEvent.click(getSearchInput());
  415. await userEvent.keyboard('dogs{Enter}');
  416. expect(router.push).toHaveBeenLastCalledWith(
  417. expect.objectContaining({
  418. pathname: '/organizations/org-slug/issues/',
  419. query: {
  420. environment: [],
  421. project: [],
  422. referrer: 'issue-list',
  423. sort: '',
  424. query: 'dogs',
  425. statsPeriod: '14d',
  426. },
  427. })
  428. );
  429. });
  430. it('pins a custom query', async function () {
  431. const pinnedSearch = {
  432. id: '666',
  433. name: 'My Pinned Search',
  434. query: 'assigned:me level:fatal',
  435. sort: 'date',
  436. isPinned: true,
  437. visibility: SavedSearchVisibility.ORGANIZATION,
  438. };
  439. MockApiClient.addMockResponse({
  440. url: '/organizations/org-slug/searches/',
  441. body: [savedSearch],
  442. });
  443. const {rerender} = render(<IssueListWithStores {...routerProps} />, {
  444. router,
  445. organization,
  446. });
  447. await screen.findByRole('grid', {name: 'Create a search query'});
  448. await userEvent.click(screen.getByRole('button', {name: 'Clear search query'}));
  449. await userEvent.click(getSearchInput());
  450. await userEvent.paste('assigned:me level:fatal');
  451. await userEvent.keyboard('{Enter}');
  452. expect(router.push).toHaveBeenCalledWith(
  453. expect.objectContaining({
  454. query: expect.objectContaining({
  455. query: 'assigned:me level:fatal',
  456. }),
  457. })
  458. );
  459. await tick();
  460. const routerWithQuery = {location: {query: {query: 'assigned:me level:fatal'}}};
  461. rerender(<IssueListWithStores {...merge({}, routerProps, routerWithQuery)} />);
  462. expect(screen.getByRole('button', {name: 'Custom Search'})).toBeInTheDocument();
  463. MockApiClient.clearMockResponses();
  464. const createPin = MockApiClient.addMockResponse({
  465. url: '/organizations/org-slug/pinned-searches/',
  466. method: 'PUT',
  467. body: pinnedSearch,
  468. });
  469. MockApiClient.addMockResponse({
  470. url: '/organizations/org-slug/searches/',
  471. body: [savedSearch, pinnedSearch],
  472. });
  473. await userEvent.click(screen.getByLabelText(/Set as Default/i));
  474. await waitFor(() => {
  475. expect(createPin).toHaveBeenCalled();
  476. });
  477. expect(router.replace).toHaveBeenLastCalledWith(
  478. expect.objectContaining({
  479. pathname: '/organizations/org-slug/issues/searches/666/',
  480. query: {
  481. referrer: 'search-bar',
  482. },
  483. search: '',
  484. })
  485. );
  486. });
  487. it('unpins a custom query', async function () {
  488. const pinnedSearch = SearchFixture({
  489. id: '666',
  490. name: 'My Pinned Search',
  491. query: 'assigned:me level:fatal',
  492. sort: 'date',
  493. isPinned: true,
  494. visibility: SavedSearchVisibility.ORGANIZATION,
  495. });
  496. MockApiClient.addMockResponse({
  497. url: '/organizations/org-slug/searches/',
  498. body: [pinnedSearch],
  499. });
  500. const deletePin = MockApiClient.addMockResponse({
  501. url: '/organizations/org-slug/pinned-searches/',
  502. method: 'DELETE',
  503. });
  504. const routerWithSavedSearch = RouterFixture({
  505. params: {searchId: pinnedSearch.id},
  506. });
  507. render(<IssueListWithStores {...merge({}, routerProps, routerWithSavedSearch)} />, {
  508. router: routerWithSavedSearch,
  509. organization,
  510. });
  511. expect(
  512. await screen.findByRole('button', {name: 'My Default Search'})
  513. ).toBeInTheDocument();
  514. await userEvent.click(screen.getByLabelText(/Remove Default/i));
  515. await waitFor(() => {
  516. expect(deletePin).toHaveBeenCalled();
  517. });
  518. await waitFor(() => {
  519. expect(routerWithSavedSearch.replace).toHaveBeenLastCalledWith(
  520. expect.objectContaining({
  521. pathname: '/organizations/org-slug/issues/',
  522. })
  523. );
  524. });
  525. });
  526. it('pins a saved query', async function () {
  527. const assignedToMe = SearchFixture({
  528. id: '234',
  529. name: 'Assigned to Me',
  530. isPinned: false,
  531. isGlobal: true,
  532. query: 'assigned:me',
  533. sort: 'date',
  534. type: 0,
  535. });
  536. MockApiClient.addMockResponse({
  537. url: '/organizations/org-slug/searches/',
  538. body: [savedSearch, assignedToMe],
  539. });
  540. const createPin = MockApiClient.addMockResponse({
  541. url: '/organizations/org-slug/pinned-searches/',
  542. method: 'PUT',
  543. body: {
  544. ...savedSearch,
  545. isPinned: true,
  546. },
  547. });
  548. const routerWithSavedSearch = RouterFixture({params: {searchId: '789'}});
  549. render(<IssueListWithStores {...merge({}, routerProps, routerWithSavedSearch)} />, {
  550. router: routerWithSavedSearch,
  551. organization,
  552. });
  553. expect(
  554. await screen.findByRole('button', {name: savedSearch.name})
  555. ).toBeInTheDocument();
  556. await userEvent.click(screen.getByLabelText(/set as default/i));
  557. await waitFor(() => {
  558. expect(createPin).toHaveBeenCalled();
  559. });
  560. expect(routerWithSavedSearch.replace).toHaveBeenLastCalledWith(
  561. expect.objectContaining({
  562. pathname: '/organizations/org-slug/issues/searches/789/',
  563. })
  564. );
  565. });
  566. it('pinning search should keep project selected', async function () {
  567. MockApiClient.addMockResponse({
  568. url: '/organizations/org-slug/searches/',
  569. body: [savedSearch],
  570. });
  571. const {router: newRouter} = initializeOrg({
  572. router: {
  573. location: {
  574. query: {
  575. project: ['123'],
  576. environment: ['prod'],
  577. query: 'assigned:me level:fatal',
  578. },
  579. },
  580. },
  581. });
  582. render(
  583. <IssueListWithStores
  584. {...newRouter}
  585. selection={{
  586. projects: [123],
  587. environments: ['prod'],
  588. datetime: {
  589. end: null,
  590. period: null,
  591. start: null,
  592. utc: null,
  593. },
  594. }}
  595. />,
  596. {router: newRouter, organization}
  597. );
  598. const createPin = MockApiClient.addMockResponse({
  599. url: '/organizations/org-slug/pinned-searches/',
  600. method: 'PUT',
  601. body: {
  602. ...savedSearch,
  603. id: '666',
  604. name: 'My Pinned Search',
  605. query: 'assigned:me level:fatal',
  606. sort: 'date',
  607. isPinned: true,
  608. },
  609. });
  610. await userEvent.click(await screen.findByLabelText(/set as default/i));
  611. await waitFor(() => {
  612. expect(createPin).toHaveBeenCalled();
  613. });
  614. expect(newRouter.replace).toHaveBeenLastCalledWith(
  615. expect.objectContaining({
  616. pathname: '/organizations/org-slug/issues/searches/666/',
  617. query: expect.objectContaining({
  618. project: ['123'],
  619. environment: ['prod'],
  620. query: 'assigned:me level:fatal',
  621. referrer: 'search-bar',
  622. }),
  623. })
  624. );
  625. });
  626. it('unpinning search should keep project selected', async function () {
  627. const localSavedSearch = {
  628. ...savedSearch,
  629. id: '666',
  630. isPinned: true,
  631. query: 'assigned:me level:fatal',
  632. };
  633. MockApiClient.addMockResponse({
  634. url: '/organizations/org-slug/searches/',
  635. body: [localSavedSearch],
  636. });
  637. const deletePin = MockApiClient.addMockResponse({
  638. url: '/organizations/org-slug/pinned-searches/',
  639. method: 'DELETE',
  640. });
  641. const {router: newRouter} = initializeOrg(
  642. merge({}, router, {
  643. router: {
  644. location: {
  645. query: {
  646. project: ['123'],
  647. environment: ['prod'],
  648. query: 'assigned:me level:fatal',
  649. },
  650. },
  651. params: {searchId: '666'},
  652. },
  653. })
  654. );
  655. render(
  656. <IssueListWithStores
  657. {...newRouter}
  658. selection={{
  659. projects: [123],
  660. environments: ['prod'],
  661. datetime: {
  662. end: null,
  663. period: null,
  664. start: null,
  665. utc: null,
  666. },
  667. }}
  668. savedSearch={localSavedSearch}
  669. />,
  670. {router: newRouter, organization}
  671. );
  672. await userEvent.click(await screen.findByLabelText(/Remove Default/i));
  673. await waitFor(() => {
  674. expect(deletePin).toHaveBeenCalled();
  675. });
  676. expect(newRouter.replace).toHaveBeenLastCalledWith(
  677. expect.objectContaining({
  678. pathname: '/organizations/org-slug/issues/',
  679. query: expect.objectContaining({
  680. project: ['123'],
  681. environment: ['prod'],
  682. query: 'assigned:me level:fatal',
  683. referrer: 'search-bar',
  684. }),
  685. })
  686. );
  687. });
  688. it('does not allow pagination to "previous" while on first page and resets cursors when navigating back to initial page', async function () {
  689. const {rerender} = render(<IssueListWithStores {...routerProps} />, {
  690. router,
  691. organization,
  692. });
  693. expect(await screen.findByRole('button', {name: 'Previous'})).toBeDisabled();
  694. issuesRequest = MockApiClient.addMockResponse({
  695. url: '/organizations/org-slug/issues/',
  696. body: [group],
  697. headers: {
  698. 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"',
  699. },
  700. });
  701. await userEvent.click(await screen.findByRole('button', {name: 'Next'}));
  702. let pushArgs = {
  703. pathname: '/organizations/org-slug/issues/',
  704. query: {
  705. cursor: '1443575000:0:0',
  706. page: 1,
  707. environment: [],
  708. project: [],
  709. query: DEFAULT_QUERY,
  710. statsPeriod: '14d',
  711. referrer: 'issue-list',
  712. },
  713. };
  714. await waitFor(() => {
  715. expect(router.push).toHaveBeenLastCalledWith(pushArgs);
  716. });
  717. rerender(<IssueListWithStores {...merge({}, routerProps, {location: pushArgs})} />);
  718. expect(screen.getByRole('button', {name: 'Previous'})).toBeEnabled();
  719. // Click next again
  720. await userEvent.click(screen.getByRole('button', {name: 'Next'}));
  721. pushArgs = {
  722. pathname: '/organizations/org-slug/issues/',
  723. query: {
  724. cursor: '1443574000:0:0',
  725. page: 2,
  726. environment: [],
  727. project: [],
  728. query: DEFAULT_QUERY,
  729. statsPeriod: '14d',
  730. referrer: 'issue-list',
  731. },
  732. };
  733. await waitFor(() => {
  734. expect(router.push).toHaveBeenLastCalledWith(pushArgs);
  735. });
  736. rerender(<IssueListWithStores {...merge({}, routerProps, {location: pushArgs})} />);
  737. // Click previous
  738. await userEvent.click(screen.getByRole('button', {name: 'Previous'}));
  739. pushArgs = {
  740. pathname: '/organizations/org-slug/issues/',
  741. query: {
  742. cursor: '1443575000:0:1',
  743. page: 1,
  744. environment: [],
  745. project: [],
  746. query: DEFAULT_QUERY,
  747. statsPeriod: '14d',
  748. referrer: 'issue-list',
  749. },
  750. };
  751. await waitFor(() => {
  752. expect(router.push).toHaveBeenLastCalledWith(pushArgs);
  753. });
  754. rerender(<IssueListWithStores {...merge({}, routerProps, {location: pushArgs})} />);
  755. // Click previous back to initial page
  756. await userEvent.click(screen.getByRole('button', {name: 'Previous'}));
  757. await waitFor(() => {
  758. // cursor is undefined because "prev" cursor is === initial "next" cursor
  759. expect(router.push).toHaveBeenLastCalledWith({
  760. pathname: '/organizations/org-slug/issues/',
  761. query: {
  762. cursor: undefined,
  763. environment: [],
  764. page: undefined,
  765. project: [],
  766. query: DEFAULT_QUERY,
  767. statsPeriod: '14d',
  768. referrer: 'issue-list',
  769. },
  770. });
  771. });
  772. });
  773. });
  774. describe('transitionTo', function () {
  775. it('pushes to history when query is updated', async function () {
  776. MockApiClient.addMockResponse({
  777. url: '/organizations/org-slug/issues/',
  778. body: [],
  779. headers: {
  780. Link: DEFAULT_LINKS_HEADER,
  781. },
  782. });
  783. render(<IssueListOverview {...props} />, {
  784. router,
  785. });
  786. await userEvent.click(screen.getByRole('button', {name: 'Clear search query'}));
  787. await userEvent.click(getSearchInput());
  788. await userEvent.paste('is:ignored');
  789. await userEvent.keyboard('{enter}');
  790. await waitFor(() => {
  791. expect(router.push).toHaveBeenCalledWith({
  792. pathname: '/organizations/org-slug/issues/',
  793. query: {
  794. environment: [],
  795. project: [parseInt(project.id, 10)],
  796. query: 'is:ignored',
  797. statsPeriod: '14d',
  798. referrer: 'issue-list',
  799. },
  800. });
  801. });
  802. });
  803. });
  804. it('fetches members', async function () {
  805. render(<IssueListOverview {...routerProps} {...props} />, {router});
  806. await waitFor(() => {
  807. expect(fetchMembersRequest).toHaveBeenCalled();
  808. });
  809. });
  810. describe('componentDidUpdate fetching groups', function () {
  811. let fetchDataMock: jest.Mock;
  812. beforeEach(function () {
  813. fetchDataMock = MockApiClient.addMockResponse({
  814. url: '/organizations/org-slug/issues/',
  815. body: [group],
  816. headers: {
  817. Link: DEFAULT_LINKS_HEADER,
  818. },
  819. });
  820. fetchDataMock.mockReset();
  821. });
  822. it('fetches data on selection change', async function () {
  823. const {rerender} = render(<IssueListOverview {...routerProps} {...props} />, {
  824. router,
  825. });
  826. rerender(
  827. <IssueListOverview
  828. {...routerProps}
  829. {...props}
  830. selection={{projects: [99], environments: [], datetime: {period: '24h'}}}
  831. />
  832. );
  833. await waitFor(() => {
  834. expect(fetchDataMock).toHaveBeenCalled();
  835. });
  836. });
  837. it('fetches data on savedSearch change', async function () {
  838. const {rerender} = render(<IssueListOverview {...routerProps} {...props} />, {
  839. router,
  840. });
  841. rerender(
  842. <IssueListOverview
  843. {...routerProps}
  844. {...props}
  845. savedSearch={{id: '1', query: 'is:resolved'}}
  846. />
  847. );
  848. await waitFor(() => {
  849. expect(fetchDataMock).toHaveBeenCalled();
  850. });
  851. });
  852. it('uses correct statsPeriod when fetching issues list and no datetime given', async function () {
  853. const {rerender} = render(<IssueListOverview {...routerProps} {...props} />, {
  854. router,
  855. });
  856. const selection = {projects: [99], environments: [], datetime: {}};
  857. rerender(<IssueListOverview {...routerProps} {...props} selection={selection} />);
  858. await waitFor(() => {
  859. expect(fetchDataMock).toHaveBeenLastCalledWith(
  860. '/organizations/org-slug/issues/',
  861. expect.objectContaining({
  862. data: 'collapse=stats&collapse=unhandled&expand=owners&expand=inbox&limit=25&project=99&query=is%3Aunresolved%20issue.priority%3A%5Bhigh%2C%20medium%5D&savedSearch=1&shortIdLookup=1&statsPeriod=14d',
  863. })
  864. );
  865. });
  866. });
  867. });
  868. describe('componentDidUpdate fetching members', function () {
  869. it('fetches memberlist on project change', async function () {
  870. const {rerender} = render(<IssueListOverview {...routerProps} {...props} />, {
  871. router,
  872. });
  873. // Called during componentDidMount
  874. await waitFor(() => {
  875. expect(fetchMembersRequest).toHaveBeenCalled();
  876. });
  877. const selection = {
  878. projects: [99],
  879. environments: [],
  880. datetime: {period: '24h'},
  881. };
  882. rerender(<IssueListOverview {...routerProps} {...props} selection={selection} />);
  883. await waitFor(() => {
  884. expect(fetchMembersRequest).toHaveBeenCalledWith(
  885. expect.anything(),
  886. expect.objectContaining({
  887. query: {
  888. project: selection.projects.map(p => p.toString()),
  889. },
  890. })
  891. );
  892. });
  893. });
  894. });
  895. describe('render states', function () {
  896. it('displays an error when issues fail to load', async function () {
  897. MockApiClient.addMockResponse({
  898. url: '/organizations/org-slug/issues/',
  899. status: 500,
  900. statusCode: 500,
  901. });
  902. render(<IssueListOverview {...routerProps} {...props} />, {
  903. router,
  904. });
  905. expect(await screen.findByTestId('loading-error')).toBeInTheDocument();
  906. });
  907. it('displays congrats robots animation with only default query', async function () {
  908. MockApiClient.addMockResponse({
  909. url: '/organizations/org-slug/issues/',
  910. body: [],
  911. headers: {
  912. Link: DEFAULT_LINKS_HEADER,
  913. },
  914. });
  915. render(<IssueListOverview {...routerProps} {...props} />, {router});
  916. expect(
  917. await screen.findByText(/We couldn't find any issues that matched your filters/i)
  918. ).toBeInTheDocument();
  919. });
  920. it('displays an empty resultset with a non-default query', async function () {
  921. MockApiClient.addMockResponse({
  922. url: '/organizations/org-slug/issues/',
  923. body: [],
  924. headers: {
  925. Link: DEFAULT_LINKS_HEADER,
  926. },
  927. });
  928. render(<IssueListOverview {...routerProps} {...props} />, {router});
  929. await screen.findByRole('grid', {name: 'Create a search query'});
  930. await userEvent.click(getSearchInput());
  931. await userEvent.keyboard('foo{enter}');
  932. expect(
  933. await screen.findByText(/We couldn't find any issues that matched your filters/i)
  934. ).toBeInTheDocument();
  935. });
  936. });
  937. describe('Error Robot', function () {
  938. const createWrapper = async (moreProps: any) => {
  939. MockApiClient.addMockResponse({
  940. url: '/organizations/org-slug/issues/',
  941. body: [],
  942. headers: {
  943. Link: DEFAULT_LINKS_HEADER,
  944. },
  945. });
  946. const defaultProps = {
  947. ...props,
  948. useOrgSavedSearches: true,
  949. selection: {
  950. projects: [],
  951. environments: [],
  952. datetime: {period: '14d'},
  953. },
  954. ...merge({}, routerProps, {
  955. params: {},
  956. location: {query: {query: DEFAULT_QUERY}, search: 'query=is:unresolved'},
  957. }),
  958. organization: OrganizationFixture(),
  959. ...moreProps,
  960. };
  961. render(<IssueListOverview {...defaultProps} />, {router});
  962. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  963. };
  964. it('displays when no projects selected and all projects user is member of, async does not have first event', async function () {
  965. const projectsBody = [
  966. ProjectFixture({
  967. id: '1',
  968. slug: 'foo',
  969. isMember: true,
  970. firstEvent: null,
  971. }),
  972. ProjectFixture({
  973. id: '2',
  974. slug: 'bar',
  975. isMember: true,
  976. firstEvent: null,
  977. }),
  978. ProjectFixture({
  979. id: '3',
  980. slug: 'baz',
  981. isMember: true,
  982. firstEvent: null,
  983. }),
  984. ];
  985. MockApiClient.addMockResponse({
  986. url: '/organizations/org-slug/sent-first-event/',
  987. query: {
  988. is_member: true,
  989. },
  990. body: {sentFirstEvent: false},
  991. });
  992. MockApiClient.addMockResponse({
  993. url: '/organizations/org-slug/projects/',
  994. body: projectsBody,
  995. });
  996. MockApiClient.addMockResponse({
  997. url: '/projects/org-slug/foo/issues/',
  998. body: [],
  999. });
  1000. await createWrapper({
  1001. organization: OrganizationFixture(),
  1002. });
  1003. expect(await screen.findByTestId('awaiting-events')).toBeInTheDocument();
  1004. });
  1005. it('does not display when no projects selected and any projects have a first event', async function () {
  1006. const projectsBody = [
  1007. ProjectFixture({
  1008. id: '1',
  1009. slug: 'foo',
  1010. isMember: true,
  1011. firstEvent: null,
  1012. }),
  1013. ProjectFixture({
  1014. id: '2',
  1015. slug: 'bar',
  1016. isMember: true,
  1017. firstEvent: new Date().toISOString(),
  1018. }),
  1019. ProjectFixture({
  1020. id: '3',
  1021. slug: 'baz',
  1022. isMember: true,
  1023. firstEvent: null,
  1024. }),
  1025. ];
  1026. MockApiClient.addMockResponse({
  1027. url: '/organizations/org-slug/sent-first-event/',
  1028. query: {
  1029. is_member: true,
  1030. },
  1031. body: {sentFirstEvent: true},
  1032. });
  1033. MockApiClient.addMockResponse({
  1034. url: '/organizations/org-slug/projects/',
  1035. body: projectsBody,
  1036. });
  1037. await createWrapper({
  1038. organization: OrganizationFixture(),
  1039. });
  1040. expect(screen.queryByTestId('awaiting-events')).not.toBeInTheDocument();
  1041. });
  1042. it('displays when all selected projects do not have first event', async function () {
  1043. const projectsBody = [
  1044. ProjectFixture({
  1045. id: '1',
  1046. slug: 'foo',
  1047. isMember: true,
  1048. firstEvent: null,
  1049. }),
  1050. ProjectFixture({
  1051. id: '2',
  1052. slug: 'bar',
  1053. isMember: true,
  1054. firstEvent: null,
  1055. }),
  1056. ProjectFixture({
  1057. id: '3',
  1058. slug: 'baz',
  1059. isMember: true,
  1060. firstEvent: null,
  1061. }),
  1062. ];
  1063. MockApiClient.addMockResponse({
  1064. url: '/organizations/org-slug/sent-first-event/',
  1065. query: {
  1066. project: [1, 2],
  1067. },
  1068. body: {sentFirstEvent: false},
  1069. });
  1070. MockApiClient.addMockResponse({
  1071. url: '/organizations/org-slug/projects/',
  1072. body: projectsBody,
  1073. });
  1074. MockApiClient.addMockResponse({
  1075. url: '/projects/org-slug/foo/issues/',
  1076. body: [],
  1077. });
  1078. await createWrapper({
  1079. selection: {
  1080. projects: [1, 2],
  1081. environments: [],
  1082. datetime: {period: '14d'},
  1083. },
  1084. organization: OrganizationFixture(),
  1085. });
  1086. expect(await screen.findByTestId('awaiting-events')).toBeInTheDocument();
  1087. });
  1088. it('does not display when any selected projects have first event', async function () {
  1089. const projectsBody = [
  1090. ProjectFixture({
  1091. id: '1',
  1092. slug: 'foo',
  1093. isMember: true,
  1094. firstEvent: null,
  1095. }),
  1096. ProjectFixture({
  1097. id: '2',
  1098. slug: 'bar',
  1099. isMember: true,
  1100. firstEvent: new Date().toISOString(),
  1101. }),
  1102. ProjectFixture({
  1103. id: '3',
  1104. slug: 'baz',
  1105. isMember: true,
  1106. firstEvent: new Date().toISOString(),
  1107. }),
  1108. ];
  1109. MockApiClient.addMockResponse({
  1110. url: '/organizations/org-slug/sent-first-event/',
  1111. query: {
  1112. project: [1, 2],
  1113. },
  1114. body: {sentFirstEvent: true},
  1115. });
  1116. MockApiClient.addMockResponse({
  1117. url: '/organizations/org-slug/projects/',
  1118. body: projectsBody,
  1119. });
  1120. await createWrapper({
  1121. selection: {
  1122. projects: [1, 2],
  1123. environments: [],
  1124. datetime: {period: '14d'},
  1125. },
  1126. organization: OrganizationFixture(),
  1127. });
  1128. expect(screen.queryByTestId('awaiting-events')).not.toBeInTheDocument();
  1129. });
  1130. });
  1131. it('displays a count that represents the current page', async function () {
  1132. MockApiClient.addMockResponse({
  1133. url: '/organizations/org-slug/issues/',
  1134. body: [...new Array(25)].map((_, i) => ({id: i})),
  1135. headers: {
  1136. Link: DEFAULT_LINKS_HEADER,
  1137. 'X-Hits': '500',
  1138. 'X-Max-Hits': '1000',
  1139. },
  1140. });
  1141. parseLinkHeaderSpy.mockReturnValue({
  1142. next: {
  1143. results: true,
  1144. cursor: '',
  1145. href: '',
  1146. },
  1147. previous: {
  1148. results: false,
  1149. cursor: '',
  1150. href: '',
  1151. },
  1152. });
  1153. props = {
  1154. ...props,
  1155. location: {
  1156. query: {
  1157. cursor: 'some cursor',
  1158. page: 1,
  1159. },
  1160. },
  1161. };
  1162. const {router: newRouter} = initializeOrg();
  1163. const {rerender} = render(<IssueListOverview {...props} />, {
  1164. router: newRouter,
  1165. });
  1166. await waitFor(() => {
  1167. expect(screen.getByText(textWithMarkupMatcher('1-25 of 500'))).toBeInTheDocument();
  1168. });
  1169. parseLinkHeaderSpy.mockReturnValue({
  1170. next: {
  1171. results: true,
  1172. cursor: '',
  1173. href: '',
  1174. },
  1175. previous: {
  1176. results: true,
  1177. cursor: '',
  1178. href: '',
  1179. },
  1180. });
  1181. rerender(<IssueListOverview {...props} />);
  1182. await waitFor(() => {
  1183. expect(screen.getByText(textWithMarkupMatcher('26-50 of 500'))).toBeInTheDocument();
  1184. });
  1185. });
  1186. describe('project low trends queue alert', function () {
  1187. const {router: newRouter} = initializeOrg();
  1188. beforeEach(function () {
  1189. act(() => ProjectsStore.reset());
  1190. });
  1191. it('does not render event processing alert', async function () {
  1192. act(() => ProjectsStore.loadInitialData([project]));
  1193. render(<IssueListOverview {...props} />, {
  1194. router: newRouter,
  1195. });
  1196. await waitFor(() => {
  1197. expect(screen.queryByText(/event processing/i)).not.toBeInTheDocument();
  1198. });
  1199. });
  1200. describe('renders alert', function () {
  1201. it('for one project', async function () {
  1202. act(() =>
  1203. ProjectsStore.loadInitialData([
  1204. {...project, eventProcessing: {symbolicationDegraded: true}},
  1205. ])
  1206. );
  1207. render(<IssueListOverview {...props} />, {router});
  1208. await waitFor(() => {
  1209. expect(
  1210. screen.getByText(/Event Processing for this project is currently degraded/i)
  1211. ).toBeInTheDocument();
  1212. });
  1213. });
  1214. it('for multiple projects', async function () {
  1215. const projectBar = ProjectFixture({
  1216. id: '3560',
  1217. name: 'Bar Project',
  1218. slug: 'project-slug-bar',
  1219. });
  1220. act(() =>
  1221. ProjectsStore.loadInitialData([
  1222. {
  1223. ...project,
  1224. slug: 'project-slug',
  1225. eventProcessing: {symbolicationDegraded: true},
  1226. },
  1227. {
  1228. ...projectBar,
  1229. slug: 'project-slug-bar',
  1230. eventProcessing: {symbolicationDegraded: true},
  1231. },
  1232. ])
  1233. );
  1234. render(
  1235. <IssueListOverview
  1236. {...props}
  1237. selection={{
  1238. ...props.selection,
  1239. projects: [Number(project.id), Number(projectBar.id)],
  1240. }}
  1241. />,
  1242. {
  1243. router: newRouter,
  1244. }
  1245. );
  1246. await waitFor(() => {
  1247. expect(
  1248. screen.getByText(
  1249. textWithMarkupMatcher(
  1250. 'Event Processing for the project-slug, project-slug-bar projects is currently degraded.'
  1251. )
  1252. )
  1253. ).toBeInTheDocument();
  1254. });
  1255. });
  1256. });
  1257. });
  1258. });