index.spec.jsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React from 'react';
  2. import {shallow} from 'enzyme';
  3. import GroupActivity from 'app/views/groupDetails/shared/groupActivity';
  4. import NoteInput from 'app/components/activity/noteInput';
  5. import ConfigStore from 'app/stores/configStore';
  6. import GroupStore from 'app/stores/groupStore';
  7. describe('GroupActivity', function() {
  8. let sandbox;
  9. beforeEach(function() {
  10. sandbox = sinon.sandbox.create();
  11. sandbox
  12. .stub(ConfigStore, 'get')
  13. .withArgs('user')
  14. .returns({id: '123'});
  15. });
  16. afterEach(function() {
  17. sandbox.restore();
  18. });
  19. it('renders a NoteInput', function() {
  20. let wrapper = shallow(<GroupActivity group={{id: '1337', activity: []}} />, {
  21. context: {
  22. group: {id: '1337'},
  23. project: TestStubs.Project(),
  24. team: {id: '1'},
  25. organization: {id: 'bar'},
  26. },
  27. });
  28. expect(wrapper.find(NoteInput)).toHaveLength(1);
  29. });
  30. describe('onNoteDelete()', function() {
  31. let instance;
  32. beforeEach(function() {
  33. instance = shallow(<GroupActivity group={{id: '1337', activity: []}} />, {
  34. context: {
  35. group: {id: '1337'},
  36. project: TestStubs.Project(),
  37. team: {id: '1'},
  38. organization: {id: 'bar'},
  39. },
  40. }).instance();
  41. });
  42. it('should do nothing if not present in GroupStore', function() {
  43. sandbox.stub(GroupStore, 'removeActivity').returns(-1); // not found
  44. let request = sandbox.stub(instance.api, 'request');
  45. instance.onNoteDelete({id: 1});
  46. expect(request.calledOnce).not.toBeTruthy();
  47. });
  48. it('should remove remove the item from the GroupStore make a DELETE API request', function() {
  49. sandbox.stub(GroupStore, 'removeActivity').returns(1);
  50. let request = sandbox.stub(instance.api, 'request');
  51. instance.onNoteDelete({id: 1});
  52. expect(request.calledOnce).toBeTruthy();
  53. expect(request.getCall(0).args[0]).toEqual('/issues/1337/comments/1/');
  54. expect(request.getCall(0).args[1]).toHaveProperty('method', 'DELETE');
  55. });
  56. });
  57. });