overview.spec.jsx 41 KB

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