streamGroup.spec.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {act, 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 group1;
  10. beforeEach(function () {
  11. group1 = 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. GroupStore.loadInitialData([group1]);
  30. });
  31. afterEach(function () {
  32. trackAdvancedAnalyticsEvent.mockClear();
  33. GroupStore.reset();
  34. GroupStore.teardown();
  35. });
  36. it('renders with anchors', function () {
  37. const {routerContext} = initializeOrg();
  38. const wrapper = render(
  39. <StreamGroup
  40. id="1337"
  41. orgId="orgId"
  42. groupId="groupId"
  43. lastSeen="2017-07-25T22:56:12Z"
  44. firstSeen="2017-07-01T02:06:02Z"
  45. hasGuideAnchor
  46. {...routerContext}
  47. />,
  48. {context: routerContext}
  49. );
  50. expect(GuideStore.state.anchors).toEqual(new Set(['dynamic_counts', 'issue_stream']));
  51. expect(wrapper.container).toSnapshot();
  52. });
  53. it('marks as reviewed', function () {
  54. const {routerContext, organization} = initializeOrg();
  55. render(
  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. {context: routerContext}
  67. );
  68. expect(screen.getByTestId('group')).toHaveAttribute('data-test-reviewed', 'false');
  69. act(() => GroupStore.onUpdate('', ['1337'], {inbox: false}));
  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. });