overview.spec.tsx 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433
  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.findByRole('textbox'));
  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.getByRole('textbox')).toHaveValue('is:unresolved ');
  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.getByRole('textbox')).toHaveValue('level:foo ');
  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.getByRole('textbox')).toHaveValue('is:resolved ');
  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.getByRole('textbox')).toHaveValue('is:unresolved ');
  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.getByRole('textbox')).toHaveValue('assigned:me ');
  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.getByRole('textbox')).toHaveValue('level:error ');
  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.getByRole('textbox')).toHaveValue('is:resolved ');
  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. await userEvent.clear(screen.getByRole('textbox'));
  417. await userEvent.type(screen.getByRole('textbox'), 'dogs{enter}');
  418. expect(browserHistory.push).toHaveBeenLastCalledWith(
  419. expect.objectContaining({
  420. pathname: '/organizations/org-slug/issues/',
  421. query: {
  422. environment: [],
  423. project: [],
  424. referrer: 'issue-list',
  425. sort: '',
  426. query: 'dogs',
  427. statsPeriod: '14d',
  428. },
  429. })
  430. );
  431. });
  432. it('pins a custom query', async function () {
  433. const pinnedSearch = {
  434. id: '666',
  435. name: 'My Pinned Search',
  436. query: 'assigned:me level:fatal',
  437. sort: 'date',
  438. isPinned: true,
  439. visibility: SavedSearchVisibility.ORGANIZATION,
  440. };
  441. savedSearchesRequest = MockApiClient.addMockResponse({
  442. url: '/organizations/org-slug/searches/',
  443. body: [savedSearch],
  444. });
  445. const {rerender} = render(<IssueListWithStores {...routerProps} />, {
  446. context: routerContext,
  447. });
  448. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  449. await userEvent.clear(screen.getByRole('textbox'));
  450. await userEvent.type(screen.getByRole('textbox'), 'assigned:me level:fatal{enter}');
  451. expect((browserHistory.push as jest.Mock).mock.calls[0][0]).toEqual(
  452. expect.objectContaining({
  453. query: expect.objectContaining({
  454. query: 'assigned:me level:fatal',
  455. }),
  456. })
  457. );
  458. await tick();
  459. const routerWithQuery = {location: {query: {query: 'assigned:me level:fatal'}}};
  460. rerender(<IssueListWithStores {...merge({}, routerProps, routerWithQuery)} />);
  461. expect(screen.getByRole('button', {name: 'Custom Search'})).toBeInTheDocument();
  462. MockApiClient.clearMockResponses();
  463. const createPin = MockApiClient.addMockResponse({
  464. url: '/organizations/org-slug/pinned-searches/',
  465. method: 'PUT',
  466. body: pinnedSearch,
  467. });
  468. MockApiClient.addMockResponse({
  469. url: '/organizations/org-slug/searches/',
  470. body: [savedSearch, pinnedSearch],
  471. });
  472. await userEvent.click(screen.getByLabelText(/Set as Default/i));
  473. await waitFor(() => {
  474. expect(createPin).toHaveBeenCalled();
  475. expect(browserHistory.replace).toHaveBeenLastCalledWith(
  476. expect.objectContaining({
  477. pathname: '/organizations/org-slug/issues/searches/666/',
  478. query: {
  479. referrer: 'search-bar',
  480. },
  481. search: '',
  482. })
  483. );
  484. });
  485. });
  486. it('unpins a custom query', async function () {
  487. const pinnedSearch = Search({
  488. id: '666',
  489. name: 'My Pinned Search',
  490. query: 'assigned:me level:fatal',
  491. sort: 'date',
  492. isPinned: true,
  493. visibility: SavedSearchVisibility.ORGANIZATION,
  494. });
  495. savedSearchesRequest = MockApiClient.addMockResponse({
  496. url: '/organizations/org-slug/searches/',
  497. body: [pinnedSearch],
  498. });
  499. const deletePin = MockApiClient.addMockResponse({
  500. url: '/organizations/org-slug/pinned-searches/',
  501. method: 'DELETE',
  502. });
  503. const routerWithSavedSearch = {
  504. params: {searchId: pinnedSearch.id},
  505. };
  506. render(<IssueListWithStores {...merge({}, routerProps, routerWithSavedSearch)} />, {
  507. context: routerContext,
  508. router: routerWithSavedSearch,
  509. });
  510. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  511. expect(screen.getByRole('button', {name: 'My Default Search'})).toBeInTheDocument();
  512. await userEvent.click(screen.getByLabelText(/Remove Default/i));
  513. await waitFor(() => {
  514. expect(deletePin).toHaveBeenCalled();
  515. });
  516. await waitFor(() => {
  517. expect(browserHistory.replace).toHaveBeenLastCalledWith(
  518. expect.objectContaining({
  519. pathname: '/organizations/org-slug/issues/',
  520. })
  521. );
  522. });
  523. });
  524. it('pins a saved query', async function () {
  525. const assignedToMe = Search({
  526. id: '234',
  527. name: 'Assigned to Me',
  528. isPinned: false,
  529. isGlobal: true,
  530. query: 'assigned:me',
  531. sort: 'date',
  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: 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: 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: 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: 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: 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.Project({
  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. });