index.spec.tsx 6.2 KB

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