overview.spec.tsx 41 KB

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