spanDetail.spec.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {SpanFixture} from 'sentry-fixture/span';
  5. import {render, screen} from 'sentry-test/reactTestingLibrary';
  6. import SpanDetail from 'sentry/components/events/interfaces/spans/spanDetail';
  7. import type {EventTransaction} from 'sentry/types/event';
  8. describe('SpanDetail', function () {
  9. const organization = OrganizationFixture();
  10. const project = ProjectFixture();
  11. const trace = {
  12. op: 'http.server',
  13. spans: [],
  14. traceID: '',
  15. traceStartTimestamp: 0,
  16. traceEndTimestamp: 0,
  17. childSpans: {},
  18. rootSpanID: '',
  19. rootSpanStatus: undefined,
  20. };
  21. const event = EventFixture({
  22. title: '/api/0/detail',
  23. projectID: project.id,
  24. startTimestamp: 0,
  25. }) as EventTransaction;
  26. const span = SpanFixture({
  27. op: 'db',
  28. hash: 'a',
  29. description: 'SELECT * FROM users;',
  30. });
  31. function renderSpanDetail(props: Partial<React.ComponentProps<typeof SpanDetail>>) {
  32. return (
  33. <SpanDetail
  34. organization={organization}
  35. event={event}
  36. resetCellMeasureCache={jest.fn()}
  37. scrollToHash={jest.fn()}
  38. isRoot={false}
  39. relatedErrors={[]}
  40. trace={trace}
  41. childTransactions={[]}
  42. span={span}
  43. {...props}
  44. />
  45. );
  46. }
  47. describe('resource spans', function () {
  48. it('shows size fields', function () {
  49. render(
  50. renderSpanDetail({
  51. span: SpanFixture({
  52. op: 'resource.link',
  53. description: 'static.assets/content.js',
  54. data: {
  55. 'http.response_content_length': 132,
  56. 'http.response_transfer_size': 0,
  57. 'http.decoded_response_content_length': null,
  58. },
  59. }),
  60. })
  61. );
  62. expect(
  63. screen.queryByText('http.decoded_response_content_length')
  64. ).not.toBeInTheDocument();
  65. expect(screen.getByText('http.response_transfer_size')).toBeInTheDocument();
  66. expect(screen.getByText('http.response_content_length')).toBeInTheDocument();
  67. expect(screen.getByText('132.0 B')).toBeInTheDocument();
  68. });
  69. });
  70. describe('http.client spans', function () {
  71. it('shows size fields for integer and string values', function () {
  72. render(
  73. renderSpanDetail({
  74. span: SpanFixture({
  75. op: 'http.client',
  76. description: 'POST /resources.json',
  77. data: {
  78. 'http.response_content_length': '143',
  79. 'http.request_content_length': 12,
  80. },
  81. }),
  82. })
  83. );
  84. expect(screen.getByText('http.response_content_length')).toBeInTheDocument();
  85. expect(screen.getByText('143.0 B')).toBeInTheDocument();
  86. expect(screen.getByText('http.request_content_length')).toBeInTheDocument();
  87. expect(screen.getByText('12.0 B')).toBeInTheDocument();
  88. });
  89. });
  90. describe('db spans', function () {
  91. it('renders "Similar Span" button but no Query Details button by default', function () {
  92. render(
  93. renderSpanDetail({
  94. span: SpanFixture({
  95. op: 'db',
  96. hash: 'a',
  97. description: 'SELECT * FROM users;',
  98. }),
  99. })
  100. );
  101. expect(screen.getByText('SELECT * FROM users;')).toBeInTheDocument();
  102. expect(
  103. screen.getByRole('button', {name: 'View Similar Spans'})
  104. ).toBeInTheDocument();
  105. expect(
  106. screen.queryByRole('button', {name: 'View Query Summary'})
  107. ).not.toBeInTheDocument();
  108. });
  109. it('renders "View Query Details" button if "Queries" view is enabled and span group is available', function () {
  110. render(
  111. renderSpanDetail({
  112. span: SpanFixture({
  113. op: 'db',
  114. hash: 'a',
  115. description: 'SELECT * FROM users;',
  116. sentry_tags: {
  117. group: 'a7ebd21614897',
  118. category: 'db',
  119. },
  120. }),
  121. organization: OrganizationFixture({
  122. ...organization,
  123. features: ['insights-initial-modules'],
  124. }),
  125. })
  126. );
  127. expect(screen.getByText('SELECT * FROM users;')).toBeInTheDocument();
  128. expect(
  129. screen.getByRole('button', {name: 'View Similar Spans'})
  130. ).toBeInTheDocument();
  131. expect(
  132. screen.getByRole('button', {name: 'View Query Summary'})
  133. ).toBeInTheDocument();
  134. expect(screen.getByRole('button', {name: 'View Query Summary'})).toHaveAttribute(
  135. 'href',
  136. '/organizations/org-slug/insights/backend/database/spans/span/a7ebd21614897/?project=2'
  137. );
  138. });
  139. });
  140. });