overview.spec.jsx 41 KB

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