overview.spec.tsx 41 KB

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