index.spec.tsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {generateSuspectSpansResponse} from 'sentry-test/performance/initializePerformanceData';
  3. import {act, render, screen, within} from 'sentry-test/reactTestingLibrary';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. import TransactionSpans from 'sentry/views/performance/transactionSummary/transactionSpans';
  6. import {
  7. SpanSortOthers,
  8. SpanSortPercentiles,
  9. } from 'sentry/views/performance/transactionSummary/transactionSpans/types';
  10. function initializeData({query} = {query: {}}) {
  11. const features = ['performance-view', 'performance-suspect-spans-view'];
  12. const organization = TestStubs.Organization({
  13. features,
  14. projects: [TestStubs.Project()],
  15. });
  16. const initialData = initializeOrg({
  17. ...initializeOrg(),
  18. organization,
  19. router: {
  20. location: {
  21. query: {
  22. transaction: 'Test Transaction',
  23. project: '1',
  24. ...query,
  25. },
  26. },
  27. },
  28. });
  29. act(() => void ProjectsStore.loadInitialData(initialData.organization.projects));
  30. return initialData;
  31. }
  32. describe('Performance > Transaction Spans', function () {
  33. let eventsMock;
  34. let eventsSpanOpsMock;
  35. let eventsSpansPerformanceMock;
  36. beforeEach(function () {
  37. MockApiClient.addMockResponse({
  38. url: '/organizations/org-slug/projects/',
  39. body: [],
  40. });
  41. MockApiClient.addMockResponse({
  42. url: '/prompts-activity/',
  43. body: {},
  44. });
  45. MockApiClient.addMockResponse({
  46. url: '/organizations/org-slug/sdk-updates/',
  47. body: [],
  48. });
  49. MockApiClient.addMockResponse({
  50. url: '/organizations/org-slug/events-has-measurements/',
  51. body: {measurements: false},
  52. });
  53. eventsMock = MockApiClient.addMockResponse({
  54. url: '/organizations/org-slug/events/',
  55. body: [{'count()': 100}],
  56. });
  57. eventsSpanOpsMock = MockApiClient.addMockResponse({
  58. url: '/organizations/org-slug/events-span-ops/',
  59. body: [],
  60. });
  61. });
  62. afterEach(function () {
  63. MockApiClient.clearMockResponses();
  64. ProjectsStore.reset();
  65. });
  66. describe('Without Span Data', function () {
  67. beforeEach(function () {
  68. eventsSpansPerformanceMock = MockApiClient.addMockResponse({
  69. url: '/organizations/org-slug/events-spans-performance/',
  70. body: [],
  71. });
  72. });
  73. it('renders empty state', async function () {
  74. const initialData = initializeData({
  75. query: {sort: SpanSortOthers.SUM_EXCLUSIVE_TIME},
  76. });
  77. render(<TransactionSpans location={initialData.router.location} />, {
  78. context: initialData.routerContext,
  79. organization: initialData.organization,
  80. });
  81. expect(
  82. await screen.findByText('No results found for your query')
  83. ).toBeInTheDocument();
  84. });
  85. });
  86. describe('With Span Data', function () {
  87. beforeEach(function () {
  88. eventsSpansPerformanceMock = MockApiClient.addMockResponse({
  89. url: '/organizations/org-slug/events-spans-performance/',
  90. body: generateSuspectSpansResponse({examples: 0}),
  91. });
  92. });
  93. it('renders basic UI elements', async function () {
  94. const initialData = initializeData({
  95. query: {sort: SpanSortOthers.SUM_EXCLUSIVE_TIME},
  96. });
  97. render(<TransactionSpans location={initialData.router.location} />, {
  98. context: initialData.routerContext,
  99. organization: initialData.organization,
  100. });
  101. // default visible columns
  102. const grid = await screen.findByTestId('grid-editable');
  103. expect(await within(grid).findByText('Span Operation')).toBeInTheDocument();
  104. expect(await within(grid).findByText('Span Name')).toBeInTheDocument();
  105. expect(await within(grid).findByText('Total Count')).toBeInTheDocument();
  106. expect(await within(grid).findByText('Frequency')).toBeInTheDocument();
  107. expect(await within(grid).findByText('P75 Self Time')).toBeInTheDocument();
  108. expect(await within(grid).findByText('Total Self Time')).toBeInTheDocument();
  109. // there should be a row for each of the spans
  110. expect(await within(grid).findByText('op1')).toBeInTheDocument();
  111. expect(await within(grid).findByText('op2')).toBeInTheDocument();
  112. expect(eventsMock).toHaveBeenCalledTimes(1);
  113. expect(eventsSpanOpsMock).toHaveBeenCalledTimes(1);
  114. expect(eventsSpansPerformanceMock).toHaveBeenCalledTimes(1);
  115. });
  116. [
  117. {sort: SpanSortPercentiles.P50_EXCLUSIVE_TIME, label: 'P50 Self Time'},
  118. {sort: SpanSortPercentiles.P75_EXCLUSIVE_TIME, label: 'P75 Self Time'},
  119. {sort: SpanSortPercentiles.P95_EXCLUSIVE_TIME, label: 'P95 Self Time'},
  120. {sort: SpanSortPercentiles.P99_EXCLUSIVE_TIME, label: 'P99 Self Time'},
  121. ].forEach(({sort, label}) => {
  122. it('renders the right percentile header', async function () {
  123. const initialData = initializeData({query: {sort}});
  124. render(<TransactionSpans location={initialData.router.location} />, {
  125. context: initialData.routerContext,
  126. organization: initialData.organization,
  127. });
  128. const grid = await screen.findByTestId('grid-editable');
  129. expect(await within(grid).findByText('Span Operation')).toBeInTheDocument();
  130. expect(await within(grid).findByText('Span Name')).toBeInTheDocument();
  131. expect(await within(grid).findByText('Total Count')).toBeInTheDocument();
  132. expect(await within(grid).findByText('Frequency')).toBeInTheDocument();
  133. expect(await within(grid).findByText(label)).toBeInTheDocument();
  134. expect(await within(grid).findByText('Total Self Time')).toBeInTheDocument();
  135. });
  136. });
  137. it('renders the right count header', async function () {
  138. const initialData = initializeData({query: {sort: SpanSortOthers.COUNT}});
  139. render(<TransactionSpans location={initialData.router.location} />, {
  140. context: initialData.routerContext,
  141. organization: initialData.organization,
  142. });
  143. const grid = await screen.findByTestId('grid-editable');
  144. expect(await within(grid).findByText('Span Operation')).toBeInTheDocument();
  145. expect(await within(grid).findByText('Span Name')).toBeInTheDocument();
  146. expect(await within(grid).findByText('Total Count')).toBeInTheDocument();
  147. expect(await within(grid).findByText('Frequency')).toBeInTheDocument();
  148. expect(await within(grid).findByText('P75 Self Time')).toBeInTheDocument();
  149. expect(await within(grid).findByText('Total Self Time')).toBeInTheDocument();
  150. });
  151. it('renders the right avg occurrence header', async function () {
  152. const initialData = initializeData({query: {sort: SpanSortOthers.AVG_OCCURRENCE}});
  153. render(<TransactionSpans location={initialData.router.location} />, {
  154. context: initialData.routerContext,
  155. organization: initialData.organization,
  156. });
  157. const grid = await screen.findByTestId('grid-editable');
  158. expect(await within(grid).findByText('Span Operation')).toBeInTheDocument();
  159. expect(await within(grid).findByText('Span Name')).toBeInTheDocument();
  160. expect(await within(grid).findByText('Average Occurrences')).toBeInTheDocument();
  161. expect(await within(grid).findByText('Frequency')).toBeInTheDocument();
  162. expect(await within(grid).findByText('P75 Self Time')).toBeInTheDocument();
  163. expect(await within(grid).findByText('Total Self Time')).toBeInTheDocument();
  164. });
  165. });
  166. });