traceLink.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {render, screen} from 'sentry-test/reactTestingLibrary';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import {TraceLink} from './traceLink';
  7. import type {TraceEventResponse} from './useTraceTimelineEvents';
  8. describe('TraceLink', () => {
  9. const organization = OrganizationFixture({features: ['issues-trace-timeline']});
  10. const event = EventFixture({
  11. contexts: {
  12. trace: {
  13. trace_id: '123',
  14. },
  15. },
  16. });
  17. const project = ProjectFixture();
  18. const issuePlatformBody: TraceEventResponse = {
  19. data: [
  20. {
  21. timestamp: '2024-01-24T09:09:03+00:00',
  22. 'issue.id': 1000,
  23. project: project.slug,
  24. 'project.name': project.name,
  25. title: 'Slow DB Query',
  26. id: 'abc',
  27. issue: 'SENTRY-ABC1',
  28. transaction: '/api/slow/',
  29. },
  30. ],
  31. meta: {fields: {}, units: {}},
  32. };
  33. const discoverBody: TraceEventResponse = {
  34. data: [
  35. {
  36. timestamp: '2024-01-23T22:11:42+00:00',
  37. 'issue.id': 4909507143,
  38. project: project.slug,
  39. 'project.name': project.name,
  40. title: 'AttributeError: Something Failed',
  41. id: event.id,
  42. issue: 'SENTRY-2EYS',
  43. transaction: 'important.task',
  44. 'event.type': 'error',
  45. },
  46. ],
  47. meta: {fields: {}, units: {}},
  48. };
  49. beforeEach(() => {
  50. ProjectsStore.loadInitialData([project]);
  51. });
  52. it('renders the number of issues', async () => {
  53. MockApiClient.addMockResponse({
  54. url: `/organizations/${organization.slug}/events/`,
  55. body: issuePlatformBody,
  56. match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
  57. });
  58. MockApiClient.addMockResponse({
  59. url: `/organizations/${organization.slug}/events/`,
  60. body: discoverBody,
  61. match: [MockApiClient.matchQuery({dataset: 'discover'})],
  62. });
  63. render(<TraceLink event={event} />, {organization});
  64. expect(
  65. await screen.findByRole('link', {name: 'View Full Trace (2 issues)'})
  66. ).toBeInTheDocument();
  67. });
  68. it('renders no trace available', async () => {
  69. render(<TraceLink event={EventFixture({})} />, {organization});
  70. expect(await screen.findByText('No Trace Available')).toBeInTheDocument();
  71. });
  72. });