overview.spec.tsx 42 KB

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