overview.spec.tsx 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. import {browserHistory} from 'react-router';
  2. import merge from 'lodash/merge';
  3. import {GroupStats} from 'sentry-fixture/groupStats';
  4. import {Search} from 'sentry-fixture/search';
  5. import {Tags} from 'sentry-fixture/tags';
  6. import {initializeOrg} from 'sentry-test/initializeOrg';
  7. import {
  8. act,
  9. render,
  10. screen,
  11. userEvent,
  12. waitFor,
  13. waitForElementToBeRemoved,
  14. } from 'sentry-test/reactTestingLibrary';
  15. import {textWithMarkupMatcher} from 'sentry-test/utils';
  16. import StreamGroup from 'sentry/components/stream/group';
  17. import ProjectsStore from 'sentry/stores/projectsStore';
  18. import TagStore from 'sentry/stores/tagStore';
  19. import {SavedSearchVisibility} from 'sentry/types';
  20. import localStorageWrapper from 'sentry/utils/localStorage';
  21. import * as parseLinkHeader from 'sentry/utils/parseLinkHeader';
  22. import IssueListWithStores, {IssueListOverview} from 'sentry/views/issueList/overview';
  23. // Mock <IssueListActions>
  24. jest.mock('sentry/views/issueList/actions', () => jest.fn(() => null));
  25. jest.mock('sentry/components/stream/group', () => jest.fn(() => null));
  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.Project({
  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: [],
  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. const tags = Tags();
  55. const group = TestStubs.Group({project});
  56. const groupStats = GroupStats();
  57. const savedSearch = Search({
  58. id: '789',
  59. query: 'is:unresolved TypeError',
  60. sort: 'date',
  61. name: 'Unresolved TypeErrors',
  62. });
  63. let fetchTagsRequest: jest.Mock;
  64. let fetchMembersRequest: jest.Mock;
  65. const api = new MockApiClient();
  66. const parseLinkHeaderSpy = jest.spyOn(parseLinkHeader, 'default');
  67. beforeEach(function () {
  68. // The tests fail because we have a "component update was not wrapped in act" error.
  69. // It should be safe to ignore this error, but we should remove the mock once we move to react testing library
  70. // eslint-disable-next-line no-console
  71. jest.spyOn(console, 'error').mockImplementation(jest.fn());
  72. MockApiClient.addMockResponse({
  73. url: '/organizations/org-slug/issues/',
  74. body: [group],
  75. headers: {
  76. Link: DEFAULT_LINKS_HEADER,
  77. },
  78. });
  79. MockApiClient.addMockResponse({
  80. url: '/organizations/org-slug/issues-stats/',
  81. body: [groupStats],
  82. });
  83. MockApiClient.addMockResponse({
  84. url: '/organizations/org-slug/searches/',
  85. body: [savedSearch],
  86. });
  87. MockApiClient.addMockResponse({
  88. url: '/organizations/org-slug/recent-searches/',
  89. body: [],
  90. });
  91. MockApiClient.addMockResponse({
  92. url: '/organizations/org-slug/recent-searches/',
  93. method: 'POST',
  94. body: [],
  95. });
  96. MockApiClient.addMockResponse({
  97. url: '/organizations/org-slug/issues-count/',
  98. method: 'GET',
  99. body: [{}],
  100. });
  101. MockApiClient.addMockResponse({
  102. url: '/organizations/org-slug/processingissues/',
  103. method: 'GET',
  104. body: [
  105. {
  106. project: 'test-project',
  107. numIssues: 1,
  108. hasIssues: true,
  109. lastSeen: '2019-01-16T15:39:11.081Z',
  110. },
  111. ],
  112. });
  113. fetchTagsRequest = MockApiClient.addMockResponse({
  114. url: '/organizations/org-slug/tags/',
  115. method: 'GET',
  116. body: tags,
  117. });
  118. fetchMembersRequest = MockApiClient.addMockResponse({
  119. url: '/organizations/org-slug/users/',
  120. method: 'GET',
  121. body: [TestStubs.Member({projects: [project.slug]})],
  122. });
  123. MockApiClient.addMockResponse({
  124. url: '/organizations/org-slug/sent-first-event/',
  125. body: {sentFirstEvent: true},
  126. });
  127. MockApiClient.addMockResponse({
  128. url: '/organizations/org-slug/projects/',
  129. body: [project],
  130. });
  131. TagStore.init?.();
  132. props = {
  133. api,
  134. savedSearchLoading: false,
  135. savedSearches: [savedSearch],
  136. useOrgSavedSearches: true,
  137. selection: {
  138. projects: [parseInt(organization.projects[0].id, 10)],
  139. environments: [],
  140. datetime: {period: '14d'},
  141. },
  142. location: {query: {query: 'is:unresolved'}, search: 'query=is:unresolved'},
  143. params: {},
  144. organization,
  145. tags: tags.reduce((acc, tag) => {
  146. acc[tag.key] = tag;
  147. return acc;
  148. }),
  149. };
  150. });
  151. afterEach(function () {
  152. jest.clearAllMocks();
  153. MockApiClient.clearMockResponses();
  154. localStorageWrapper.clear();
  155. });
  156. describe('withStores and feature flags', function () {
  157. let savedSearchesRequest: jest.Mock;
  158. let recentSearchesRequest: jest.Mock;
  159. let issuesRequest: jest.Mock;
  160. beforeEach(function () {
  161. jest.mocked(StreamGroup).mockClear();
  162. recentSearchesRequest = MockApiClient.addMockResponse({
  163. url: '/organizations/org-slug/recent-searches/',
  164. method: 'GET',
  165. body: [],
  166. });
  167. savedSearchesRequest = MockApiClient.addMockResponse({
  168. url: '/organizations/org-slug/searches/',
  169. body: [savedSearch],
  170. });
  171. issuesRequest = MockApiClient.addMockResponse({
  172. url: '/organizations/org-slug/issues/',
  173. body: [group],
  174. headers: {
  175. Link: DEFAULT_LINKS_HEADER,
  176. },
  177. });
  178. });
  179. it('loads group rows with default query (no pinned queries, async and no query in URL)', async function () {
  180. render(<IssueListWithStores {...routerProps} />, {
  181. context: routerContext,
  182. });
  183. // Loading saved searches
  184. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  185. expect(savedSearchesRequest).toHaveBeenCalledTimes(1);
  186. await userEvent.click(await screen.findByRole('textbox'));
  187. // auxillary requests being made
  188. expect(recentSearchesRequest).toHaveBeenCalledTimes(1);
  189. expect(fetchTagsRequest).toHaveBeenCalledTimes(1);
  190. expect(fetchMembersRequest).toHaveBeenCalledTimes(1);
  191. // primary /issues/ request
  192. expect(issuesRequest).toHaveBeenCalledWith(
  193. expect.anything(),
  194. expect.objectContaining({
  195. // Should be called with default query
  196. data: expect.stringContaining('is%3Aunresolved'),
  197. })
  198. );
  199. expect(screen.getByRole('textbox')).toHaveValue('is:unresolved ');
  200. expect(screen.getByRole('button', {name: /custom search/i})).toBeInTheDocument();
  201. });
  202. it('loads with query in URL and pinned queries', async function () {
  203. savedSearchesRequest = MockApiClient.addMockResponse({
  204. url: '/organizations/org-slug/searches/',
  205. body: [
  206. savedSearch,
  207. Search({
  208. id: '123',
  209. name: 'My Pinned Search',
  210. isPinned: true,
  211. query: 'is:resolved',
  212. }),
  213. ],
  214. });
  215. const location = TestStubs.location({query: {query: 'level:foo'}});
  216. render(<IssueListWithStores {...merge({}, routerProps, {location})} />, {
  217. context: routerContext,
  218. router: {location},
  219. });
  220. await waitFor(() => {
  221. // Main /issues/ request
  222. expect(issuesRequest).toHaveBeenCalledWith(
  223. expect.anything(),
  224. expect.objectContaining({
  225. // Should be called with default query
  226. data: expect.stringContaining('level%3Afoo'),
  227. })
  228. );
  229. });
  230. expect(screen.getByRole('textbox')).toHaveValue('level:foo ');
  231. // Tab shows "custom search"
  232. expect(screen.getByRole('button', {name: 'Custom Search'})).toBeInTheDocument();
  233. });
  234. it('loads with a pinned custom query', async function () {
  235. savedSearchesRequest = MockApiClient.addMockResponse({
  236. url: '/organizations/org-slug/searches/',
  237. body: [
  238. savedSearch,
  239. Search({
  240. id: '123',
  241. name: 'My Pinned Search',
  242. isPinned: true,
  243. isGlobal: false,
  244. query: 'is:resolved',
  245. }),
  246. ],
  247. });
  248. render(<IssueListWithStores {...routerProps} />, {
  249. context: routerContext,
  250. });
  251. await waitFor(() => {
  252. expect(issuesRequest).toHaveBeenCalledWith(
  253. expect.anything(),
  254. expect.objectContaining({
  255. // Should be called with default query
  256. data: expect.stringContaining('is%3Aresolved'),
  257. })
  258. );
  259. });
  260. expect(screen.getByRole('textbox')).toHaveValue('is:resolved ');
  261. // Organization saved search selector should have default saved search selected
  262. expect(screen.getByRole('button', {name: 'My Default Search'})).toBeInTheDocument();
  263. });
  264. it('shows archived tab', async function () {
  265. render(
  266. <IssueListWithStores
  267. {...routerProps}
  268. organization={{...organization, features: ['escalating-issues']}}
  269. />,
  270. {
  271. context: routerContext,
  272. }
  273. );
  274. await waitFor(() => {
  275. expect(issuesRequest).toHaveBeenCalled();
  276. });
  277. expect(screen.getByRole('textbox')).toHaveValue('is:unresolved ');
  278. // TODO(workflow): remove this test when we remove the feature flag
  279. expect(screen.getByRole('tab', {name: 'Archived'})).toBeInTheDocument();
  280. });
  281. it('loads with a saved query', async function () {
  282. savedSearchesRequest = MockApiClient.addMockResponse({
  283. url: '/organizations/org-slug/searches/',
  284. body: [
  285. Search({
  286. id: '123',
  287. name: 'Assigned to Me',
  288. isPinned: false,
  289. isGlobal: true,
  290. query: 'assigned:me',
  291. sort: 'priority',
  292. type: 0,
  293. }),
  294. ],
  295. });
  296. const localRouter = {params: {searchId: '123'}};
  297. render(<IssueListWithStores {...merge({}, routerProps, localRouter)} />, {
  298. context: routerContext,
  299. router: localRouter,
  300. });
  301. await waitFor(() => {
  302. expect(issuesRequest).toHaveBeenCalledWith(
  303. expect.anything(),
  304. expect.objectContaining({
  305. // Should be called with default query
  306. data:
  307. expect.stringContaining('assigned%3Ame') &&
  308. expect.stringContaining('sort=priority'),
  309. })
  310. );
  311. });
  312. expect(screen.getByRole('textbox')).toHaveValue('assigned:me ');
  313. // Organization saved search selector should have default saved search selected
  314. expect(screen.getByRole('button', {name: 'Assigned to Me'})).toBeInTheDocument();
  315. });
  316. it('loads with a query in URL', async function () {
  317. savedSearchesRequest = MockApiClient.addMockResponse({
  318. url: '/organizations/org-slug/searches/',
  319. body: [
  320. Search({
  321. id: '123',
  322. name: 'Assigned to Me',
  323. isPinned: false,
  324. isGlobal: true,
  325. query: 'assigned:me',
  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. 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. 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. sort: '',
  425. query: 'dogs',
  426. statsPeriod: '14d',
  427. },
  428. })
  429. );
  430. });
  431. it('pins a custom query', async function () {
  432. const pinnedSearch = {
  433. id: '666',
  434. name: 'My Pinned Search',
  435. query: 'assigned:me level:fatal',
  436. sort: 'date',
  437. isPinned: true,
  438. visibility: SavedSearchVisibility.ORGANIZATION,
  439. };
  440. savedSearchesRequest = MockApiClient.addMockResponse({
  441. url: '/organizations/org-slug/searches/',
  442. body: [savedSearch],
  443. });
  444. const {rerender} = render(<IssueListWithStores {...routerProps} />, {
  445. context: routerContext,
  446. });
  447. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  448. await userEvent.clear(screen.getByRole('textbox'));
  449. await userEvent.type(screen.getByRole('textbox'), 'assigned:me level:fatal{enter}');
  450. expect((browserHistory.push as jest.Mock).mock.calls[0][0]).toEqual(
  451. expect.objectContaining({
  452. query: expect.objectContaining({
  453. query: 'assigned:me level:fatal',
  454. }),
  455. })
  456. );
  457. await tick();
  458. const routerWithQuery = {location: {query: {query: 'assigned:me level:fatal'}}};
  459. rerender(<IssueListWithStores {...merge({}, routerProps, routerWithQuery)} />);
  460. expect(screen.getByRole('button', {name: 'Custom Search'})).toBeInTheDocument();
  461. MockApiClient.clearMockResponses();
  462. const createPin = MockApiClient.addMockResponse({
  463. url: '/organizations/org-slug/pinned-searches/',
  464. method: 'PUT',
  465. body: pinnedSearch,
  466. });
  467. MockApiClient.addMockResponse({
  468. url: '/organizations/org-slug/searches/',
  469. body: [savedSearch, pinnedSearch],
  470. });
  471. await userEvent.click(screen.getByLabelText(/Set as Default/i));
  472. await waitFor(() => {
  473. expect(createPin).toHaveBeenCalled();
  474. expect(browserHistory.replace).toHaveBeenLastCalledWith(
  475. expect.objectContaining({
  476. pathname: '/organizations/org-slug/issues/searches/666/',
  477. query: {
  478. referrer: 'search-bar',
  479. },
  480. search: '',
  481. })
  482. );
  483. });
  484. });
  485. it('unpins a custom query', async function () {
  486. const pinnedSearch = Search({
  487. id: '666',
  488. name: 'My Pinned Search',
  489. query: 'assigned:me level:fatal',
  490. sort: 'date',
  491. isPinned: true,
  492. visibility: SavedSearchVisibility.ORGANIZATION,
  493. });
  494. savedSearchesRequest = MockApiClient.addMockResponse({
  495. url: '/organizations/org-slug/searches/',
  496. body: [pinnedSearch],
  497. });
  498. const deletePin = MockApiClient.addMockResponse({
  499. url: '/organizations/org-slug/pinned-searches/',
  500. method: 'DELETE',
  501. });
  502. const routerWithSavedSearch = {
  503. params: {searchId: pinnedSearch.id},
  504. };
  505. render(<IssueListWithStores {...merge({}, routerProps, routerWithSavedSearch)} />, {
  506. context: routerContext,
  507. router: routerWithSavedSearch,
  508. });
  509. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  510. expect(screen.getByRole('button', {name: 'My Default Search'})).toBeInTheDocument();
  511. await userEvent.click(screen.getByLabelText(/Remove Default/i));
  512. await waitFor(() => {
  513. expect(deletePin).toHaveBeenCalled();
  514. });
  515. await waitFor(() => {
  516. expect(browserHistory.replace).toHaveBeenLastCalledWith(
  517. expect.objectContaining({
  518. pathname: '/organizations/org-slug/issues/',
  519. })
  520. );
  521. });
  522. });
  523. it('pins a saved query', async function () {
  524. const assignedToMe = Search({
  525. id: '234',
  526. name: 'Assigned to Me',
  527. isPinned: false,
  528. isGlobal: true,
  529. query: 'assigned:me',
  530. sort: 'date',
  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.Project({
  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. });