overview.spec.jsx 42 KB

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