spanDescription.spec.tsx 4.2 KB

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