groupActivity.spec.jsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {act} from 'sentry-test/reactTestingLibrary';
  4. import NoteInput from 'sentry/components/activity/note/input';
  5. import ConfigStore from 'sentry/stores/configStore';
  6. import GroupStore from 'sentry/stores/groupStore';
  7. import OrganizationStore from 'sentry/stores/organizationStore';
  8. import ProjectsStore from 'sentry/stores/projectsStore';
  9. import TeamStore from 'sentry/stores/teamStore';
  10. import {GroupActivity} from 'sentry/views/organizationGroupDetails/groupActivity';
  11. describe('GroupActivity', function () {
  12. let project;
  13. beforeEach(function () {
  14. project = TestStubs.Project();
  15. act(() => ProjectsStore.loadInitialData([project]));
  16. jest.spyOn(ConfigStore, 'get').mockImplementation(key => {
  17. if (key === 'user') {
  18. return {
  19. id: '123',
  20. };
  21. }
  22. return {};
  23. });
  24. });
  25. function createWrapper({activity, organization: additionalOrg} = {}) {
  26. const group = TestStubs.Group({
  27. id: '1337',
  28. activity: activity || [
  29. {type: 'note', id: 'note-1', data: {text: 'Test Note'}, user: TestStubs.User()},
  30. ],
  31. project,
  32. });
  33. const {organization, routerContext} = initializeOrg({
  34. organization: additionalOrg,
  35. group,
  36. });
  37. act(() => TeamStore.loadInitialData([TestStubs.Team({id: '999', slug: 'no-team'})]));
  38. act(() => OrganizationStore.onUpdate(organization, {replace: true}));
  39. return mountWithTheme(
  40. <GroupActivity
  41. api={new MockApiClient()}
  42. params={{orgId: 'org-slug'}}
  43. group={group}
  44. organization={organization}
  45. />,
  46. routerContext
  47. );
  48. }
  49. it('renders a NoteInput', function () {
  50. const wrapper = createWrapper();
  51. expect(wrapper.find(NoteInput)).toHaveLength(1);
  52. });
  53. it('renders a marked reviewed activity', function () {
  54. const wrapper = createWrapper({
  55. activity: [
  56. {type: 'mark_reviewed', id: 'reviewed-1', data: {}, user: TestStubs.User()},
  57. ],
  58. });
  59. expect(wrapper.find('GroupActivityItem').text()).toContain(
  60. 'marked this issue as reviewed'
  61. );
  62. });
  63. it('renders a assigned to self activity', function () {
  64. const user = TestStubs.User({id: '301', name: 'Mark'});
  65. const wrapper = createWrapper({
  66. activity: [
  67. {
  68. data: {
  69. assignee: user.id,
  70. assigneeEmail: user.email,
  71. assigneeType: 'user',
  72. },
  73. dateCreated: '2021-10-01T15:31:38.950115Z',
  74. id: '117',
  75. type: 'assigned',
  76. user,
  77. },
  78. ],
  79. });
  80. expect(wrapper.find('GroupActivityItem').text()).toContain(
  81. 'assigned this issue to themselves'
  82. );
  83. });
  84. it('requests assignees that are not in the team store', async function () {
  85. const team = TestStubs.Team({id: '123', name: 'workflow'});
  86. const teamRequest = MockApiClient.addMockResponse({
  87. url: `/organizations/org-slug/teams/`,
  88. body: [team],
  89. });
  90. const wrapper = createWrapper({
  91. activity: [
  92. {
  93. id: '123',
  94. user: null,
  95. type: 'assigned',
  96. data: {
  97. assignee: team.id,
  98. assigneeEmail: null,
  99. assigneeType: 'team',
  100. },
  101. dateCreated: '2021-10-28T13:40:10.634821Z',
  102. },
  103. ],
  104. });
  105. await act(() => tick());
  106. wrapper.update();
  107. expect(teamRequest).toHaveBeenCalledTimes(1);
  108. expect(wrapper.find('GroupActivityItem').text()).toContain(
  109. 'assigned this issue to #team-slug'
  110. );
  111. });
  112. describe('Delete', function () {
  113. let wrapper;
  114. let deleteMock;
  115. beforeEach(function () {
  116. deleteMock = MockApiClient.addMockResponse({
  117. url: '/issues/1337/comments/note-1/',
  118. method: 'DELETE',
  119. });
  120. wrapper = createWrapper();
  121. });
  122. it('should do nothing if not present in GroupStore', function () {
  123. jest.spyOn(GroupStore, 'removeActivity').mockImplementation(() => -1); // not found
  124. // Would rather call simulate on the actual component but it's in a styled component
  125. // that is only visible on hover
  126. wrapper.find('NoteHeader').prop('onDelete')();
  127. expect(deleteMock).not.toHaveBeenCalled();
  128. });
  129. it('should remove remove the item from the GroupStore make a DELETE API request', function () {
  130. jest.spyOn(GroupStore, 'removeActivity').mockImplementation(() => 1);
  131. // Would rather call simulate on the actual component but it's in a styled component
  132. // that is only visible on hover
  133. wrapper.find('NoteHeader').prop('onDelete')();
  134. expect(deleteMock).toHaveBeenCalledTimes(1);
  135. });
  136. });
  137. });