group.spec.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. });
  35. it('renders with anchors', function () {
  36. const {routerContext, organization} = initializeOrg();
  37. const wrapper = render(<StreamGroup id="1337" hasGuideAnchor {...routerContext} />, {
  38. context: routerContext,
  39. organization,
  40. });
  41. expect(GuideStore.state.anchors).toEqual(new Set(['dynamic_counts', 'issue_stream']));
  42. expect(wrapper.container).toSnapshot();
  43. });
  44. it('marks as reviewed', function () {
  45. const {routerContext, organization} = initializeOrg();
  46. render(
  47. <StreamGroup
  48. id="1337"
  49. query="is:unresolved is:for_review assigned_or_suggested:[me, none]"
  50. {...routerContext}
  51. />,
  52. {context: routerContext, organization}
  53. );
  54. expect(screen.getByTestId('group')).toHaveAttribute('data-test-reviewed', 'false');
  55. const data = {inbox: false};
  56. act(() => GroupStore.onUpdate('1337', undefined, data));
  57. act(() => GroupStore.onUpdateSuccess('1337', undefined, data));
  58. // Reviewed only applies styles, difficult to select with RTL
  59. expect(screen.getByTestId('group')).toHaveAttribute('data-test-reviewed', 'true');
  60. });
  61. it('marks as resolved', function () {
  62. const {routerContext, organization} = initializeOrg();
  63. render(<StreamGroup id="1337" query="is:unresolved" />, {
  64. context: routerContext,
  65. organization,
  66. });
  67. expect(screen.queryByTestId('resolved-issue')).not.toBeInTheDocument();
  68. const data = {status: 'resolved', statusDetails: {}};
  69. act(() => GroupStore.onUpdate('1337', undefined, data));
  70. act(() => GroupStore.onUpdateSuccess('1337', undefined, data));
  71. expect(screen.getByTestId('resolved-issue')).toBeInTheDocument();
  72. });
  73. it('tracks clicks from issues stream', function () {
  74. const {routerContext, organization} = initializeOrg();
  75. render(
  76. <StreamGroup
  77. id="1337"
  78. query="is:unresolved is:for_review assigned_or_suggested:[me, none]"
  79. {...routerContext}
  80. />,
  81. {context: routerContext, organization}
  82. );
  83. userEvent.click(screen.getByText('RequestError'));
  84. expect(trackAdvancedAnalyticsEvent).toHaveBeenCalledTimes(2);
  85. });
  86. });