spanDescription.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
  4. import {textWithMarkupMatcher} from 'sentry-test/utils';
  5. import {EntryType} from 'sentry/types/event';
  6. import usePageFilters from 'sentry/utils/usePageFilters';
  7. import {DatabaseSpanDescription} from 'sentry/views/insights/common/components/spanDescription';
  8. jest.mock('sentry/utils/usePageFilters');
  9. describe('DatabaseSpanDescription', function () {
  10. const organization = OrganizationFixture();
  11. const project = ProjectFixture();
  12. jest.mocked(usePageFilters).mockReturnValue({
  13. isReady: true,
  14. desyncedFilters: new Set(),
  15. pinnedFilters: new Set(),
  16. shouldPersist: true,
  17. selection: {
  18. datetime: {
  19. period: '10d',
  20. start: null,
  21. end: null,
  22. utc: false,
  23. },
  24. environments: [],
  25. projects: [],
  26. },
  27. });
  28. const groupId = '2ed2abf6ce7e3577';
  29. const spanId = 'abfed2aabf';
  30. const eventId = '65c7d8647b8a76ef8f4c05d41deb7860';
  31. it('shows preliminary description if no more data is available', async function () {
  32. MockApiClient.addMockResponse({
  33. url: `/organizations/${organization.slug}/events/`,
  34. body: [],
  35. });
  36. render(
  37. <DatabaseSpanDescription
  38. groupId={groupId}
  39. preliminaryDescription="SELECT USERS FRO*"
  40. />,
  41. {organization}
  42. );
  43. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  44. expect(screen.getByText('SELECT USERS FRO*')).toBeInTheDocument();
  45. });
  46. it('shows full query if full event is available', async function () {
  47. MockApiClient.addMockResponse({
  48. url: `/organizations/${organization.slug}/events/`,
  49. body: {
  50. data: [
  51. {
  52. 'transaction.id': eventId,
  53. project: project.slug,
  54. span_id: spanId,
  55. },
  56. ],
  57. },
  58. });
  59. MockApiClient.addMockResponse({
  60. url: `/organizations/${organization.slug}/events/${project.slug}:${eventId}/`,
  61. body: {
  62. id: eventId,
  63. entries: [
  64. {
  65. type: EntryType.SPANS,
  66. data: [
  67. {
  68. span_id: spanId,
  69. description: 'SELECT users FROM my_table LIMIT 1;',
  70. },
  71. ],
  72. },
  73. ],
  74. },
  75. });
  76. render(
  77. <DatabaseSpanDescription
  78. groupId={groupId}
  79. preliminaryDescription="SELECT USERS FRO*"
  80. />,
  81. {organization}
  82. );
  83. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  84. expect(
  85. await screen.findByText('SELECT users FROM my_table LIMIT 1;')
  86. ).toBeInTheDocument();
  87. });
  88. it('shows query source if available', async function () {
  89. MockApiClient.addMockResponse({
  90. url: `/organizations/${organization.slug}/events/`,
  91. body: {
  92. data: [
  93. {
  94. 'transaction.id': eventId,
  95. project: project.slug,
  96. span_id: spanId,
  97. },
  98. ],
  99. },
  100. });
  101. MockApiClient.addMockResponse({
  102. url: `/organizations/${organization.slug}/events/${project.slug}:${eventId}/`,
  103. body: {
  104. id: eventId,
  105. entries: [
  106. {
  107. type: EntryType.SPANS,
  108. data: [
  109. {
  110. span_id: spanId,
  111. description: 'SELECT users FROM my_table LIMIT 1;',
  112. data: {
  113. 'code.filepath': '/app/views/users.py',
  114. 'code.lineno': 78,
  115. },
  116. },
  117. ],
  118. },
  119. ],
  120. },
  121. });
  122. render(
  123. <DatabaseSpanDescription
  124. groupId={groupId}
  125. preliminaryDescription="SELECT USERS FRO*"
  126. />,
  127. {organization}
  128. );
  129. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  130. expect(
  131. await screen.findByText('SELECT users FROM my_table LIMIT 1;')
  132. ).toBeInTheDocument();
  133. expect(
  134. screen.getByText(textWithMarkupMatcher('/app/views/users.py at line 78'))
  135. ).toBeInTheDocument();
  136. });
  137. });