import {initializeOrg} from 'sentry-test/initializeOrg';
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
import StreamGroup from 'sentry/components/stream/group';
import GroupStore from 'sentry/stores/groupStore';
import GuideStore from 'sentry/stores/guideStore';
import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
jest.mock('sentry/utils/analytics/trackAdvancedAnalyticsEvent');
describe('StreamGroup', function () {
let GROUP_1;
beforeEach(function () {
GROUP_1 = TestStubs.Group({
id: '1337',
project: {
id: '13',
slug: 'foo-project',
},
type: 'error',
inbox: {
date_added: '2020-11-24T13:17:42.248751Z',
reason: 0,
reason_details: null,
},
});
MockApiClient.addMockResponse({
url: '/organizations/org-slug/projects/',
query: 'foo',
body: [TestStubs.Project({slug: 'foo-project'})],
});
jest.spyOn(GroupStore, 'get').mockImplementation(() => GROUP_1);
});
afterEach(function () {
trackAdvancedAnalyticsEvent.mockClear();
GroupStore.teardown();
});
it('renders with anchors', function () {
const {routerContext} = initializeOrg();
const wrapper = render(
,
{context: routerContext}
);
expect(GuideStore.state.anchors).toEqual(new Set(['dynamic_counts', 'issue_stream']));
expect(wrapper.container).toSnapshot();
});
it('marks as reviewed', function () {
const {routerContext, organization} = initializeOrg();
render(
,
{context: routerContext}
);
expect(screen.getByTestId('group')).toHaveAttribute('data-test-reviewed', 'false');
GROUP_1.inbox = false;
GroupStore.trigger(new Set(['1337']));
// Reviewed only applies styles, difficult to select with RTL
expect(screen.getByTestId('group')).toHaveAttribute('data-test-reviewed', 'true');
});
it('tracks clicks from issues stream', function () {
const {routerContext, organization} = initializeOrg();
render(
,
{context: routerContext}
);
userEvent.click(screen.getByText('RequestError'));
expect(trackAdvancedAnalyticsEvent).toHaveBeenCalledTimes(2);
});
});