123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- import {EventFixture} from 'sentry-fixture/event';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {ProjectFixture} from 'sentry-fixture/project';
- import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
- import ProjectsStore from 'sentry/stores/projectsStore';
- import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
- import {TraceTimeline} from './traceTimeline';
- import type {TraceEventResponse} from './useTraceTimelineEvents';
- jest.mock('sentry/utils/routeAnalytics/useRouteAnalyticsParams');
- describe('TraceTimeline', () => {
- const organization = OrganizationFixture();
- const event = EventFixture({
- dateCreated: '2024-01-24T09:09:03+00:00',
- contexts: {
- trace: {
- trace_id: '123',
- },
- },
- });
- const project = ProjectFixture();
- const emptyBody: TraceEventResponse = {data: [], meta: {fields: {}, units: {}}};
- const issuePlatformBody: TraceEventResponse = {
- data: [
- {
- timestamp: '2024-01-24T09:09:03+00:00',
- 'issue.id': 1000,
- project: project.slug,
- 'project.name': project.name,
- title: 'Slow DB Query',
- id: 'abc',
- transaction: '/api/slow/',
- },
- ],
- meta: {fields: {}, units: {}},
- };
- const discoverBody: TraceEventResponse = {
- data: [
- {
- timestamp: '2024-01-23T22:11:42+00:00',
- 'issue.id': 4909507143,
- project: project.slug,
- 'project.name': project.name,
- title: 'AttributeError: Something Failed',
- id: event.id,
- transaction: 'important.task',
- 'event.type': 'error',
- 'stack.function': ['important.task', 'task.run'],
- },
- ],
- meta: {fields: {}, units: {}},
- };
- beforeEach(() => {
- ProjectsStore.loadInitialData([project]);
- jest.clearAllMocks();
- });
- it('renders items and highlights the current event', async () => {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: issuePlatformBody,
- match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: discoverBody,
- match: [MockApiClient.matchQuery({dataset: 'discover'})],
- });
- render(<TraceTimeline event={event} />, {organization});
- expect(await screen.findByLabelText('Current Event')).toBeInTheDocument();
- await userEvent.hover(screen.getByTestId('trace-timeline-tooltip-1'));
- expect(await screen.findByText('You are here')).toBeInTheDocument();
- expect(useRouteAnalyticsParams).toHaveBeenCalledWith({
- trace_timeline_status: 'shown',
- });
- });
- it('displays nothing if the only event is the current event', async () => {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: emptyBody,
- match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: discoverBody,
- match: [MockApiClient.matchQuery({dataset: 'discover'})],
- });
- const {container} = render(<TraceTimeline event={event} />, {organization});
- await waitFor(() =>
- expect(useRouteAnalyticsParams).toHaveBeenCalledWith({
- trace_timeline_status: 'empty',
- })
- );
- expect(container).toBeEmptyDOMElement();
- });
- it('displays nothing if there are no events', async () => {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: emptyBody,
- match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: emptyBody,
- match: [MockApiClient.matchQuery({dataset: 'discover'})],
- });
- const {container} = render(<TraceTimeline event={event} />, {organization});
- await waitFor(() =>
- expect(useRouteAnalyticsParams).toHaveBeenCalledWith({
- trace_timeline_status: 'empty',
- })
- );
- expect(container).toBeEmptyDOMElement();
- });
- it('shows seconds for very short timelines', async () => {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: issuePlatformBody,
- match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: emptyBody,
- match: [MockApiClient.matchQuery({dataset: 'discover'})],
- });
- render(<TraceTimeline event={event} />, {organization});
- // Checking for the presence of seconds
- expect(await screen.findAllByText(/\d{1,2}:\d{2}:\d{2} (AM|PM)/)).toHaveLength(5);
- });
- it('adds the current event if not in the api response', async () => {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: issuePlatformBody,
- match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: emptyBody,
- match: [MockApiClient.matchQuery({dataset: 'discover'})],
- });
- render(<TraceTimeline event={event} />, {organization});
- expect(await screen.findByLabelText('Current Event')).toBeInTheDocument();
- });
- it('skips the timeline and shows related issues (2 issues)', async () => {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: issuePlatformBody,
- match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: discoverBody,
- match: [MockApiClient.matchQuery({dataset: 'discover'})],
- });
- // I believe the call to projects is to determine what projects a user belongs to
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [],
- });
- render(<TraceTimeline event={event} />, {
- organization: OrganizationFixture({
- features: ['related-issues-issue-details-page'],
- }),
- });
- // Instead of a timeline, we should see related issues
- expect(await screen.findByText('Slow DB Query')).toBeInTheDocument();
- expect(
- await screen.findByText('AttributeError: Something Failed')
- ).toBeInTheDocument();
- expect(screen.queryByLabelText('Current Event')).not.toBeInTheDocument();
- expect(useRouteAnalyticsParams).toHaveBeenCalledWith({
- trace_timeline_status: 'empty',
- });
- let element = await screen.getByTestId('this-event-1');
- expect(element).toHaveTextContent('This event');
- element = await screen.getByTestId('this-event-abc');
- expect(element).toHaveTextContent('');
- });
- it('skips the timeline and shows NO related issues (only 1 issue)', async () => {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- body: emptyBody,
- match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events/`,
- // Only 1 issue
- body: discoverBody,
- match: [MockApiClient.matchQuery({dataset: 'discover'})],
- });
- // I believe the call to projects is to determine what projects a user belongs to
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [],
- });
- render(<TraceTimeline event={event} />, {
- organization: OrganizationFixture({
- features: ['related-issues-issue-details-page'],
- }),
- });
- // We do not display any related issues because we only have 1 issue
- expect(await screen.queryByText('Slow DB Query')).not.toBeInTheDocument();
- expect(
- await screen.queryByText('AttributeError: Something Failed')
- ).not.toBeInTheDocument();
- // We do not display the timeline because we only have 1 event
- expect(await screen.queryByLabelText('Current Event')).not.toBeInTheDocument();
- expect(useRouteAnalyticsParams).toHaveBeenCalledWith({
- trace_timeline_status: 'empty',
- });
- });
- });
|