streamGroup.spec.jsx 3.0 KB

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