123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- import {EventFixture} from 'sentry-fixture/event';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {ProjectFixture} from 'sentry-fixture/project';
- import {RRWebInitFrameEventsFixture} from 'sentry-fixture/replay/rrweb';
- import {ReplayErrorFixture} from 'sentry-fixture/replayError';
- import {ReplayRecordFixture} from 'sentry-fixture/replayRecord';
- import {render, screen} from 'sentry-test/reactTestingLibrary';
- import EventReplay from 'sentry/components/events/eventReplay';
- import {
- useHasOrganizationSentAnyReplayEvents,
- useReplayOnboardingSidebarPanel,
- } from 'sentry/utils/replays/hooks/useReplayOnboarding';
- import useReplayReader from 'sentry/utils/replays/hooks/useReplayReader';
- import ReplayReader from 'sentry/utils/replays/replayReader';
- import useProjects from 'sentry/utils/useProjects';
- import type {ReplayError} from 'sentry/views/replays/types';
- jest.mock('sentry/utils/replays/hooks/useReplayOnboarding');
- jest.mock('sentry/utils/replays/hooks/useReplayReader');
- jest.mock('sentry/utils/useProjects');
- // Replay clip preview is very heavy, mock it out
- jest.mock(
- 'sentry/components/events/eventReplay/replayClipPreview',
- () =>
- function () {
- return <div data-test-id="replay-clip" />;
- }
- );
- const mockEventTimestamp = new Date('2022-09-22T16:59:41Z');
- const mockReplayId = '761104e184c64d439ee1014b72b4d83b';
- const mockErrors: ReplayError[] = [
- ReplayErrorFixture({
- id: '1',
- issue: 'JAVASCRIPT-101',
- 'issue.id': 101,
- 'error.value': ['Something bad happened.'],
- 'error.type': ['error'],
- 'project.name': 'javascript',
- timestamp: mockEventTimestamp.toISOString(),
- title: 'Something bad happened.',
- }),
- ReplayErrorFixture({
- id: '2',
- issue: 'JAVASCRIPT-102',
- 'issue.id': 102,
- 'error.value': ['Something bad happened 2.'],
- 'error.type': ['error'],
- 'project.name': 'javascript',
- timestamp: mockEventTimestamp.toISOString(),
- title: 'Something bad happened 2.',
- }),
- ];
- const mockReplay = ReplayReader.factory({
- replayRecord: ReplayRecordFixture({
- browser: {
- name: 'Chrome',
- version: '110.0.0',
- },
- }),
- errors: mockErrors,
- attachments: RRWebInitFrameEventsFixture({
- timestamp: new Date('Sep 22, 2022 4:58:39 PM UTC'),
- }),
- });
- jest.mocked(useReplayReader).mockImplementation(() => {
- return {
- attachments: [],
- errors: mockErrors,
- fetchError: undefined,
- fetching: false,
- onRetry: jest.fn(),
- projectSlug: ProjectFixture().slug,
- replay: mockReplay,
- replayId: mockReplayId,
- replayRecord: ReplayRecordFixture(),
- };
- });
- const mockIsFullscreen = jest.fn();
- jest.mock('screenfull', () => ({
- enabled: true,
- get isFullscreen() {
- return mockIsFullscreen();
- },
- request: jest.fn(),
- exit: jest.fn(),
- on: jest.fn(),
- off: jest.fn(),
- }));
- describe('EventReplay', function () {
- const MockUseReplayOnboardingSidebarPanel = jest.mocked(
- useReplayOnboardingSidebarPanel
- );
- const MockUseHasOrganizationSentAnyReplayEvents = jest.mocked(
- useHasOrganizationSentAnyReplayEvents
- );
- const organization = OrganizationFixture({
- features: ['session-replay'],
- });
- const mockEvent = EventFixture({
- entries: [],
- tags: [],
- platform: 'javascript',
- dateCreated: mockEventTimestamp.getTime(),
- });
- const defaultProps = {
- event: mockEvent,
- projectSlug: 'project-slug',
- };
- beforeEach(function () {
- const project = ProjectFixture({platform: 'javascript'});
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/replay-count/`,
- method: 'GET',
- body: {},
- });
- jest.mocked(useProjects).mockReturnValue({
- fetchError: null,
- fetching: false,
- hasMore: false,
- initiallyLoaded: false,
- onSearch: () => Promise.resolve(),
- placeholders: [],
- projects: [project],
- });
- MockUseHasOrganizationSentAnyReplayEvents.mockReturnValue({
- hasOrgSentReplays: false,
- fetching: false,
- });
- MockUseReplayOnboardingSidebarPanel.mockReturnValue({
- activateSidebar: jest.fn(),
- });
- });
- it('should render the replay inline onboarding component when replays are enabled and the project supports replay', async function () {
- MockUseHasOrganizationSentAnyReplayEvents.mockReturnValue({
- hasOrgSentReplays: false,
- fetching: false,
- });
- MockUseReplayOnboardingSidebarPanel.mockReturnValue({
- activateSidebar: jest.fn(),
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/prompts-activity/',
- body: {data: {dismissed_ts: null}},
- });
- render(<EventReplay {...defaultProps} />, {organization});
- expect(
- await screen.findByText('Watch the errors and latency issues your users face')
- ).toBeInTheDocument();
- });
- it('should render a replay when there is a replayId from tags', async function () {
- MockUseHasOrganizationSentAnyReplayEvents.mockReturnValue({
- hasOrgSentReplays: true,
- fetching: false,
- });
- MockUseReplayOnboardingSidebarPanel.mockReturnValue({
- activateSidebar: jest.fn(),
- });
- render(
- <EventReplay
- {...defaultProps}
- event={EventFixture({
- entries: [],
- tags: [{key: 'replayId', value: '761104e184c64d439ee1014b72b4d83b'}],
- platform: 'javascript',
- })}
- />,
- {organization}
- );
- expect(await screen.findByTestId('replay-clip')).toBeInTheDocument();
- });
- it('should render a replay when there is a replay_id from contexts', async function () {
- MockUseHasOrganizationSentAnyReplayEvents.mockReturnValue({
- hasOrgSentReplays: true,
- fetching: false,
- });
- MockUseReplayOnboardingSidebarPanel.mockReturnValue({
- activateSidebar: jest.fn(),
- });
- render(
- <EventReplay
- {...defaultProps}
- event={EventFixture({
- entries: [],
- tags: [],
- contexts: {
- replay: {
- replay_id: '761104e184c64d439ee1014b72b4d83b',
- },
- },
- platform: 'javascript',
- })}
- />,
- {organization}
- );
- expect(await screen.findByTestId('replay-clip')).toBeInTheDocument();
- });
- });
|