fieldRenderer.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import type {Location} from 'history';
  2. import {LocationFixture} from 'sentry-fixture/locationFixture';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {render, screen} from 'sentry-test/reactTestingLibrary';
  5. import EventView from 'sentry/utils/discover/eventView';
  6. import {FieldRenderer} from './fieldRenderer';
  7. const mockedEventData = {
  8. id: 'spanId',
  9. timestamp: '2024-10-03T10:15:00',
  10. trace: 'traceId',
  11. 'span.op': 'test_op',
  12. 'transaction.id': 'transactionId',
  13. 'transaction.span_id': 'transactionSpanId',
  14. };
  15. describe('FieldRenderer tests', function () {
  16. const organization = OrganizationFixture({
  17. features: ['trace-view-v1'],
  18. });
  19. const location: Location = LocationFixture({
  20. query: {
  21. id: '42',
  22. name: 'best query',
  23. field: ['id', 'timestamp', 'trace', 'span.op', 'transaction.id'],
  24. },
  25. });
  26. const eventView = EventView.fromLocation(location);
  27. beforeAll(() => {
  28. const mockTimestamp = new Date('2024-10-06T00:00:00').getTime();
  29. jest.spyOn(global.Date, 'now').mockImplementation(() => mockTimestamp);
  30. });
  31. afterAll(() => {
  32. jest.restoreAllMocks();
  33. });
  34. it('renders span.op', function () {
  35. render(
  36. <FieldRenderer
  37. column={eventView.getColumns()[3]}
  38. data={mockedEventData}
  39. meta={{}}
  40. />,
  41. {organization}
  42. );
  43. expect(screen.getByText('test_op')).toBeInTheDocument();
  44. });
  45. it('renders span id link to traceview', function () {
  46. render(
  47. <FieldRenderer
  48. column={eventView.getColumns()[0]}
  49. data={mockedEventData}
  50. meta={{}}
  51. />,
  52. {organization}
  53. );
  54. expect(screen.getByText('spanId')).toBeInTheDocument();
  55. expect(screen.getByRole('link')).toHaveAttribute(
  56. 'href',
  57. `/organizations/org-slug/performance/trace/traceId/?node=span-spanId&node=txn-transactionSpanId&source=traces&statsPeriod=14d&targetId=transactionSpanId&timestamp=1727964900`
  58. );
  59. });
  60. it('renders transaction id link to traceview', function () {
  61. render(
  62. <FieldRenderer
  63. column={eventView.getColumns()[4]}
  64. data={mockedEventData}
  65. meta={{}}
  66. />,
  67. {organization}
  68. );
  69. expect(screen.getByText('transactionId')).toBeInTheDocument();
  70. expect(screen.getByRole('link')).toHaveAttribute(
  71. 'href',
  72. `/organizations/org-slug/performance/trace/traceId/?source=traces&statsPeriod=14d&targetId=transactionSpanId&timestamp=1727964900`
  73. );
  74. });
  75. it('renders trace id link to traceview', function () {
  76. render(
  77. <FieldRenderer
  78. column={eventView.getColumns()[2]}
  79. data={mockedEventData}
  80. meta={{}}
  81. />,
  82. {organization}
  83. );
  84. expect(screen.getByText('traceId')).toBeInTheDocument();
  85. expect(screen.getByRole('link')).toHaveAttribute(
  86. 'href',
  87. `/organizations/org-slug/performance/trace/traceId/?source=traces&statsPeriod=14d&timestamp=1727964900`
  88. );
  89. });
  90. it('renders timestamp', function () {
  91. render(
  92. <FieldRenderer
  93. column={eventView.getColumns()[1]}
  94. data={mockedEventData}
  95. meta={{}}
  96. />,
  97. {organization}
  98. );
  99. expect(screen.getByRole('time')).toBeInTheDocument();
  100. expect(screen.getByText('3d ago')).toBeInTheDocument();
  101. });
  102. });