overview.spec.tsx 42 KB

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