spanDescription.spec.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {Project} 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 = Organization({
  13. features: ['performance-database-view-query-source'],
  14. });
  15. jest.mocked(useOrganization).mockReturnValue(organization);
  16. const project = Project();
  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(screen.getByText('SELECT users FROM my_table LIMIT 1;')).toBeInTheDocument();
  88. });
  89. it('shows query source if available', async function () {
  90. MockApiClient.addMockResponse({
  91. url: `/organizations/${organization.slug}/events/`,
  92. body: {
  93. data: [
  94. {
  95. 'transaction.id': eventId,
  96. project: project.slug,
  97. span_id: spanId,
  98. },
  99. ],
  100. },
  101. });
  102. MockApiClient.addMockResponse({
  103. url: `/organizations/${organization.slug}/events/${project.slug}:${eventId}/`,
  104. body: {
  105. id: eventId,
  106. entries: [
  107. {
  108. type: EntryType.SPANS,
  109. data: [
  110. {
  111. span_id: spanId,
  112. description: 'SELECT users FROM my_table LIMIT 1;',
  113. data: {
  114. 'code.filepath': '/app/views/users.py',
  115. 'code.lineno': 78,
  116. },
  117. },
  118. ],
  119. },
  120. ],
  121. },
  122. });
  123. render(
  124. <DatabaseSpanDescription
  125. groupId={groupId}
  126. preliminaryDescription="SELECT USERS FRO*"
  127. />,
  128. {organization}
  129. );
  130. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  131. expect(screen.getByText('SELECT users FROM my_table LIMIT 1;')).toBeInTheDocument();
  132. expect(
  133. screen.getByText(textWithMarkupMatcher('/app/views/users.py at line 78'))
  134. ).toBeInTheDocument();
  135. });
  136. });