index.spec.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. ...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('Frequency')).toBeInTheDocument();
  106. expect(await within(grid).findByText('P75 Self Time')).toBeInTheDocument();
  107. expect(await within(grid).findByText('Total Self Time')).toBeInTheDocument();
  108. // there should be a row for each of the spans
  109. expect(await within(grid).findByText('op1')).toBeInTheDocument();
  110. expect(await within(grid).findByText('op2')).toBeInTheDocument();
  111. expect(eventsMock).toHaveBeenCalledTimes(1);
  112. expect(eventsSpanOpsMock).toHaveBeenCalledTimes(1);
  113. expect(eventsSpansPerformanceMock).toHaveBeenCalledTimes(1);
  114. });
  115. [
  116. {sort: SpanSortPercentiles.P50_EXCLUSIVE_TIME, label: 'P50 Self Time'},
  117. {sort: SpanSortPercentiles.P75_EXCLUSIVE_TIME, label: 'P75 Self Time'},
  118. {sort: SpanSortPercentiles.P95_EXCLUSIVE_TIME, label: 'P95 Self Time'},
  119. {sort: SpanSortPercentiles.P99_EXCLUSIVE_TIME, label: 'P99 Self Time'},
  120. ].forEach(({sort, label}) => {
  121. it('renders the right percentile header', async function () {
  122. const initialData = initializeData({query: {sort}});
  123. render(<TransactionSpans location={initialData.router.location} />, {
  124. context: initialData.routerContext,
  125. organization: initialData.organization,
  126. });
  127. const grid = await screen.findByTestId('grid-editable');
  128. expect(await within(grid).findByText('Span Operation')).toBeInTheDocument();
  129. expect(await within(grid).findByText('Span Name')).toBeInTheDocument();
  130. expect(await within(grid).findByText('Frequency')).toBeInTheDocument();
  131. expect(await within(grid).findByText(label)).toBeInTheDocument();
  132. expect(await within(grid).findByText('Total Self Time')).toBeInTheDocument();
  133. });
  134. });
  135. it('renders the right avg occurrence header', async function () {
  136. const initialData = initializeData({query: {sort: SpanSortOthers.AVG_OCCURRENCE}});
  137. render(<TransactionSpans location={initialData.router.location} />, {
  138. context: initialData.routerContext,
  139. organization: initialData.organization,
  140. });
  141. const grid = await screen.findByTestId('grid-editable');
  142. expect(await within(grid).findByText('Span Operation')).toBeInTheDocument();
  143. expect(await within(grid).findByText('Span Name')).toBeInTheDocument();
  144. expect(await within(grid).findByText('Average Occurrences')).toBeInTheDocument();
  145. expect(await within(grid).findByText('Frequency')).toBeInTheDocument();
  146. expect(await within(grid).findByText('P75 Self Time')).toBeInTheDocument();
  147. expect(await within(grid).findByText('Total Self Time')).toBeInTheDocument();
  148. });
  149. });
  150. });