spanDescription.spec.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 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. jest.mocked(useOrganization).mockReturnValue(organization);
  14. const project = ProjectFixture();
  15. jest.mocked(usePageFilters).mockReturnValue({
  16. isReady: true,
  17. desyncedFilters: new Set(),
  18. pinnedFilters: new Set(),
  19. shouldPersist: true,
  20. selection: {
  21. datetime: {
  22. period: '10d',
  23. start: null,
  24. end: null,
  25. utc: false,
  26. },
  27. environments: [],
  28. projects: [],
  29. },
  30. });
  31. const groupId = '2ed2abf6ce7e3577';
  32. const spanId = 'abfed2aabf';
  33. const eventId = '65c7d8647b8a76ef8f4c05d41deb7860';
  34. it('shows preliminary description if no more data is available', async function () {
  35. MockApiClient.addMockResponse({
  36. url: `/organizations/${organization.slug}/events/`,
  37. body: [],
  38. });
  39. render(
  40. <DatabaseSpanDescription
  41. groupId={groupId}
  42. preliminaryDescription="SELECT USERS FRO*"
  43. />
  44. );
  45. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  46. expect(screen.getByText('SELECT USERS FRO*')).toBeInTheDocument();
  47. });
  48. it('shows full query if full event is available', async function () {
  49. MockApiClient.addMockResponse({
  50. url: `/organizations/${organization.slug}/events/`,
  51. body: {
  52. data: [
  53. {
  54. 'transaction.id': eventId,
  55. project: project.slug,
  56. span_id: spanId,
  57. },
  58. ],
  59. },
  60. });
  61. MockApiClient.addMockResponse({
  62. url: `/organizations/${organization.slug}/events/${project.slug}:${eventId}/`,
  63. body: {
  64. id: eventId,
  65. entries: [
  66. {
  67. type: EntryType.SPANS,
  68. data: [
  69. {
  70. span_id: spanId,
  71. description: 'SELECT users FROM my_table LIMIT 1;',
  72. },
  73. ],
  74. },
  75. ],
  76. },
  77. });
  78. render(
  79. <DatabaseSpanDescription
  80. groupId={groupId}
  81. preliminaryDescription="SELECT USERS FRO*"
  82. />
  83. );
  84. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  85. expect(
  86. await screen.findByText('SELECT users FROM my_table LIMIT 1;')
  87. ).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(
  132. await screen.findByText('SELECT users FROM my_table LIMIT 1;')
  133. ).toBeInTheDocument();
  134. expect(
  135. screen.getByText(textWithMarkupMatcher('/app/views/users.py at line 78'))
  136. ).toBeInTheDocument();
  137. });
  138. });