groupActivity.spec.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. act,
  4. render,
  5. renderGlobalModal,
  6. screen,
  7. userEvent,
  8. waitFor,
  9. } from 'sentry-test/reactTestingLibrary';
  10. import ConfigStore from 'sentry/stores/configStore';
  11. import GroupStore from 'sentry/stores/groupStore';
  12. import OrganizationStore from 'sentry/stores/organizationStore';
  13. import ProjectsStore from 'sentry/stores/projectsStore';
  14. import TeamStore from 'sentry/stores/teamStore';
  15. import {Group, GroupActivityType, Organization} from 'sentry/types';
  16. import {GroupActivity} from 'sentry/views/issueDetails/groupActivity';
  17. describe('GroupActivity', function () {
  18. let project;
  19. const dateCreated = '2021-10-01T15:31:38.950115Z';
  20. beforeEach(function () {
  21. project = TestStubs.Project();
  22. ProjectsStore.loadInitialData([project]);
  23. ConfigStore.init();
  24. ConfigStore.set('user', TestStubs.User({id: '123'}));
  25. GroupStore.init();
  26. });
  27. afterEach(() => {
  28. MockApiClient.clearMockResponses();
  29. jest.clearAllMocks();
  30. });
  31. function createWrapper({
  32. activity,
  33. organization: additionalOrg,
  34. }: {
  35. activity?: Group['activity'];
  36. organization?: Organization;
  37. } = {}) {
  38. const group = TestStubs.Group({
  39. id: '1337',
  40. activity: activity ?? [
  41. {type: 'note', id: 'note-1', data: {text: 'Test Note'}, user: TestStubs.User()},
  42. ],
  43. project,
  44. });
  45. const {organization, routerContext, routerProps} = initializeOrg({
  46. organization: additionalOrg,
  47. });
  48. GroupStore.add([group]);
  49. TeamStore.loadInitialData([TestStubs.Team({id: '999', slug: 'no-team'})]);
  50. OrganizationStore.onUpdate(organization, {replace: true});
  51. return render(
  52. <GroupActivity
  53. {...routerProps}
  54. api={new MockApiClient()}
  55. params={{orgId: 'org-slug'}}
  56. group={group}
  57. organization={organization}
  58. />,
  59. {context: routerContext}
  60. );
  61. }
  62. it('renders a NoteInput', function () {
  63. createWrapper();
  64. expect(screen.getByTestId('activity-note-body')).toBeInTheDocument();
  65. });
  66. it('renders a marked reviewed activity', function () {
  67. const user = TestStubs.User({name: 'Samwise'});
  68. createWrapper({
  69. activity: [
  70. {
  71. type: GroupActivityType.MARK_REVIEWED,
  72. id: 'reviewed-1',
  73. dateCreated: '',
  74. project: TestStubs.Project(),
  75. data: {},
  76. user,
  77. },
  78. ],
  79. });
  80. expect(screen.getByText('marked this issue as reviewed')).toBeInTheDocument();
  81. expect(screen.getByText(user.name)).toBeInTheDocument();
  82. });
  83. it('renders a pr activity', function () {
  84. const user = TestStubs.User({name: 'Test User'});
  85. const repository = TestStubs.Repository();
  86. createWrapper({
  87. activity: [
  88. {
  89. dateCreated: '',
  90. project: TestStubs.Project(),
  91. type: GroupActivityType.SET_RESOLVED_IN_PULL_REQUEST,
  92. id: 'pr-1',
  93. data: {
  94. pullRequest: {
  95. externalUrl: '',
  96. id: '',
  97. title: '',
  98. repository,
  99. },
  100. },
  101. user,
  102. },
  103. ],
  104. });
  105. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  106. 'Test User has created a PR for this issue:'
  107. );
  108. });
  109. it('renders a assigned to self activity', function () {
  110. const user = TestStubs.User({id: '123', name: 'Mark'});
  111. createWrapper({
  112. activity: [
  113. {
  114. data: {
  115. assignee: user.id,
  116. assigneeEmail: user.email,
  117. assigneeType: 'user',
  118. user,
  119. },
  120. user,
  121. dateCreated: '2021-10-01T15:31:38.950115Z',
  122. id: '117',
  123. project: TestStubs.Project(),
  124. type: GroupActivityType.ASSIGNED,
  125. },
  126. ],
  127. });
  128. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  129. /Mark assigned this issue to themselves/
  130. );
  131. });
  132. it('renders an assigned via codeowners activity', function () {
  133. createWrapper({
  134. activity: [
  135. {
  136. data: {
  137. assignee: '123',
  138. assigneeEmail: 'anotheruser@sentry.io',
  139. assigneeType: 'user',
  140. integration: 'codeowners',
  141. rule: 'path:something/*.py #workflow',
  142. user: TestStubs.User(),
  143. },
  144. project: TestStubs.Project(),
  145. dateCreated: '2021-10-01T15:31:38.950115Z',
  146. id: '117',
  147. type: GroupActivityType.ASSIGNED,
  148. user: null,
  149. },
  150. ],
  151. });
  152. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  153. /Sentry auto-assigned this issue to anotheruser@sentry.io/
  154. );
  155. });
  156. it('renders an assigned via slack activity', function () {
  157. const user = TestStubs.User({id: '301', name: 'Mark'});
  158. createWrapper({
  159. activity: [
  160. {
  161. data: {
  162. assignee: '123',
  163. assigneeEmail: 'anotheruser@sentry.io',
  164. assigneeType: 'user',
  165. integration: 'slack',
  166. user: TestStubs.User(),
  167. },
  168. project: TestStubs.Project(),
  169. dateCreated: '2021-10-01T15:31:38.950115Z',
  170. id: '117',
  171. type: GroupActivityType.ASSIGNED,
  172. user,
  173. },
  174. ],
  175. });
  176. const item = screen.getAllByTestId('activity-item').at(-1);
  177. expect(item).toHaveTextContent(/Mark assigned this issue to anotheruser@sentry.io/);
  178. expect(item).toHaveTextContent(/Assigned via Slack/);
  179. });
  180. it('resolved in commit with no releases', function () {
  181. createWrapper({
  182. activity: [
  183. {
  184. type: GroupActivityType.SET_RESOLVED_IN_COMMIT,
  185. id: '123',
  186. project: TestStubs.Project(),
  187. dateCreated: '',
  188. data: {
  189. commit: {
  190. dateCreated: '',
  191. message: '',
  192. id: 'komal-commit',
  193. repository: TestStubs.Repository(),
  194. releases: [],
  195. },
  196. },
  197. user: TestStubs.User(),
  198. },
  199. ],
  200. });
  201. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  202. 'Foo Bar marked this issue as resolved in komal-commit'
  203. );
  204. });
  205. it('resolved in commit with one release', function () {
  206. createWrapper({
  207. activity: [
  208. {
  209. type: GroupActivityType.SET_RESOLVED_IN_COMMIT,
  210. id: '123',
  211. project: TestStubs.Project(),
  212. dateCreated: '',
  213. data: {
  214. commit: {
  215. id: 'komal-commit',
  216. dateCreated: '',
  217. message: '',
  218. repository: TestStubs.Repository(),
  219. releases: [
  220. TestStubs.Release({
  221. dateCreated: '2022-05-01',
  222. dateReleased: '2022-05-02',
  223. version: 'random',
  224. }),
  225. ],
  226. },
  227. },
  228. user: TestStubs.User(),
  229. },
  230. ],
  231. });
  232. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  233. 'Foo Bar marked this issue as resolved in komal-commit This commit was released in random'
  234. );
  235. });
  236. it('resolved in commit with multiple releases', function () {
  237. createWrapper({
  238. activity: [
  239. {
  240. type: GroupActivityType.SET_RESOLVED_IN_COMMIT,
  241. id: '123',
  242. project: TestStubs.Project(),
  243. dateCreated: '',
  244. data: {
  245. commit: {
  246. id: 'komal-commit',
  247. dateCreated: '',
  248. message: '',
  249. repository: TestStubs.Repository(),
  250. releases: [
  251. TestStubs.Release({
  252. dateCreated: '2022-05-01',
  253. dateReleased: '2022-05-02',
  254. version: 'random',
  255. }),
  256. TestStubs.Release({
  257. dateCreated: '2022-06-01',
  258. dateReleased: '2022-06-02',
  259. version: 'newest',
  260. }),
  261. TestStubs.Release({
  262. dateCreated: '2021-08-03',
  263. dateReleased: '2021-08-03',
  264. version: 'oldest-release',
  265. }),
  266. TestStubs.Release({
  267. dateCreated: '2022-04-21',
  268. dateReleased: '2022-04-21',
  269. version: 'randomTwo',
  270. }),
  271. ],
  272. },
  273. },
  274. user: TestStubs.User(),
  275. },
  276. ],
  277. });
  278. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  279. 'Foo Bar marked this issue as resolved in komal-commit This commit was released in oldest-release and 3 others'
  280. );
  281. });
  282. it('requests assignees that are not in the team store', async function () {
  283. const team = TestStubs.Team({id: '123', name: 'workflow'});
  284. const teamRequest = MockApiClient.addMockResponse({
  285. url: `/organizations/org-slug/teams/`,
  286. body: [team],
  287. });
  288. createWrapper({
  289. activity: [
  290. {
  291. id: '123',
  292. user: null,
  293. type: GroupActivityType.ASSIGNED,
  294. project: TestStubs.Project(),
  295. data: {
  296. assignee: team.id,
  297. assigneeType: 'team',
  298. user: TestStubs.User(),
  299. },
  300. dateCreated: '2021-10-28T13:40:10.634821Z',
  301. },
  302. ],
  303. });
  304. await waitFor(() => expect(teamRequest).toHaveBeenCalledTimes(1));
  305. expect(
  306. await screen.findByText(`assigned this issue to #${team.slug}`)
  307. ).toBeInTheDocument();
  308. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  309. /Sentry assigned this issue to #team-slug/
  310. );
  311. });
  312. describe('Delete', function () {
  313. let deleteMock;
  314. beforeEach(function () {
  315. deleteMock = MockApiClient.addMockResponse({
  316. url: '/issues/1337/comments/note-1/',
  317. method: 'DELETE',
  318. });
  319. ConfigStore.set('user', TestStubs.User({id: '123', isSuperuser: true}));
  320. });
  321. it('should do nothing if not present in GroupStore', async function () {
  322. createWrapper();
  323. renderGlobalModal();
  324. act(() => {
  325. // Remove note from group activity
  326. GroupStore.removeActivity('1337', 'note-1');
  327. });
  328. await userEvent.click(screen.getByRole('button', {name: 'Comment Actions'}));
  329. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Remove'}));
  330. expect(
  331. screen.getByText('Are you sure you wish to delete this comment?')
  332. ).toBeInTheDocument();
  333. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  334. expect(deleteMock).not.toHaveBeenCalled();
  335. });
  336. it('should remove remove the item from the GroupStore make a DELETE API request', async function () {
  337. createWrapper();
  338. renderGlobalModal();
  339. await userEvent.click(screen.getByRole('button', {name: 'Comment Actions'}));
  340. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Remove'}));
  341. expect(
  342. screen.getByText('Are you sure you wish to delete this comment?')
  343. ).toBeInTheDocument();
  344. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  345. expect(deleteMock).toHaveBeenCalledTimes(1);
  346. });
  347. });
  348. it('renders ignored', function () {
  349. createWrapper({
  350. activity: [
  351. {
  352. id: '123',
  353. type: GroupActivityType.SET_IGNORED,
  354. project: TestStubs.Project(),
  355. data: {
  356. ignoreUntilEscalating: true,
  357. },
  358. user: TestStubs.User(),
  359. dateCreated,
  360. },
  361. ],
  362. });
  363. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  364. 'Foo Bar ignored this issue'
  365. );
  366. });
  367. it('renders archived until escalating if org has `escalating-issues` feature', function () {
  368. createWrapper({
  369. activity: [
  370. {
  371. id: '123',
  372. type: GroupActivityType.SET_IGNORED,
  373. project: TestStubs.Project(),
  374. data: {
  375. ignoreUntilEscalating: true,
  376. },
  377. user: TestStubs.User(),
  378. dateCreated,
  379. },
  380. ],
  381. organization: TestStubs.Organization({features: ['escalating-issues']}),
  382. });
  383. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  384. 'Foo Bar archived this issue until it escalates'
  385. );
  386. });
  387. it('renders escalating with forecast and plural events if org has `escalating-issues` feature', function () {
  388. createWrapper({
  389. activity: [
  390. {
  391. id: '123',
  392. type: GroupActivityType.SET_UNRESOLVED,
  393. project: TestStubs.Project(),
  394. data: {
  395. forecast: 200,
  396. },
  397. user: null,
  398. dateCreated,
  399. },
  400. {
  401. id: '124',
  402. type: GroupActivityType.SET_ESCALATING,
  403. project: TestStubs.Project(),
  404. data: {
  405. forecast: 400,
  406. },
  407. user: null,
  408. dateCreated: '2021-10-05T15:31:38.950115Z',
  409. },
  410. ],
  411. organization: TestStubs.Organization({features: ['escalating-issues']}),
  412. });
  413. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  414. 'Sentry flagged this issue as escalating because over 400 events happened in an hour'
  415. );
  416. expect(screen.getAllByTestId('activity-item').at(-2)).toHaveTextContent(
  417. 'Sentry flagged this issue as escalating because over 200 events happened in an hour'
  418. );
  419. });
  420. it('renders escalating with forecast and singular event if org has `escalating-issues` feature', function () {
  421. createWrapper({
  422. activity: [
  423. {
  424. id: '123',
  425. type: GroupActivityType.SET_UNRESOLVED,
  426. project: TestStubs.Project(),
  427. data: {
  428. forecast: 1,
  429. },
  430. user: null,
  431. dateCreated,
  432. },
  433. ],
  434. organization: TestStubs.Organization({features: ['escalating-issues']}),
  435. });
  436. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  437. 'Sentry flagged this issue as escalating because over 1 event happened in an hour'
  438. );
  439. });
  440. it('renders ignored until it happens x times in time window', function () {
  441. createWrapper({
  442. activity: [
  443. {
  444. id: '123',
  445. type: GroupActivityType.SET_IGNORED,
  446. project: TestStubs.Project(),
  447. data: {
  448. ignoreCount: 400,
  449. ignoreWindow: 1,
  450. },
  451. user: TestStubs.User(),
  452. dateCreated,
  453. },
  454. ],
  455. });
  456. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  457. 'Foo Bar ignored this issue until it happens 400 time(s) in 1 minute'
  458. );
  459. });
  460. it('renders escalating since it happened x times in time window', function () {
  461. createWrapper({
  462. activity: [
  463. {
  464. id: '123',
  465. type: GroupActivityType.SET_ESCALATING,
  466. project: TestStubs.Project(),
  467. data: {
  468. expired_snooze: {
  469. count: 400,
  470. window: 1,
  471. until: null,
  472. user_count: null,
  473. user_window: null,
  474. },
  475. },
  476. dateCreated,
  477. },
  478. ],
  479. });
  480. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  481. 'Sentry flagged this issue as escalating because 400 events happened in 1 minute'
  482. );
  483. });
  484. it('renders escalating since x users were affected in time window', function () {
  485. createWrapper({
  486. activity: [
  487. {
  488. id: '123',
  489. type: GroupActivityType.SET_ESCALATING,
  490. project: TestStubs.Project(),
  491. data: {
  492. expired_snooze: {
  493. user_count: 1,
  494. user_window: 1,
  495. until: null,
  496. count: null,
  497. window: null,
  498. },
  499. },
  500. dateCreated,
  501. },
  502. ],
  503. });
  504. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  505. 'Sentry flagged this issue as escalating because 1 user was affected in 1 minute'
  506. );
  507. });
  508. it('renders escalating since until date passed', function () {
  509. const date = new Date('2018-10-30');
  510. createWrapper({
  511. activity: [
  512. {
  513. id: '123',
  514. type: GroupActivityType.SET_ESCALATING,
  515. project: TestStubs.Project(),
  516. data: {
  517. expired_snooze: {
  518. until: date,
  519. user_count: null,
  520. user_window: null,
  521. count: null,
  522. window: null,
  523. },
  524. },
  525. dateCreated,
  526. },
  527. ],
  528. });
  529. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  530. 'Sentry flagged this issue as escalating because Oct 30, 2018 12:00 AM passed'
  531. );
  532. });
  533. it('renders archived forever', function () {
  534. createWrapper({
  535. activity: [
  536. {
  537. id: '123',
  538. type: GroupActivityType.SET_IGNORED,
  539. project: TestStubs.Project(),
  540. data: {},
  541. user: TestStubs.User(),
  542. dateCreated,
  543. },
  544. ],
  545. organization: TestStubs.Organization({features: ['escalating-issues']}),
  546. });
  547. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  548. 'Foo Bar archived this issue forever'
  549. );
  550. });
  551. it('renders resolved in release with semver information', function () {
  552. createWrapper({
  553. activity: [
  554. {
  555. id: '123',
  556. type: GroupActivityType.SET_RESOLVED_IN_RELEASE,
  557. project: TestStubs.Project(),
  558. data: {
  559. version: 'frontend@1.0.0',
  560. },
  561. user: TestStubs.User(),
  562. dateCreated,
  563. },
  564. ],
  565. });
  566. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  567. 'Foo Bar marked this issue as resolved in 1.0.0 (semver)'
  568. );
  569. });
  570. it('renders resolved in next release with semver information', function () {
  571. createWrapper({
  572. activity: [
  573. {
  574. id: '123',
  575. type: GroupActivityType.SET_RESOLVED_IN_RELEASE,
  576. project: TestStubs.Project(),
  577. data: {
  578. current_release_version: 'frontend@1.0.0',
  579. },
  580. user: TestStubs.User(),
  581. dateCreated,
  582. },
  583. ],
  584. });
  585. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  586. 'Foo Bar marked this issue as resolved in releases greater than 1.0.0 (semver)'
  587. );
  588. });
  589. describe('regression', function () {
  590. it('renders basic regression', function () {
  591. createWrapper({
  592. activity: [
  593. {
  594. id: '123',
  595. type: GroupActivityType.SET_REGRESSION,
  596. project: TestStubs.Project(),
  597. data: {},
  598. dateCreated,
  599. },
  600. ],
  601. });
  602. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  603. 'Sentry marked this issue as a regression'
  604. );
  605. });
  606. it('renders regression with version', function () {
  607. createWrapper({
  608. activity: [
  609. {
  610. id: '123',
  611. type: GroupActivityType.SET_REGRESSION,
  612. project: TestStubs.Project(),
  613. data: {
  614. version: 'frontend@1.0.0',
  615. },
  616. dateCreated,
  617. },
  618. ],
  619. });
  620. expect(screen.getAllByTestId('activity-item').at(-1)).toHaveTextContent(
  621. 'Sentry marked this issue as a regression in 1.0.0'
  622. );
  623. });
  624. it('renders regression with semver description', function () {
  625. createWrapper({
  626. activity: [
  627. {
  628. id: '123',
  629. type: GroupActivityType.SET_REGRESSION,
  630. project: TestStubs.Project(),
  631. data: {
  632. version: 'frontend@2.0.0',
  633. resolved_in_version: 'frontend@1.0.0',
  634. follows_semver: true,
  635. },
  636. dateCreated,
  637. },
  638. ],
  639. });
  640. const activity = screen.getAllByTestId('activity-item').at(-1);
  641. expect(activity).toHaveTextContent(
  642. 'Sentry marked this issue as a regression in 2.0.0'
  643. );
  644. expect(activity).toHaveTextContent(
  645. '2.0.0 is greater than or equal to 1.0.0 compared via semver'
  646. );
  647. });
  648. it('renders regression with non-semver description', function () {
  649. createWrapper({
  650. activity: [
  651. {
  652. id: '123',
  653. type: GroupActivityType.SET_REGRESSION,
  654. project: TestStubs.Project(),
  655. data: {
  656. version: 'frontend@abc1',
  657. resolved_in_version: 'frontend@abc2',
  658. follows_semver: false,
  659. },
  660. dateCreated,
  661. },
  662. ],
  663. });
  664. const activity = screen.getAllByTestId('activity-item').at(-1);
  665. expect(activity).toHaveTextContent(
  666. 'Sentry marked this issue as a regression in abc1'
  667. );
  668. expect(activity).toHaveTextContent(
  669. 'abc1 is greater than or equal to abc2 compared via release date'
  670. );
  671. });
  672. });
  673. });