streamGroup.spec.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import StreamGroup from 'sentry/components/stream/group';
  4. import GroupStore from 'sentry/stores/groupStore';
  5. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  6. jest.mock('sentry/utils/analytics/trackAdvancedAnalyticsEvent');
  7. describe('StreamGroup', function () {
  8. let GROUP_1;
  9. beforeEach(function () {
  10. GROUP_1 = TestStubs.Group({
  11. id: '1337',
  12. project: {
  13. id: '13',
  14. slug: 'foo-project',
  15. },
  16. type: 'error',
  17. inbox: {
  18. date_added: '2020-11-24T13:17:42.248751Z',
  19. reason: 0,
  20. reason_details: null,
  21. },
  22. });
  23. MockApiClient.addMockResponse({
  24. url: '/organizations/org-slug/projects/',
  25. query: 'foo',
  26. body: [TestStubs.Project({slug: 'foo-project'})],
  27. });
  28. jest.spyOn(GroupStore, 'get').mockImplementation(() => GROUP_1);
  29. });
  30. afterEach(function () {
  31. trackAdvancedAnalyticsEvent.mockClear();
  32. });
  33. it('renders with anchors', async function () {
  34. const {routerContext} = initializeOrg();
  35. const component = mountWithTheme(
  36. <StreamGroup
  37. id="1L"
  38. orgId="orgId"
  39. groupId="groupId"
  40. lastSeen="2017-07-25T22:56:12Z"
  41. firstSeen="2017-07-01T02:06:02Z"
  42. hasGuideAnchor
  43. {...routerContext}
  44. />,
  45. routerContext
  46. );
  47. component.update();
  48. await tick();
  49. expect(component.find('GuideAnchor').exists()).toBe(true);
  50. expect(component.find('GuideAnchor')).toHaveLength(3);
  51. expect(component).toSnapshot();
  52. });
  53. it('marks as reviewed', function () {
  54. const {routerContext, organization} = initializeOrg();
  55. const wrapper = mountWithTheme(
  56. <StreamGroup
  57. id="1337"
  58. orgId="orgId"
  59. groupId="groupId"
  60. lastSeen="2017-07-25T22:56:12Z"
  61. firstSeen="2017-07-01T02:06:02Z"
  62. query="is:unresolved is:for_review assigned_or_suggested:[me, none]"
  63. organization={organization}
  64. {...routerContext}
  65. />,
  66. routerContext
  67. );
  68. const streamGroup = wrapper.find('StreamGroup');
  69. expect(streamGroup.state('reviewed')).toBe(false);
  70. GROUP_1.inbox = false;
  71. streamGroup.instance().onGroupChange(new Set(['1337']));
  72. expect(streamGroup.state('reviewed')).toBe(true);
  73. });
  74. it('tracks clicks from issues stream', function () {
  75. const {routerContext, organization} = initializeOrg();
  76. const wrapper = mountWithTheme(
  77. <StreamGroup
  78. id="1337"
  79. orgId="orgId"
  80. groupId="groupId"
  81. lastSeen="2017-07-25T22:56:12Z"
  82. firstSeen="2017-07-01T02:06:02Z"
  83. query="is:unresolved is:for_review assigned_or_suggested:[me, none]"
  84. organization={organization}
  85. {...routerContext}
  86. />,
  87. routerContext
  88. );
  89. wrapper.find('GlobalSelectionLink').simulate('click');
  90. expect(trackAdvancedAnalyticsEvent).toHaveBeenCalledTimes(2);
  91. });
  92. });