traceLink.spec.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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();
  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. // In issuePlatform, we store the subtitle within the message
  22. message: '/api/slow/ Slow DB Query SELECT "sentry_monitorcheckin"."monitor_id"',
  23. timestamp: '2024-01-24T09:09:03+00:00',
  24. 'issue.id': 1000,
  25. project: project.slug,
  26. 'project.name': project.name,
  27. title: 'Slow DB Query',
  28. id: 'abc',
  29. transaction: '/api/slow/',
  30. },
  31. ],
  32. meta: {fields: {}, units: {}},
  33. };
  34. const discoverBody: TraceEventResponse = {
  35. data: [
  36. {
  37. message: 'This is the subtitle of the issue',
  38. timestamp: '2024-01-23T22:11:42+00:00',
  39. 'issue.id': 4909507143,
  40. project: project.slug,
  41. 'project.name': project.name,
  42. title: 'AttributeError: Something Failed',
  43. id: event.id,
  44. transaction: 'important.task',
  45. 'event.type': 'error',
  46. },
  47. ],
  48. meta: {fields: {}, units: {}},
  49. };
  50. beforeEach(() => {
  51. ProjectsStore.loadInitialData([project]);
  52. });
  53. it('renders the number of issues', async () => {
  54. MockApiClient.addMockResponse({
  55. url: `/organizations/${organization.slug}/events/`,
  56. body: issuePlatformBody,
  57. match: [MockApiClient.matchQuery({dataset: 'issuePlatform'})],
  58. });
  59. MockApiClient.addMockResponse({
  60. url: `/organizations/${organization.slug}/events/`,
  61. body: discoverBody,
  62. match: [MockApiClient.matchQuery({dataset: 'discover'})],
  63. });
  64. render(<TraceLink event={event} />, {organization});
  65. expect(await screen.findByText('View Full Trace')).toBeInTheDocument();
  66. });
  67. it('renders no trace available', async () => {
  68. render(<TraceLink event={EventFixture()} />, {organization});
  69. expect(await screen.findByText('No Trace Available')).toBeInTheDocument();
  70. });
  71. });