groupActivity.spec.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React from 'react';
  2. import {GroupActivity} from 'app/views/organizationGroupDetails/groupActivity';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {mountWithTheme} from 'sentry-test/enzyme';
  5. import ConfigStore from 'app/stores/configStore';
  6. import GroupStore from 'app/stores/groupStore';
  7. import NoteInput from 'app/components/activity/note/input';
  8. import ProjectsStore from 'app/stores/projectsStore';
  9. describe('GroupActivity', function() {
  10. const project = TestStubs.Project();
  11. const group = TestStubs.Group({
  12. id: '1337',
  13. activity: [
  14. {type: 'note', id: 'note-1', data: {text: 'Test Note'}, user: TestStubs.User()},
  15. ],
  16. project,
  17. });
  18. const {organization, routerContext} = initializeOrg({
  19. group,
  20. });
  21. beforeEach(function() {
  22. ProjectsStore.loadInitialData([project]);
  23. jest.spyOn(ConfigStore, 'get').mockImplementation(key => {
  24. if (key === 'user') {
  25. return {
  26. id: '123',
  27. };
  28. }
  29. return {};
  30. });
  31. });
  32. afterEach(function() {});
  33. it('renders a NoteInput', function() {
  34. const wrapper = mountWithTheme(
  35. <GroupActivity
  36. api={new MockApiClient()}
  37. group={group}
  38. organization={organization}
  39. />,
  40. routerContext
  41. );
  42. expect(wrapper.find(NoteInput)).toHaveLength(1);
  43. });
  44. describe('Delete', function() {
  45. let wrapper;
  46. let deleteMock;
  47. beforeEach(function() {
  48. deleteMock = MockApiClient.addMockResponse({
  49. url: '/issues/1337/comments/note-1/',
  50. method: 'DELETE',
  51. });
  52. wrapper = mountWithTheme(
  53. <GroupActivity
  54. api={new MockApiClient()}
  55. group={group}
  56. organization={organization}
  57. />,
  58. routerContext
  59. );
  60. });
  61. it('should do nothing if not present in GroupStore', function() {
  62. jest.spyOn(GroupStore, 'removeActivity').mockImplementation(() => -1); // not found
  63. // Would rather call simulate on the actual component but it's in a styled component
  64. // that is only visible on hover
  65. wrapper.find('NoteHeader').prop('onDelete')();
  66. expect(deleteMock).not.toHaveBeenCalled();
  67. });
  68. it('should remove remove the item from the GroupStore make a DELETE API request', function() {
  69. jest.spyOn(GroupStore, 'removeActivity').mockImplementation(() => 1);
  70. // Would rather call simulate on the actual component but it's in a styled component
  71. // that is only visible on hover
  72. wrapper.find('NoteHeader').prop('onDelete')();
  73. expect(deleteMock).toHaveBeenCalledTimes(1);
  74. });
  75. });
  76. });