traceLink.spec.tsx 2.2 KB

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