overview.spec.jsx 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901
  1. import {browserHistory} from 'react-router';
  2. import cloneDeep from 'lodash/cloneDeep';
  3. import range from 'lodash/range';
  4. import {mountWithTheme, shallow} from 'sentry-test/enzyme';
  5. import {initializeOrg} from 'sentry-test/initializeOrg';
  6. import {act} from 'sentry-test/reactTestingLibrary';
  7. import {triggerPress} from 'sentry-test/utils';
  8. import StreamGroup from 'sentry/components/stream/group';
  9. import GroupStore from 'sentry/stores/groupStore';
  10. import ProjectsStore from 'sentry/stores/projectsStore';
  11. import TagStore from 'sentry/stores/tagStore';
  12. import * as parseLinkHeader from 'sentry/utils/parseLinkHeader';
  13. import IssueListWithStores, {IssueListOverview} from 'sentry/views/issueList/overview';
  14. import {OrganizationContext} from 'sentry/views/organizationContext';
  15. // Mock <IssueListSidebar> and <IssueListActions>
  16. jest.mock('sentry/views/issueList/sidebar', () => jest.fn(() => null));
  17. jest.mock('sentry/views/issueList/actions', () => jest.fn(() => null));
  18. jest.mock('sentry/components/stream/group', () => jest.fn(() => null));
  19. jest.mock('sentry/views/issueList/noGroupsHandler/congratsRobots', () =>
  20. jest.fn(() => null)
  21. );
  22. const DEFAULT_LINKS_HEADER =
  23. '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575731:0:1>; rel="previous"; results="false"; cursor="1443575731:0:1", ' +
  24. '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575000:0:0>; rel="next"; results="true"; cursor="1443575000:0:0"';
  25. describe('IssueList', function () {
  26. let wrapper;
  27. let props;
  28. let organization;
  29. let project;
  30. let group;
  31. let groupStats;
  32. let savedSearch;
  33. let mountWithThemeAndOrg;
  34. let fetchTagsRequest;
  35. let fetchMembersRequest;
  36. const api = new MockApiClient();
  37. const parseLinkHeaderSpy = jest.spyOn(parseLinkHeader, 'default');
  38. beforeEach(function () {
  39. // The tests fail because we have a "component update was not wrapped in act" error.
  40. // It should be safe to ignore this error, but we should remove the mock once we move to react testing library
  41. // eslint-disable-next-line no-console
  42. console.error = jest.fn();
  43. MockApiClient.clearMockResponses();
  44. project = TestStubs.ProjectDetails({
  45. id: '3559',
  46. name: 'Foo Project',
  47. slug: 'project-slug',
  48. firstEvent: true,
  49. });
  50. organization = TestStubs.Organization({
  51. id: '1337',
  52. slug: 'org-slug',
  53. access: ['releases'],
  54. features: [],
  55. projects: [project],
  56. });
  57. savedSearch = TestStubs.Search({
  58. id: '789',
  59. query: 'is:unresolved TypeError',
  60. sort: 'date',
  61. name: 'Unresolved TypeErrors',
  62. projectId: project.id,
  63. });
  64. group = TestStubs.Group({project});
  65. MockApiClient.addMockResponse({
  66. url: '/organizations/org-slug/issues/',
  67. body: [group],
  68. headers: {
  69. Link: DEFAULT_LINKS_HEADER,
  70. },
  71. });
  72. groupStats = TestStubs.GroupStats();
  73. MockApiClient.addMockResponse({
  74. url: '/organizations/org-slug/issues-stats/',
  75. body: [groupStats],
  76. });
  77. MockApiClient.addMockResponse({
  78. url: '/organizations/org-slug/searches/',
  79. body: [savedSearch],
  80. });
  81. MockApiClient.addMockResponse({
  82. url: '/organizations/org-slug/recent-searches/',
  83. body: [],
  84. });
  85. MockApiClient.addMockResponse({
  86. url: '/organizations/org-slug/recent-searches/',
  87. method: 'POST',
  88. body: [],
  89. });
  90. MockApiClient.addMockResponse({
  91. url: '/organizations/org-slug/issues-count/',
  92. method: 'GET',
  93. body: [{}],
  94. });
  95. MockApiClient.addMockResponse({
  96. url: '/organizations/org-slug/processingissues/',
  97. method: 'GET',
  98. body: [
  99. {
  100. project: 'test-project',
  101. numIssues: 1,
  102. hasIssues: true,
  103. lastSeen: '2019-01-16T15:39:11.081Z',
  104. },
  105. ],
  106. });
  107. const tags = TestStubs.Tags();
  108. fetchTagsRequest = MockApiClient.addMockResponse({
  109. url: '/organizations/org-slug/tags/',
  110. method: 'GET',
  111. body: tags,
  112. });
  113. fetchMembersRequest = MockApiClient.addMockResponse({
  114. url: '/organizations/org-slug/users/',
  115. method: 'GET',
  116. body: [TestStubs.Member({projects: [project.slug]})],
  117. });
  118. MockApiClient.addMockResponse({
  119. url: '/organizations/org-slug/sent-first-event/',
  120. body: {sentFirstEvent: true},
  121. });
  122. MockApiClient.addMockResponse({
  123. url: '/organizations/org-slug/projects/',
  124. body: [project],
  125. });
  126. TagStore.init();
  127. mountWithThemeAndOrg = (component, opts) =>
  128. mountWithTheme(component, {
  129. ...opts,
  130. wrappingComponent: ({children}) => (
  131. <OrganizationContext.Provider value={organization}>
  132. {children}
  133. </OrganizationContext.Provider>
  134. ),
  135. });
  136. props = {
  137. api,
  138. savedSearchLoading: false,
  139. savedSearches: [savedSearch],
  140. useOrgSavedSearches: true,
  141. selection: {
  142. projects: [parseInt(organization.projects[0].id, 10)],
  143. environments: [],
  144. datetime: {period: '14d'},
  145. },
  146. location: {query: {query: 'is:unresolved'}, search: 'query=is:unresolved'},
  147. params: {orgId: organization.slug},
  148. organization,
  149. tags: tags.reduce((acc, tag) => {
  150. acc[tag.key] = tag;
  151. return acc;
  152. }),
  153. };
  154. });
  155. afterEach(function () {
  156. jest.clearAllMocks();
  157. MockApiClient.clearMockResponses();
  158. if (wrapper) {
  159. wrapper.unmount();
  160. }
  161. wrapper = null;
  162. TagStore.teardown();
  163. });
  164. describe('withStores and feature flags', function () {
  165. const {router, routerContext} = initializeOrg({
  166. organization: {
  167. features: ['global-views'],
  168. slug: 'org-slug',
  169. },
  170. router: {
  171. location: {query: {}, search: ''},
  172. params: {orgId: 'org-slug'},
  173. },
  174. });
  175. const defaultProps = {};
  176. let savedSearchesRequest;
  177. let recentSearchesRequest;
  178. let issuesRequest;
  179. /* helpers */
  180. const getSavedSearchTitle = w => w.find('SavedSearchTab ButtonLabel').text().trim();
  181. const getSearchBarValue = w =>
  182. w.find('SmartSearchBarContainer textarea').prop('value').trim();
  183. const createWrapper = ({params, location, ...p} = {}) => {
  184. const newRouter = {
  185. ...router,
  186. params: {
  187. ...router.params,
  188. ...params,
  189. },
  190. location: {
  191. ...router.location,
  192. ...location,
  193. },
  194. };
  195. wrapper = mountWithThemeAndOrg(
  196. <IssueListWithStores {...newRouter} {...defaultProps} {...p} />,
  197. routerContext
  198. );
  199. };
  200. beforeEach(function () {
  201. StreamGroup.mockClear();
  202. recentSearchesRequest = MockApiClient.addMockResponse({
  203. url: '/organizations/org-slug/recent-searches/',
  204. method: 'GET',
  205. body: [],
  206. });
  207. savedSearchesRequest = MockApiClient.addMockResponse({
  208. url: '/organizations/org-slug/searches/',
  209. body: [savedSearch],
  210. });
  211. issuesRequest = MockApiClient.addMockResponse({
  212. url: '/organizations/org-slug/issues/',
  213. body: [group],
  214. headers: {
  215. Link: DEFAULT_LINKS_HEADER,
  216. },
  217. });
  218. });
  219. it('loads group rows with default query (no pinned queries, and no query in URL)', async function () {
  220. createWrapper();
  221. // Loading saved searches
  222. expect(savedSearchesRequest).toHaveBeenCalledTimes(1);
  223. // Update stores with saved searches
  224. await tick();
  225. await tick();
  226. wrapper.update();
  227. // auxillary requests being made
  228. expect(recentSearchesRequest).toHaveBeenCalledTimes(1);
  229. expect(fetchTagsRequest).toHaveBeenCalledTimes(1);
  230. expect(fetchMembersRequest).toHaveBeenCalledTimes(1);
  231. // primary /issues/ request
  232. expect(issuesRequest).toHaveBeenCalledWith(
  233. expect.anything(),
  234. expect.objectContaining({
  235. // Should be called with default query
  236. data: expect.stringContaining('is%3Aunresolved'),
  237. })
  238. );
  239. expect(getSearchBarValue(wrapper)).toBe('is:unresolved');
  240. // Saved search not active since is:unresolved is a tab
  241. expect(getSavedSearchTitle(wrapper)).toBe('Saved Searches');
  242. // This is mocked
  243. expect(StreamGroup).toHaveBeenCalled();
  244. });
  245. it('loads with query in URL and pinned queries', async function () {
  246. savedSearchesRequest = MockApiClient.addMockResponse({
  247. url: '/organizations/org-slug/searches/',
  248. body: [
  249. savedSearch,
  250. TestStubs.Search({
  251. id: '123',
  252. name: 'My Pinned Search',
  253. isPinned: true,
  254. query: 'is:resolved',
  255. }),
  256. ],
  257. });
  258. createWrapper({
  259. location: {
  260. query: {
  261. query: 'level:foo',
  262. },
  263. },
  264. });
  265. // Update stores with saved searches
  266. await tick();
  267. await tick();
  268. wrapper.update();
  269. // Main /issues/ request
  270. expect(issuesRequest).toHaveBeenCalledWith(
  271. expect.anything(),
  272. expect.objectContaining({
  273. // Should be called with default query
  274. data: expect.stringContaining('level%3Afoo'),
  275. })
  276. );
  277. expect(getSearchBarValue(wrapper)).toBe('level:foo');
  278. // Custom search
  279. expect(getSavedSearchTitle(wrapper)).toBe('Custom Search');
  280. });
  281. it('loads with a pinned saved query', async function () {
  282. savedSearchesRequest = MockApiClient.addMockResponse({
  283. url: '/organizations/org-slug/searches/',
  284. body: [
  285. savedSearch,
  286. TestStubs.Search({
  287. id: '123',
  288. name: 'Org Custom',
  289. isPinned: true,
  290. isGlobal: false,
  291. isOrgCustom: true,
  292. query: 'is:resolved',
  293. }),
  294. ],
  295. });
  296. createWrapper();
  297. await tick();
  298. await tick();
  299. wrapper.update();
  300. expect(issuesRequest).toHaveBeenCalledWith(
  301. expect.anything(),
  302. expect.objectContaining({
  303. // Should be called with default query
  304. data: expect.stringContaining('is%3Aresolved'),
  305. })
  306. );
  307. expect(getSearchBarValue(wrapper)).toBe('is:resolved');
  308. // Organization saved search selector should have default saved search selected
  309. expect(getSavedSearchTitle(wrapper)).toBe('Org Custom');
  310. });
  311. it('loads with a pinned custom query', async function () {
  312. savedSearchesRequest = MockApiClient.addMockResponse({
  313. url: '/organizations/org-slug/searches/',
  314. body: [
  315. savedSearch,
  316. TestStubs.Search({
  317. id: '123',
  318. name: 'My Pinned Search',
  319. isPinned: true,
  320. isGlobal: false,
  321. isOrgCustom: false,
  322. query: 'is:resolved',
  323. }),
  324. ],
  325. });
  326. createWrapper();
  327. await tick();
  328. await tick();
  329. wrapper.update();
  330. expect(issuesRequest).toHaveBeenCalledWith(
  331. expect.anything(),
  332. expect.objectContaining({
  333. // Should be called with default query
  334. data: expect.stringContaining('is%3Aresolved'),
  335. })
  336. );
  337. expect(getSearchBarValue(wrapper)).toBe('is:resolved');
  338. // Organization saved search selector should have default saved search selected
  339. expect(getSavedSearchTitle(wrapper)).toBe('My Pinned Search');
  340. });
  341. it('loads with a saved query', async function () {
  342. savedSearchesRequest = MockApiClient.addMockResponse({
  343. url: '/organizations/org-slug/searches/',
  344. body: [
  345. TestStubs.Search({
  346. id: '123',
  347. name: 'Assigned to Me',
  348. isPinned: false,
  349. isGlobal: true,
  350. query: 'assigned:me',
  351. sort: 'priority',
  352. projectId: null,
  353. type: 0,
  354. }),
  355. ],
  356. });
  357. createWrapper({params: {searchId: '123'}});
  358. await tick();
  359. await tick();
  360. wrapper.update();
  361. expect(issuesRequest).toHaveBeenCalledWith(
  362. expect.anything(),
  363. expect.objectContaining({
  364. // Should be called with default query
  365. data:
  366. expect.stringContaining('assigned%3Ame') &&
  367. expect.stringContaining('sort=priority'),
  368. })
  369. );
  370. expect(getSearchBarValue(wrapper)).toBe('assigned:me');
  371. // Organization saved search selector should have default saved search selected
  372. expect(getSavedSearchTitle(wrapper)).toBe('Assigned to Me');
  373. });
  374. it('loads with a query in URL', async function () {
  375. savedSearchesRequest = MockApiClient.addMockResponse({
  376. url: '/organizations/org-slug/searches/',
  377. body: [
  378. TestStubs.Search({
  379. id: '123',
  380. name: 'Assigned to Me',
  381. isPinned: false,
  382. isGlobal: true,
  383. query: 'assigned:me',
  384. projectId: null,
  385. type: 0,
  386. }),
  387. ],
  388. });
  389. createWrapper({location: {query: {query: 'level:error'}}});
  390. await tick();
  391. await tick();
  392. wrapper.update();
  393. expect(issuesRequest).toHaveBeenCalledWith(
  394. expect.anything(),
  395. expect.objectContaining({
  396. // Should be called with default query
  397. data: expect.stringContaining('level%3Aerror'),
  398. })
  399. );
  400. expect(getSearchBarValue(wrapper)).toBe('level:error');
  401. // Organization saved search selector should have default saved search selected
  402. expect(getSavedSearchTitle(wrapper)).toBe('Custom Search');
  403. });
  404. it('loads with an empty query in URL', async function () {
  405. savedSearchesRequest = MockApiClient.addMockResponse({
  406. url: '/organizations/org-slug/searches/',
  407. body: [
  408. TestStubs.Search({
  409. id: '123',
  410. name: 'My Pinned Search',
  411. isPinned: true,
  412. isGlobal: false,
  413. isOrgCustom: false,
  414. query: 'is:resolved',
  415. }),
  416. ],
  417. });
  418. createWrapper({location: {query: {query: undefined}}});
  419. await tick();
  420. await tick();
  421. wrapper.update();
  422. expect(issuesRequest).toHaveBeenCalledWith(
  423. expect.anything(),
  424. expect.objectContaining({
  425. // Should be called with empty query
  426. data: expect.stringContaining(''),
  427. })
  428. );
  429. expect(getSearchBarValue(wrapper)).toBe('is:resolved');
  430. // Organization saved search selector should have default saved search selected
  431. expect(getSavedSearchTitle(wrapper)).toBe('My Pinned Search');
  432. });
  433. it('selects a saved search', async function () {
  434. const localSavedSearch = {...savedSearch, projectId: null};
  435. savedSearchesRequest = MockApiClient.addMockResponse({
  436. url: '/organizations/org-slug/searches/',
  437. body: [localSavedSearch],
  438. });
  439. createWrapper();
  440. await tick();
  441. await tick();
  442. wrapper.update();
  443. await act(async () => {
  444. triggerPress(wrapper.find('SavedSearchTab StyledDropdownTrigger'));
  445. await tick();
  446. wrapper.update();
  447. });
  448. wrapper.find('SelectOption').last().simulate('click');
  449. expect(browserHistory.push).toHaveBeenLastCalledWith(
  450. expect.objectContaining({
  451. pathname: '/organizations/org-slug/issues/searches/789/',
  452. })
  453. );
  454. });
  455. it('clears a saved search when a custom one is entered', async function () {
  456. savedSearchesRequest = MockApiClient.addMockResponse({
  457. url: '/organizations/org-slug/searches/',
  458. body: [
  459. savedSearch,
  460. TestStubs.Search({
  461. id: '123',
  462. name: 'Pinned search',
  463. isPinned: true,
  464. isGlobal: false,
  465. isOrgCustom: true,
  466. query: 'is:resolved',
  467. }),
  468. ],
  469. });
  470. createWrapper();
  471. await tick();
  472. await tick();
  473. wrapper.update();
  474. // Update the search textarea
  475. wrapper
  476. .find('IssueListFilters SmartSearchBar textarea')
  477. .simulate('change', {target: {value: 'dogs'}});
  478. // Submit the form
  479. wrapper.find('IssueListFilters SmartSearchBar form').simulate('submit');
  480. wrapper.update();
  481. expect(browserHistory.push).toHaveBeenLastCalledWith(
  482. expect.objectContaining({
  483. pathname: '/organizations/org-slug/issues/',
  484. query: {
  485. environment: [],
  486. project: [],
  487. query: 'dogs',
  488. statsPeriod: '14d',
  489. },
  490. })
  491. );
  492. });
  493. it('pins and unpins a custom query', async function () {
  494. savedSearchesRequest = MockApiClient.addMockResponse({
  495. url: '/organizations/org-slug/searches/',
  496. body: [savedSearch],
  497. });
  498. createWrapper();
  499. await tick();
  500. await tick();
  501. wrapper.update();
  502. const createPin = MockApiClient.addMockResponse({
  503. url: '/organizations/org-slug/pinned-searches/',
  504. method: 'PUT',
  505. body: {
  506. ...savedSearch,
  507. id: '666',
  508. name: 'My Pinned Search',
  509. query: 'assigned:me level:fatal',
  510. sort: 'date',
  511. isPinned: true,
  512. },
  513. });
  514. const deletePin = MockApiClient.addMockResponse({
  515. url: '/organizations/org-slug/pinned-searches/',
  516. method: 'DELETE',
  517. });
  518. wrapper
  519. .find('SmartSearchBar textarea')
  520. .simulate('change', {target: {value: 'assigned:me level:fatal'}});
  521. wrapper.find('SmartSearchBar form').simulate('submit');
  522. expect(browserHistory.push.mock.calls[0][0]).toEqual(
  523. expect.objectContaining({
  524. query: expect.objectContaining({
  525. query: 'assigned:me level:fatal',
  526. }),
  527. })
  528. );
  529. await tick();
  530. wrapper.setProps({
  531. location: {
  532. ...router.location,
  533. query: {
  534. query: 'assigned:me level:fatal',
  535. },
  536. },
  537. });
  538. expect(getSavedSearchTitle(wrapper)).toBe('Custom Search');
  539. wrapper.find('Button[aria-label="Pin this search"] button').simulate('click');
  540. expect(createPin).toHaveBeenCalled();
  541. await tick();
  542. wrapper.update();
  543. expect(browserHistory.push).toHaveBeenLastCalledWith(
  544. expect.objectContaining({
  545. pathname: '/organizations/org-slug/issues/searches/666/',
  546. query: {},
  547. search: '',
  548. })
  549. );
  550. wrapper.setProps({
  551. params: {
  552. ...router.params,
  553. searchId: '666',
  554. },
  555. });
  556. await tick();
  557. wrapper.update();
  558. expect(getSavedSearchTitle(wrapper)).toBe('My Pinned Search');
  559. wrapper.find('Button[aria-label="Unpin this search"] button').simulate('click');
  560. expect(deletePin).toHaveBeenCalled();
  561. await tick();
  562. wrapper.update();
  563. expect(browserHistory.push).toHaveBeenLastCalledWith(
  564. expect.objectContaining({
  565. pathname: '/organizations/org-slug/issues/',
  566. query: {
  567. query: 'assigned:me level:fatal',
  568. sort: 'date',
  569. },
  570. })
  571. );
  572. });
  573. it('pins and unpins a saved query', async function () {
  574. const assignedToMe = TestStubs.Search({
  575. id: '234',
  576. name: 'Assigned to Me',
  577. isPinned: false,
  578. isGlobal: true,
  579. query: 'assigned:me',
  580. sort: 'date',
  581. projectId: null,
  582. type: 0,
  583. });
  584. savedSearchesRequest = MockApiClient.addMockResponse({
  585. url: '/organizations/org-slug/searches/',
  586. body: [savedSearch, assignedToMe],
  587. });
  588. createWrapper();
  589. await tick();
  590. await tick();
  591. wrapper.update();
  592. let createPin = MockApiClient.addMockResponse({
  593. url: '/organizations/org-slug/pinned-searches/',
  594. method: 'PUT',
  595. body: {
  596. ...savedSearch,
  597. isPinned: true,
  598. },
  599. });
  600. await act(async () => {
  601. triggerPress(wrapper.find('SavedSearchTab StyledDropdownTrigger'));
  602. await tick();
  603. wrapper.update();
  604. });
  605. wrapper.find('SelectOption').first().simulate('click');
  606. await tick();
  607. expect(browserHistory.push).toHaveBeenLastCalledWith(
  608. expect.objectContaining({
  609. pathname: '/organizations/org-slug/issues/searches/789/',
  610. query: {
  611. environment: [],
  612. project: ['3559'],
  613. statsPeriod: '14d',
  614. sort: 'date',
  615. },
  616. })
  617. );
  618. wrapper.setProps({
  619. params: {
  620. ...router.params,
  621. searchId: '789',
  622. },
  623. });
  624. expect(getSavedSearchTitle(wrapper)).toBe('Unresolved TypeErrors');
  625. wrapper.find('Button[aria-label="Pin this search"] button').simulate('click');
  626. expect(createPin).toHaveBeenCalled();
  627. await tick();
  628. wrapper.update();
  629. expect(browserHistory.push).toHaveBeenLastCalledWith(
  630. expect.objectContaining({
  631. pathname: '/organizations/org-slug/issues/searches/789/',
  632. })
  633. );
  634. wrapper.setProps({
  635. params: {
  636. ...router.params,
  637. searchId: '789',
  638. },
  639. });
  640. await tick();
  641. wrapper.update();
  642. expect(getSavedSearchTitle(wrapper)).toBe('Unresolved TypeErrors');
  643. // Select other saved search
  644. await act(async () => {
  645. triggerPress(wrapper.find('SavedSearchTab StyledDropdownTrigger'));
  646. await tick();
  647. wrapper.update();
  648. });
  649. wrapper.find('SelectOption').last().simulate('click');
  650. expect(browserHistory.push).toHaveBeenLastCalledWith(
  651. expect.objectContaining({
  652. pathname: '/organizations/org-slug/issues/searches/234/',
  653. query: {
  654. project: [],
  655. environment: [],
  656. statsPeriod: '14d',
  657. sort: 'date',
  658. },
  659. })
  660. );
  661. wrapper.setProps({
  662. params: {
  663. ...router.params,
  664. searchId: '234',
  665. },
  666. });
  667. expect(getSavedSearchTitle(wrapper)).toBe('Assigned to Me');
  668. createPin = MockApiClient.addMockResponse({
  669. url: '/organizations/org-slug/pinned-searches/',
  670. method: 'PUT',
  671. body: {
  672. ...assignedToMe,
  673. isPinned: true,
  674. },
  675. });
  676. wrapper.find('Button[aria-label="Pin this search"] button').simulate('click');
  677. expect(createPin).toHaveBeenCalled();
  678. await tick();
  679. wrapper.update();
  680. expect(browserHistory.push).toHaveBeenLastCalledWith(
  681. expect.objectContaining({
  682. pathname: '/organizations/org-slug/issues/searches/234/',
  683. })
  684. );
  685. wrapper.setProps({
  686. params: {
  687. ...router.params,
  688. searchId: '234',
  689. },
  690. });
  691. await tick();
  692. wrapper.update();
  693. expect(getSavedSearchTitle(wrapper)).toBe('Assigned to Me');
  694. });
  695. it('pinning and unpinning searches should keep project selected', async function () {
  696. savedSearchesRequest = MockApiClient.addMockResponse({
  697. url: '/organizations/org-slug/searches/',
  698. body: [savedSearch],
  699. });
  700. createWrapper({
  701. selection: {
  702. projects: [123],
  703. environments: ['prod'],
  704. datetime: {},
  705. },
  706. location: {query: {project: ['123'], environment: ['prod']}},
  707. });
  708. await tick();
  709. await tick();
  710. wrapper.update();
  711. const deletePin = MockApiClient.addMockResponse({
  712. url: '/organizations/org-slug/pinned-searches/',
  713. method: 'DELETE',
  714. });
  715. const createPin = MockApiClient.addMockResponse({
  716. url: '/organizations/org-slug/pinned-searches/',
  717. method: 'PUT',
  718. body: {
  719. ...savedSearch,
  720. id: '666',
  721. name: 'My Pinned Search',
  722. query: 'assigned:me level:fatal',
  723. sort: 'date',
  724. isPinned: true,
  725. },
  726. });
  727. wrapper
  728. .find('SmartSearchBar textarea')
  729. .simulate('change', {target: {value: 'assigned:me level:fatal'}});
  730. wrapper.find('SmartSearchBar form').simulate('submit');
  731. await tick();
  732. expect(browserHistory.push).toHaveBeenLastCalledWith(
  733. expect.objectContaining({
  734. query: expect.objectContaining({
  735. project: [123],
  736. environment: ['prod'],
  737. query: 'assigned:me level:fatal',
  738. }),
  739. })
  740. );
  741. const newRouter = {
  742. ...router,
  743. location: {
  744. ...router.location,
  745. query: {
  746. ...router.location.query,
  747. project: [123],
  748. environment: ['prod'],
  749. query: 'assigned:me level:fatal',
  750. },
  751. },
  752. };
  753. wrapper.setProps({...newRouter, router: newRouter});
  754. wrapper.setContext({router: newRouter});
  755. wrapper.update();
  756. wrapper.find('Button[aria-label="Pin this search"] button').simulate('click');
  757. expect(createPin).toHaveBeenCalled();
  758. await tick();
  759. wrapper.update();
  760. expect(browserHistory.push).toHaveBeenLastCalledWith(
  761. expect.objectContaining({
  762. pathname: '/organizations/org-slug/issues/searches/666/',
  763. query: expect.objectContaining({
  764. project: [123],
  765. environment: ['prod'],
  766. query: 'assigned:me level:fatal',
  767. }),
  768. })
  769. );
  770. wrapper.setProps({
  771. params: {
  772. ...router.params,
  773. searchId: '666',
  774. },
  775. });
  776. await tick();
  777. wrapper.update();
  778. wrapper.find('Button[aria-label="Unpin this search"] button').simulate('click');
  779. expect(deletePin).toHaveBeenCalled();
  780. await tick();
  781. wrapper.update();
  782. expect(browserHistory.push).toHaveBeenLastCalledWith(
  783. expect.objectContaining({
  784. pathname: '/organizations/org-slug/issues/',
  785. query: expect.objectContaining({
  786. project: [123],
  787. environment: ['prod'],
  788. query: 'assigned:me level:fatal',
  789. }),
  790. })
  791. );
  792. });
  793. it.todo('saves a new query');
  794. it.todo('loads pinned search when invalid saved search id is accessed');
  795. it('does not allow pagination to "previous" while on first page and resets cursors when navigating back to initial page', async function () {
  796. let pushArgs;
  797. createWrapper();
  798. await tick();
  799. await tick();
  800. wrapper.update();
  801. expect(wrapper.find('Pagination Button').first().prop('disabled')).toBe(true);
  802. issuesRequest = MockApiClient.addMockResponse({
  803. url: '/organizations/org-slug/issues/',
  804. body: [group],
  805. headers: {
  806. 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"',
  807. },
  808. });
  809. // Click next
  810. wrapper.find('Pagination Button').last().simulate('click');
  811. await tick();
  812. pushArgs = {
  813. pathname: '/organizations/org-slug/issues/',
  814. query: {
  815. cursor: '1443575000:0:0',
  816. page: 1,
  817. environment: [],
  818. project: [],
  819. query: 'is:unresolved',
  820. statsPeriod: '14d',
  821. },
  822. };
  823. expect(browserHistory.push).toHaveBeenLastCalledWith(pushArgs);
  824. wrapper.setProps({location: pushArgs});
  825. expect(wrapper.find('Pagination Button').first().prop('disabled')).toBe(false);
  826. // Click next again
  827. wrapper.find('Pagination Button').last().simulate('click');
  828. await tick();
  829. pushArgs = {
  830. pathname: '/organizations/org-slug/issues/',
  831. query: {
  832. cursor: '1443574000:0:0',
  833. page: 2,
  834. environment: [],
  835. project: [],
  836. query: 'is:unresolved',
  837. statsPeriod: '14d',
  838. },
  839. };
  840. expect(browserHistory.push).toHaveBeenLastCalledWith(pushArgs);
  841. wrapper.setProps({location: pushArgs});
  842. // Click previous
  843. wrapper.find('Pagination Button').first().simulate('click');
  844. await tick();
  845. pushArgs = {
  846. pathname: '/organizations/org-slug/issues/',
  847. query: {
  848. cursor: '1443575000:0:1',
  849. page: 1,
  850. environment: [],
  851. project: [],
  852. query: 'is:unresolved',
  853. statsPeriod: '14d',
  854. },
  855. };
  856. expect(browserHistory.push).toHaveBeenLastCalledWith(pushArgs);
  857. wrapper.setProps({location: pushArgs});
  858. // Click previous back to initial page
  859. wrapper.find('Pagination Button').first().simulate('click');
  860. await tick();
  861. // cursor is undefined because "prev" cursor is === initial "next" cursor
  862. expect(browserHistory.push).toHaveBeenLastCalledWith({
  863. pathname: '/organizations/org-slug/issues/',
  864. query: {
  865. cursor: undefined,
  866. environment: [],
  867. page: undefined,
  868. project: [],
  869. query: 'is:unresolved',
  870. statsPeriod: '14d',
  871. },
  872. });
  873. });
  874. });
  875. describe('transitionTo', function () {
  876. let instance;
  877. beforeEach(function () {
  878. wrapper = shallow(<IssueListOverview {...props} />);
  879. instance = wrapper.instance();
  880. });
  881. it('transitions to query updates', function () {
  882. instance.transitionTo({query: 'is:ignored'});
  883. expect(browserHistory.push).toHaveBeenCalledWith({
  884. pathname: '/organizations/org-slug/issues/',
  885. query: {
  886. environment: [],
  887. project: [parseInt(project.id, 10)],
  888. query: 'is:ignored',
  889. statsPeriod: '14d',
  890. },
  891. });
  892. });
  893. it('transitions to cursor with project-less saved search', function () {
  894. savedSearch = {
  895. id: 123,
  896. projectId: null,
  897. query: 'foo:bar',
  898. };
  899. instance.transitionTo({cursor: '1554756114000:0:0'}, savedSearch);
  900. // should keep the current project selection as we're going to the next page.
  901. expect(browserHistory.push).toHaveBeenCalledWith({
  902. pathname: '/organizations/org-slug/issues/searches/123/',
  903. query: {
  904. environment: [],
  905. project: [parseInt(project.id, 10)],
  906. cursor: '1554756114000:0:0',
  907. statsPeriod: '14d',
  908. },
  909. });
  910. });
  911. it('transitions to cursor with project saved search', function () {
  912. savedSearch = {
  913. id: 123,
  914. projectId: 999,
  915. query: 'foo:bar',
  916. };
  917. instance.transitionTo({cursor: '1554756114000:0:0'}, savedSearch);
  918. // should keep the current project selection as we're going to the next page.
  919. expect(browserHistory.push).toHaveBeenCalledWith({
  920. pathname: '/organizations/org-slug/issues/searches/123/',
  921. query: {
  922. environment: [],
  923. project: [parseInt(project.id, 10)],
  924. cursor: '1554756114000:0:0',
  925. statsPeriod: '14d',
  926. },
  927. });
  928. });
  929. it('transitions to saved search that has a projectId', function () {
  930. savedSearch = {
  931. id: 123,
  932. projectId: 99,
  933. query: 'foo:bar',
  934. };
  935. instance.transitionTo(undefined, savedSearch);
  936. expect(browserHistory.push).toHaveBeenCalledWith({
  937. pathname: '/organizations/org-slug/issues/searches/123/',
  938. query: {
  939. environment: [],
  940. project: [savedSearch.projectId],
  941. statsPeriod: '14d',
  942. },
  943. });
  944. });
  945. it('transitions to saved search with a sort', function () {
  946. savedSearch = {
  947. id: 123,
  948. project: null,
  949. query: 'foo:bar',
  950. sort: 'freq',
  951. };
  952. instance.transitionTo(undefined, savedSearch);
  953. expect(browserHistory.push).toHaveBeenCalledWith({
  954. pathname: '/organizations/org-slug/issues/searches/123/',
  955. query: {
  956. environment: [],
  957. project: [parseInt(project.id, 10)],
  958. statsPeriod: '14d',
  959. sort: savedSearch.sort,
  960. },
  961. });
  962. });
  963. it('goes to all projects when using a basic saved search and global-views feature', function () {
  964. organization.features = ['global-views'];
  965. savedSearch = {
  966. id: 1,
  967. project: null,
  968. query: 'is:unresolved',
  969. };
  970. instance.transitionTo(undefined, savedSearch);
  971. expect(browserHistory.push).toHaveBeenCalledWith({
  972. pathname: '/organizations/org-slug/issues/searches/1/',
  973. query: {
  974. project: [parseInt(project.id, 10)],
  975. environment: [],
  976. statsPeriod: '14d',
  977. },
  978. });
  979. });
  980. it('retains project selection when using a basic saved search and no global-views feature', function () {
  981. organization.features = [];
  982. savedSearch = {
  983. id: 1,
  984. projectId: null,
  985. query: 'is:unresolved',
  986. };
  987. instance.transitionTo(undefined, savedSearch);
  988. expect(browserHistory.push).toHaveBeenCalledWith({
  989. pathname: '/organizations/org-slug/issues/searches/1/',
  990. query: {
  991. environment: [],
  992. project: props.selection.projects,
  993. statsPeriod: '14d',
  994. },
  995. });
  996. });
  997. });
  998. describe('getEndpointParams', function () {
  999. beforeEach(function () {
  1000. wrapper = shallow(<IssueListOverview {...props} />);
  1001. });
  1002. it('omits null values', function () {
  1003. wrapper.setProps({
  1004. selection: {
  1005. projects: null,
  1006. environments: null,
  1007. datetime: {period: '14d'},
  1008. },
  1009. });
  1010. const value = wrapper.instance().getEndpointParams();
  1011. expect(value.project).toBeUndefined();
  1012. expect(value.projects).toBeUndefined();
  1013. expect(value.environment).toBeUndefined();
  1014. expect(value.environments).toBeUndefined();
  1015. expect(value.statsPeriod).toEqual('14d');
  1016. });
  1017. it('omits defaults', function () {
  1018. wrapper.setProps({
  1019. location: {
  1020. query: {
  1021. sort: 'date',
  1022. groupStatsPeriod: '24h',
  1023. },
  1024. },
  1025. });
  1026. const value = wrapper.instance().getEndpointParams();
  1027. expect(value.groupStatsPeriod).toBeUndefined();
  1028. expect(value.sort).toBeUndefined();
  1029. });
  1030. it('uses saved search data', function () {
  1031. const value = wrapper.instance().getEndpointParams();
  1032. expect(value.query).toEqual('is:unresolved');
  1033. expect(value.project).toEqual([parseInt(savedSearch.projectId, 10)]);
  1034. });
  1035. });
  1036. describe('componentDidMount', function () {
  1037. beforeEach(function () {
  1038. wrapper = shallow(<IssueListOverview {...props} />);
  1039. });
  1040. it('fetches tags and sets state', async function () {
  1041. const instance = wrapper.instance();
  1042. await instance.componentDidMount();
  1043. expect(fetchTagsRequest).toHaveBeenCalled();
  1044. expect(instance.state.tagsLoading).toBeFalsy();
  1045. });
  1046. it('fetches members and sets state', async function () {
  1047. const instance = wrapper.instance();
  1048. await instance.componentDidMount();
  1049. wrapper.update();
  1050. expect(fetchMembersRequest).toHaveBeenCalled();
  1051. const members = instance.state.memberList;
  1052. // Spot check the resulting structure as we munge it a bit.
  1053. expect(members).toBeTruthy();
  1054. expect(members[project.slug]).toBeTruthy();
  1055. expect(members[project.slug][0].email).toBeTruthy();
  1056. });
  1057. it('fetches groups when there is no searchid', async function () {
  1058. await wrapper.instance().componentDidMount();
  1059. });
  1060. });
  1061. describe('componentDidUpdate fetching groups', function () {
  1062. let fetchDataMock;
  1063. beforeEach(function () {
  1064. fetchDataMock = MockApiClient.addMockResponse({
  1065. url: '/organizations/org-slug/issues/',
  1066. body: [group],
  1067. headers: {
  1068. Link: DEFAULT_LINKS_HEADER,
  1069. },
  1070. });
  1071. fetchDataMock.mockReset();
  1072. wrapper = shallow(<IssueListOverview {...props} />);
  1073. });
  1074. it('fetches data on selection change', function () {
  1075. const selection = {projects: [99], environments: [], datetime: {period: '24h'}};
  1076. wrapper.setProps({selection, foo: 'bar'});
  1077. expect(fetchDataMock).toHaveBeenCalled();
  1078. });
  1079. it('fetches data on savedSearch change', function () {
  1080. savedSearch = {id: '1', query: 'is:resolved'};
  1081. wrapper.setProps({savedSearch});
  1082. wrapper.update();
  1083. expect(fetchDataMock).toHaveBeenCalled();
  1084. });
  1085. it('fetches data on location change', async function () {
  1086. const queryAttrs = ['query', 'sort', 'statsPeriod', 'cursor', 'groupStatsPeriod'];
  1087. const location = cloneDeep(props.location);
  1088. for (const [i, attr] of queryAttrs.entries()) {
  1089. // reclone each iteration so that only one property changes.
  1090. const newLocation = cloneDeep(location);
  1091. newLocation.query[attr] = 'newValue';
  1092. wrapper.setProps({location: newLocation});
  1093. await tick();
  1094. wrapper.update();
  1095. // Each property change after the first will actually cause two new
  1096. // fetchData calls, one from the property change and another from a
  1097. // change in this.state.issuesLoading going from false to true.
  1098. expect(fetchDataMock).toHaveBeenCalledTimes(2 * i + 1);
  1099. }
  1100. });
  1101. it('uses correct statsPeriod when fetching issues list and no datetime given', async function () {
  1102. const selection = {projects: [99], environments: [], datetime: {}};
  1103. wrapper.setProps({selection, foo: 'bar'});
  1104. expect(fetchDataMock).toHaveBeenLastCalledWith(
  1105. '/organizations/org-slug/issues/',
  1106. expect.objectContaining({
  1107. data: 'collapse=stats&expand=owners&expand=inbox&limit=25&project=99&query=is%3Aunresolved&shortIdLookup=1&statsPeriod=14d',
  1108. })
  1109. );
  1110. });
  1111. });
  1112. describe('componentDidUpdate fetching members', function () {
  1113. beforeEach(function () {
  1114. wrapper = shallow(<IssueListOverview {...props} />);
  1115. wrapper.instance().fetchData = jest.fn();
  1116. });
  1117. it('fetches memberlist on project change', function () {
  1118. // Called during componentDidMount
  1119. expect(fetchMembersRequest).toHaveBeenCalledTimes(1);
  1120. const selection = {
  1121. projects: [99],
  1122. environments: [],
  1123. datetime: {period: '24h'},
  1124. };
  1125. wrapper.setProps({selection});
  1126. wrapper.update();
  1127. expect(fetchMembersRequest).toHaveBeenCalledTimes(2);
  1128. });
  1129. });
  1130. describe('componentDidUpdate fetching tags', function () {
  1131. beforeEach(function () {
  1132. wrapper = shallow(<IssueListOverview {...props} />);
  1133. wrapper.instance().fetchData = jest.fn();
  1134. });
  1135. it('fetches tags on project change', function () {
  1136. // Called during componentDidMount
  1137. expect(fetchTagsRequest).toHaveBeenCalledTimes(1);
  1138. const selection = {
  1139. projects: [99],
  1140. environments: [],
  1141. datetime: {period: '24h'},
  1142. };
  1143. wrapper.setProps({selection});
  1144. wrapper.update();
  1145. expect(fetchTagsRequest).toHaveBeenCalledTimes(2);
  1146. });
  1147. });
  1148. describe('processingIssues', function () {
  1149. beforeEach(function () {
  1150. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />);
  1151. });
  1152. it('fetches and displays processing issues', async function () {
  1153. const instance = wrapper.instance();
  1154. instance.componentDidMount();
  1155. wrapper.update();
  1156. GroupStore.add([group]);
  1157. wrapper.setState({
  1158. groupIds: ['1'],
  1159. loading: false,
  1160. });
  1161. const issues = wrapper.find('ProcessingIssueList');
  1162. expect(issues).toHaveLength(1);
  1163. });
  1164. });
  1165. describe('render states', function () {
  1166. it('displays the loading icon', function () {
  1167. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />);
  1168. wrapper.setState({savedSearchLoading: true});
  1169. expect(wrapper.find('LoadingIndicator')).toHaveLength(1);
  1170. });
  1171. it('displays an error', function () {
  1172. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />);
  1173. wrapper.setState({
  1174. error: 'Things broke',
  1175. savedSearchLoading: false,
  1176. issuesLoading: false,
  1177. });
  1178. const error = wrapper.find('LoadingError');
  1179. expect(error).toHaveLength(1);
  1180. expect(error.props().message).toEqual('Things broke');
  1181. });
  1182. it('displays congrats robots animation with only is:unresolved query', async function () {
  1183. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />);
  1184. wrapper.setState({
  1185. savedSearchLoading: false,
  1186. issuesLoading: false,
  1187. error: false,
  1188. groupIds: [],
  1189. });
  1190. await tick();
  1191. wrapper.update();
  1192. expect(wrapper.find('NoUnresolvedIssues').exists()).toBe(true);
  1193. });
  1194. it('displays an empty resultset with is:unresolved and level:error query', async function () {
  1195. const errorsOnlyQuery = {
  1196. ...props,
  1197. location: {
  1198. query: {query: 'is:unresolved level:error'},
  1199. },
  1200. };
  1201. wrapper = mountWithThemeAndOrg(<IssueListOverview {...errorsOnlyQuery} />);
  1202. wrapper.setState({
  1203. savedSearchLoading: false,
  1204. issuesLoading: false,
  1205. error: false,
  1206. groupIds: [],
  1207. fetchingSentFirstEvent: false,
  1208. sentFirstEvent: true,
  1209. });
  1210. await tick();
  1211. wrapper.update();
  1212. expect(wrapper.find('EmptyStateWarning').exists()).toBe(true);
  1213. });
  1214. it('displays an empty resultset with has:browser query', async function () {
  1215. const hasBrowserQuery = {
  1216. ...props,
  1217. location: {
  1218. query: {query: 'has:browser'},
  1219. },
  1220. };
  1221. wrapper = mountWithThemeAndOrg(<IssueListOverview {...hasBrowserQuery} />);
  1222. wrapper.setState({
  1223. savedSearchLoading: false,
  1224. issuesLoading: false,
  1225. error: false,
  1226. groupIds: [],
  1227. fetchingSentFirstEvent: false,
  1228. sentFirstEvent: true,
  1229. });
  1230. await tick();
  1231. wrapper.update();
  1232. expect(wrapper.find('EmptyStateWarning').exists()).toBe(true);
  1233. });
  1234. });
  1235. describe('Error Robot', function () {
  1236. const createWrapper = moreProps => {
  1237. const defaultProps = {
  1238. ...props,
  1239. savedSearchLoading: false,
  1240. useOrgSavedSearches: true,
  1241. selection: {
  1242. projects: [],
  1243. environments: [],
  1244. datetime: {period: '14d'},
  1245. },
  1246. location: {query: {query: 'is:unresolved'}, search: 'query=is:unresolved'},
  1247. params: {orgId: organization.slug},
  1248. organization: TestStubs.Organization({
  1249. projects: [],
  1250. }),
  1251. ...moreProps,
  1252. };
  1253. const localWrapper = mountWithThemeAndOrg(<IssueListOverview {...defaultProps} />);
  1254. localWrapper.setState({
  1255. error: false,
  1256. issuesLoading: false,
  1257. groupIds: [],
  1258. });
  1259. return localWrapper;
  1260. };
  1261. it('displays when no projects selected and all projects user is member of, does not have first event', async function () {
  1262. const projects = [
  1263. TestStubs.Project({
  1264. id: '1',
  1265. slug: 'foo',
  1266. isMember: true,
  1267. firstEvent: false,
  1268. }),
  1269. TestStubs.Project({
  1270. id: '2',
  1271. slug: 'bar',
  1272. isMember: true,
  1273. firstEvent: false,
  1274. }),
  1275. TestStubs.Project({
  1276. id: '3',
  1277. slug: 'baz',
  1278. isMember: true,
  1279. firstEvent: false,
  1280. }),
  1281. ];
  1282. MockApiClient.addMockResponse({
  1283. url: '/organizations/org-slug/sent-first-event/',
  1284. query: {
  1285. is_member: true,
  1286. },
  1287. body: {sentFirstEvent: false},
  1288. });
  1289. MockApiClient.addMockResponse({
  1290. url: '/organizations/org-slug/projects/',
  1291. body: projects,
  1292. });
  1293. MockApiClient.addMockResponse({
  1294. url: '/projects/org-slug/foo/issues/',
  1295. body: [],
  1296. });
  1297. wrapper = createWrapper({
  1298. organization: TestStubs.Organization({
  1299. projects,
  1300. }),
  1301. });
  1302. await tick();
  1303. wrapper.update();
  1304. expect(wrapper.find('ErrorRobot')).toHaveLength(1);
  1305. });
  1306. it('does not display when no projects selected and any projects have a first event', async function () {
  1307. const projects = [
  1308. TestStubs.Project({
  1309. id: '1',
  1310. slug: 'foo',
  1311. isMember: true,
  1312. firstEvent: false,
  1313. }),
  1314. TestStubs.Project({
  1315. id: '2',
  1316. slug: 'bar',
  1317. isMember: true,
  1318. firstEvent: true,
  1319. }),
  1320. TestStubs.Project({
  1321. id: '3',
  1322. slug: 'baz',
  1323. isMember: true,
  1324. firstEvent: false,
  1325. }),
  1326. ];
  1327. MockApiClient.addMockResponse({
  1328. url: '/organizations/org-slug/sent-first-event/',
  1329. query: {
  1330. is_member: true,
  1331. },
  1332. body: {sentFirstEvent: true},
  1333. });
  1334. MockApiClient.addMockResponse({
  1335. url: '/organizations/org-slug/projects/',
  1336. body: projects,
  1337. });
  1338. wrapper = createWrapper({
  1339. organization: TestStubs.Organization({
  1340. projects,
  1341. }),
  1342. });
  1343. await tick();
  1344. wrapper.update();
  1345. expect(wrapper.find('ErrorRobot')).toHaveLength(0);
  1346. });
  1347. it('displays when all selected projects do not have first event', async function () {
  1348. const projects = [
  1349. TestStubs.Project({
  1350. id: '1',
  1351. slug: 'foo',
  1352. isMember: true,
  1353. firstEvent: false,
  1354. }),
  1355. TestStubs.Project({
  1356. id: '2',
  1357. slug: 'bar',
  1358. isMember: true,
  1359. firstEvent: false,
  1360. }),
  1361. TestStubs.Project({
  1362. id: '3',
  1363. slug: 'baz',
  1364. isMember: true,
  1365. firstEvent: false,
  1366. }),
  1367. ];
  1368. MockApiClient.addMockResponse({
  1369. url: '/organizations/org-slug/sent-first-event/',
  1370. query: {
  1371. project: [1, 2],
  1372. },
  1373. body: {sentFirstEvent: false},
  1374. });
  1375. MockApiClient.addMockResponse({
  1376. url: '/organizations/org-slug/projects/',
  1377. body: projects,
  1378. });
  1379. MockApiClient.addMockResponse({
  1380. url: '/projects/org-slug/foo/issues/',
  1381. body: [],
  1382. });
  1383. wrapper = createWrapper({
  1384. selection: {
  1385. projects: [1, 2],
  1386. environments: [],
  1387. datetime: {period: '14d'},
  1388. },
  1389. organization: TestStubs.Organization({
  1390. projects,
  1391. }),
  1392. });
  1393. await tick();
  1394. wrapper.update();
  1395. expect(wrapper.find('ErrorRobot')).toHaveLength(1);
  1396. });
  1397. it('does not display when any selected projects have first event', function () {
  1398. const projects = [
  1399. TestStubs.Project({
  1400. id: '1',
  1401. slug: 'foo',
  1402. isMember: true,
  1403. firstEvent: false,
  1404. }),
  1405. TestStubs.Project({
  1406. id: '2',
  1407. slug: 'bar',
  1408. isMember: true,
  1409. firstEvent: true,
  1410. }),
  1411. TestStubs.Project({
  1412. id: '3',
  1413. slug: 'baz',
  1414. isMember: true,
  1415. firstEvent: true,
  1416. }),
  1417. ];
  1418. MockApiClient.addMockResponse({
  1419. url: '/organizations/org-slug/sent-first-event/',
  1420. query: {
  1421. project: [1, 2],
  1422. },
  1423. body: {sentFirstEvent: true},
  1424. });
  1425. MockApiClient.addMockResponse({
  1426. url: '/organizations/org-slug/projects/',
  1427. body: projects,
  1428. });
  1429. wrapper = createWrapper({
  1430. selection: {
  1431. projects: [1, 2],
  1432. environments: [],
  1433. datetime: {period: '14d'},
  1434. },
  1435. organization: TestStubs.Organization({
  1436. projects,
  1437. }),
  1438. });
  1439. expect(wrapper.find('ErrorRobot')).toHaveLength(0);
  1440. });
  1441. });
  1442. it('displays a count that represents the current page', function () {
  1443. parseLinkHeaderSpy.mockReturnValue({
  1444. next: {
  1445. results: true,
  1446. },
  1447. previous: {
  1448. results: false,
  1449. },
  1450. });
  1451. props = {
  1452. ...props,
  1453. location: {
  1454. query: {
  1455. cursor: 'some cursor',
  1456. page: 0,
  1457. },
  1458. },
  1459. };
  1460. const {routerContext} = initializeOrg();
  1461. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />, routerContext);
  1462. wrapper.setState({
  1463. groupIds: range(0, 25).map(String),
  1464. queryCount: 500,
  1465. queryMaxCount: 1000,
  1466. pageLinks: DEFAULT_LINKS_HEADER,
  1467. });
  1468. const paginationCaption = wrapper.find('PaginationCaption');
  1469. expect(paginationCaption.text()).toBe('Showing 25 of 500 issues');
  1470. parseLinkHeaderSpy.mockReturnValue({
  1471. next: {
  1472. results: true,
  1473. },
  1474. previous: {
  1475. results: true,
  1476. },
  1477. });
  1478. wrapper.setProps({
  1479. location: {
  1480. query: {
  1481. cursor: 'some cursor',
  1482. page: 1,
  1483. },
  1484. },
  1485. });
  1486. expect(paginationCaption.text()).toBe('Showing 50 of 500 issues');
  1487. expect(wrapper.find('IssueListHeader').exists()).toBeTruthy();
  1488. });
  1489. it('displays a count that makes sense based on the current page', function () {
  1490. parseLinkHeaderSpy.mockReturnValue({
  1491. next: {
  1492. // Is at last page according to the cursor
  1493. results: false,
  1494. },
  1495. previous: {
  1496. results: true,
  1497. },
  1498. });
  1499. props = {
  1500. ...props,
  1501. location: {
  1502. query: {
  1503. cursor: 'some cursor',
  1504. page: 3,
  1505. },
  1506. },
  1507. };
  1508. const {routerContext} = initializeOrg();
  1509. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />, routerContext);
  1510. wrapper.setState({
  1511. groupIds: range(0, 25).map(String),
  1512. queryCount: 500,
  1513. queryMaxCount: 1000,
  1514. pageLinks: DEFAULT_LINKS_HEADER,
  1515. });
  1516. const paginationCaption = wrapper.find('PaginationCaption');
  1517. expect(paginationCaption.text()).toBe('Showing 500 of 500 issues');
  1518. parseLinkHeaderSpy.mockReturnValue({
  1519. next: {
  1520. results: true,
  1521. },
  1522. previous: {
  1523. // Is at first page according to cursor
  1524. results: false,
  1525. },
  1526. });
  1527. wrapper.setProps({
  1528. location: {
  1529. query: {
  1530. cursor: 'some cursor',
  1531. page: 2,
  1532. },
  1533. },
  1534. });
  1535. expect(paginationCaption.text()).toBe('Showing 25 of 500 issues');
  1536. expect(wrapper.find('IssueListHeader').exists()).toBeTruthy();
  1537. });
  1538. it('displays a count based on items removed', function () {
  1539. parseLinkHeaderSpy.mockReturnValue({
  1540. next: {
  1541. results: true,
  1542. },
  1543. previous: {
  1544. results: true,
  1545. },
  1546. });
  1547. props = {
  1548. ...props,
  1549. location: {
  1550. query: {
  1551. cursor: 'some cursor',
  1552. page: 1,
  1553. },
  1554. },
  1555. };
  1556. const {routerContext} = initializeOrg();
  1557. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />, routerContext);
  1558. wrapper.setState({
  1559. groupIds: range(0, 25).map(String),
  1560. queryCount: 75,
  1561. itemsRemoved: 1,
  1562. queryMaxCount: 1000,
  1563. pageLinks: DEFAULT_LINKS_HEADER,
  1564. });
  1565. const paginationCaption = wrapper.find('PaginationCaption');
  1566. // 2nd page subtracts the one removed
  1567. expect(paginationCaption.text()).toBe('Showing 49 of 74 issues');
  1568. });
  1569. describe('with relative change feature', function () {
  1570. it('defaults to larger graph selection', function () {
  1571. organization.features = ['issue-list-trend-sort'];
  1572. props.location = {
  1573. query: {query: 'is:unresolved', sort: 'trend'},
  1574. search: 'query=is:unresolved',
  1575. };
  1576. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />);
  1577. expect(wrapper.instance().getGroupStatsPeriod()).toBe('auto');
  1578. });
  1579. });
  1580. describe('project low priority queue alert', function () {
  1581. const {routerContext} = initializeOrg();
  1582. beforeEach(function () {
  1583. act(() => ProjectsStore.reset());
  1584. });
  1585. it('does not render alert', function () {
  1586. act(() => ProjectsStore.loadInitialData([project]));
  1587. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />, routerContext);
  1588. const eventProcessingAlert = wrapper.find('StyledGlobalEventProcessingAlert');
  1589. expect(eventProcessingAlert.exists()).toBe(true);
  1590. expect(eventProcessingAlert.isEmptyRender()).toBe(true);
  1591. });
  1592. describe('renders alert', function () {
  1593. it('for one project', function () {
  1594. act(() =>
  1595. ProjectsStore.loadInitialData([
  1596. {...project, eventProcessing: {symbolicationDegraded: true}},
  1597. ])
  1598. );
  1599. wrapper = mountWithThemeAndOrg(<IssueListOverview {...props} />, routerContext);
  1600. const eventProcessingAlert = wrapper.find('StyledGlobalEventProcessingAlert');
  1601. expect(eventProcessingAlert.exists()).toBe(true);
  1602. expect(eventProcessingAlert.isEmptyRender()).toBe(false);
  1603. expect(eventProcessingAlert.text()).toBe(
  1604. 'Event Processing for this project is currently degraded. Events may appear with larger delays than usual or get dropped. Please check the Status page for a potential outage.'
  1605. );
  1606. });
  1607. it('for multiple projects', function () {
  1608. const projectBar = TestStubs.ProjectDetails({
  1609. id: '3560',
  1610. name: 'Bar Project',
  1611. slug: 'project-slug-bar',
  1612. });
  1613. act(() =>
  1614. ProjectsStore.loadInitialData([
  1615. {
  1616. ...project,
  1617. slug: 'project-slug',
  1618. eventProcessing: {symbolicationDegraded: true},
  1619. },
  1620. {
  1621. ...projectBar,
  1622. slug: 'project-slug-bar',
  1623. eventProcessing: {symbolicationDegraded: true},
  1624. },
  1625. ])
  1626. );
  1627. wrapper = mountWithThemeAndOrg(
  1628. <IssueListOverview
  1629. {...props}
  1630. selection={{
  1631. ...props.selection,
  1632. projects: [Number(project.id), Number(projectBar.id)],
  1633. }}
  1634. />,
  1635. routerContext
  1636. );
  1637. const eventProcessingAlert = wrapper.find('StyledGlobalEventProcessingAlert');
  1638. expect(eventProcessingAlert.exists()).toBe(true);
  1639. expect(eventProcessingAlert.isEmptyRender()).toBe(false);
  1640. expect(eventProcessingAlert.text()).toBe(
  1641. `Event Processing for the ${project.slug}, ${projectBar.slug} projects is currently degraded. Events may appear with larger delays than usual or get dropped. Please check the Status page for a potential outage.`
  1642. );
  1643. });
  1644. });
  1645. });
  1646. });