123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- import {EventFixture} from 'sentry-fixture/event';
- import {LocationFixture} from 'sentry-fixture/locationFixture';
- import {ProjectFixture} from 'sentry-fixture/project';
- import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
- import {QueryError} from 'sentry/utils/discover/genericDiscoverQuery';
- import type {
- QuickTraceQueryChildrenProps,
- TraceMeta,
- } from 'sentry/utils/performance/quickTrace/types';
- import QuickTraceMeta from 'sentry/views/performance/transactionDetails/quickTraceMeta';
- describe('QuickTraceMeta', function () {
- const location = LocationFixture();
- const project = ProjectFixture({platform: 'javascript'});
- const event = EventFixture({contexts: {trace: {trace_id: 'a'.repeat(32)}}});
- const emptyQuickTrace: QuickTraceQueryChildrenProps = {
- isLoading: false,
- error: null,
- trace: [],
- type: 'empty',
- currentEvent: null,
- };
- const emptyTraceMeta: TraceMeta = {
- projects: 0,
- transactions: 0,
- errors: 0,
- performance_issues: 0,
- };
- it('renders basic UI', function () {
- render(
- <QuickTraceMeta
- event={event}
- project={project}
- location={location}
- quickTrace={emptyQuickTrace}
- traceMeta={emptyTraceMeta}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- />
- );
- expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
- expect(screen.getByTestId('quick-trace-body')).toBeInTheDocument();
- });
- it('renders placeholder while loading', function () {
- render(
- <QuickTraceMeta
- event={event}
- project={project}
- location={location}
- quickTrace={{
- ...emptyQuickTrace,
- isLoading: true,
- }}
- traceMeta={emptyTraceMeta}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- />
- );
- expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
- const qtBody = screen.getByTestId('quick-trace-body');
- expect(within(qtBody).getByTestId('loading-placeholder')).toBeInTheDocument();
- });
- it('renders errors', function () {
- render(
- <QuickTraceMeta
- event={event}
- project={project}
- location={location}
- quickTrace={{
- ...emptyQuickTrace,
- error: new QueryError('something bad'),
- }}
- traceMeta={emptyTraceMeta}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- />
- );
- expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
- expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('\u2014');
- });
- it('renders footer', function () {
- render(
- <QuickTraceMeta
- event={event}
- project={project}
- location={location}
- quickTrace={{
- ...emptyQuickTrace,
- type: 'full',
- trace: [
- {
- event_id: '6c2fa0db524a41b784db2de220f9754c',
- span_id: '9f4d8db340e5b9c2',
- transaction: '/api/0/internal/health/',
- 'transaction.duration': 15,
- project_id: 1,
- project_slug: 'sentry',
- parent_span_id: '87a45c44efdf60d5',
- parent_event_id: null,
- generation: 0,
- errors: [],
- performance_issues: [],
- timestamp: 123213123,
- },
- ],
- }}
- traceMeta={{
- projects: 0,
- transactions: 1,
- errors: 0,
- performance_issues: 0,
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- />
- );
- expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
- expect(screen.getByTestId('quick-trace-body')).toBeInTheDocument();
- expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent(
- `View Full Trace: ${'a'.repeat(8)} (1 event)`
- );
- });
- it('renders missing trace when trace id is not present', function () {
- const newEvent = EventFixture();
- render(
- <QuickTraceMeta
- event={newEvent}
- project={project}
- location={location}
- quickTrace={emptyQuickTrace}
- traceMeta={emptyTraceMeta}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- />
- );
- expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
- expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('Missing Trace');
- expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent('Read the docs');
- });
- it('renders missing trace with hover card when feature disabled', async function () {
- const newEvent = EventFixture();
- render(
- <QuickTraceMeta
- event={newEvent}
- project={project}
- location={location}
- quickTrace={emptyQuickTrace}
- traceMeta={emptyTraceMeta}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- />
- );
- expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
- expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('Missing Trace');
- const qtFooter = screen.getByTestId('quick-trace-footer');
- expect(qtFooter).toHaveTextContent('Read the docs');
- const child = qtFooter.firstChild;
- if (!child) {
- throw new Error('child is null');
- }
- await userEvent.hover(child as HTMLElement);
- expect(
- await screen.findByText('Requires performance monitoring.')
- ).toBeInTheDocument();
- });
- it('does not render when platform does not support tracing', function () {
- const newProject = ProjectFixture();
- const newEvent = EventFixture();
- const result = render(
- <QuickTraceMeta
- event={newEvent}
- project={newProject}
- location={location}
- quickTrace={emptyQuickTrace}
- traceMeta={emptyTraceMeta}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- />
- );
- expect(result.container).toBeEmptyDOMElement();
- });
- });
|