group.spec.jsx 3.3 KB

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