index.spec.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {generateSuspectSpansResponse} from 'sentry-test/performance/initializePerformanceData';
  5. import {
  6. act,
  7. render,
  8. screen,
  9. waitForElementToBeRemoved,
  10. within,
  11. } from 'sentry-test/reactTestingLibrary';
  12. import ProjectsStore from 'sentry/stores/projectsStore';
  13. import {useLocation} from 'sentry/utils/useLocation';
  14. import TransactionSpans from 'sentry/views/performance/transactionSummary/transactionSpans';
  15. import {
  16. SpanSortOthers,
  17. SpanSortPercentiles,
  18. } from 'sentry/views/performance/transactionSummary/transactionSpans/types';
  19. jest.mock('sentry/utils/useLocation');
  20. const mockUseLocation = jest.mocked(useLocation);
  21. function initializeData(options: {query: {}; additionalFeatures?: string[]}) {
  22. const {query, additionalFeatures} = options;
  23. const defaultFeatures = ['performance-view'];
  24. const organization = OrganizationFixture({
  25. features: [...defaultFeatures, ...(additionalFeatures ? additionalFeatures : [])],
  26. });
  27. const initialData = initializeOrg({
  28. organization,
  29. router: {
  30. location: {
  31. query: {
  32. transaction: 'Test Transaction',
  33. project: '1',
  34. ...query,
  35. },
  36. },
  37. },
  38. });
  39. act(() => void ProjectsStore.loadInitialData(initialData.projects));
  40. return initialData;
  41. }
  42. describe('Performance > Transaction Spans', function () {
  43. let eventsMock: jest.Mock;
  44. let eventsSpanOpsMock: jest.Mock;
  45. let eventsSpansPerformanceMock: jest.Mock;
  46. beforeEach(function () {
  47. mockUseLocation.mockReturnValue(
  48. LocationFixture({pathname: '/organizations/org-slug/performance/summary'})
  49. );
  50. MockApiClient.addMockResponse({
  51. url: '/organizations/org-slug/projects/',
  52. body: [],
  53. });
  54. MockApiClient.addMockResponse({
  55. url: '/organizations/org-slug/prompts-activity/',
  56. body: {},
  57. });
  58. MockApiClient.addMockResponse({
  59. url: '/organizations/org-slug/sdk-updates/',
  60. body: [],
  61. });
  62. MockApiClient.addMockResponse({
  63. url: '/organizations/org-slug/events-has-measurements/',
  64. body: {measurements: false},
  65. });
  66. eventsMock = MockApiClient.addMockResponse({
  67. url: '/organizations/org-slug/events/',
  68. body: [{'count()': 100}],
  69. });
  70. eventsSpanOpsMock = MockApiClient.addMockResponse({
  71. url: '/organizations/org-slug/events-span-ops/',
  72. body: [],
  73. });
  74. MockApiClient.addMockResponse({
  75. url: '/organizations/org-slug/replay-count/',
  76. body: {},
  77. });
  78. MockApiClient.addMockResponse({
  79. url: '/organizations/org-slug/spans/fields/',
  80. body: [],
  81. });
  82. });
  83. afterEach(function () {
  84. MockApiClient.clearMockResponses();
  85. ProjectsStore.reset();
  86. });
  87. describe('Without Span Data', function () {
  88. beforeEach(function () {
  89. eventsSpansPerformanceMock = MockApiClient.addMockResponse({
  90. url: '/organizations/org-slug/events-spans-performance/',
  91. body: [],
  92. });
  93. });
  94. it('renders empty state', async function () {
  95. const initialData = initializeData({
  96. query: {sort: SpanSortOthers.SUM_EXCLUSIVE_TIME},
  97. });
  98. render(<TransactionSpans location={initialData.router.location} />, {
  99. router: initialData.router,
  100. organization: initialData.organization,
  101. });
  102. expect(
  103. await screen.findByText('No results found for your query')
  104. ).toBeInTheDocument();
  105. });
  106. });
  107. describe('With Span Data', function () {
  108. beforeEach(function () {
  109. eventsSpansPerformanceMock = MockApiClient.addMockResponse({
  110. url: '/organizations/org-slug/events-spans-performance/',
  111. body: generateSuspectSpansResponse({examples: 0}),
  112. });
  113. });
  114. it('renders basic UI elements', async function () {
  115. const initialData = initializeData({
  116. query: {sort: SpanSortOthers.SUM_EXCLUSIVE_TIME},
  117. });
  118. render(<TransactionSpans location={initialData.router.location} />, {
  119. router: initialData.router,
  120. organization: initialData.organization,
  121. });
  122. // default visible columns
  123. const grid = await screen.findByTestId('grid-editable');
  124. expect(await within(grid).findByText('Span Operation')).toBeInTheDocument();
  125. expect(await within(grid).findByText('Span Name')).toBeInTheDocument();
  126. expect(await within(grid).findByText('Frequency')).toBeInTheDocument();
  127. expect(await within(grid).findByText('P75 Self Time')).toBeInTheDocument();
  128. expect(await within(grid).findByText('Total Self Time')).toBeInTheDocument();
  129. // there should be a row for each of the spans
  130. expect(await within(grid).findByText('op1')).toBeInTheDocument();
  131. expect(await within(grid).findByText('op2')).toBeInTheDocument();
  132. expect(eventsMock).toHaveBeenCalledTimes(1);
  133. expect(eventsSpanOpsMock).toHaveBeenCalledTimes(1);
  134. expect(eventsSpansPerformanceMock).toHaveBeenCalledTimes(1);
  135. });
  136. [
  137. {sort: SpanSortPercentiles.P50_EXCLUSIVE_TIME, label: 'P50 Self Time'},
  138. {sort: SpanSortPercentiles.P75_EXCLUSIVE_TIME, label: 'P75 Self Time'},
  139. {sort: SpanSortPercentiles.P95_EXCLUSIVE_TIME, label: 'P95 Self Time'},
  140. {sort: SpanSortPercentiles.P99_EXCLUSIVE_TIME, label: 'P99 Self Time'},
  141. ].forEach(({sort, label}) => {
  142. it('renders the right percentile header', async function () {
  143. const initialData = initializeData({query: {sort}});
  144. render(<TransactionSpans location={initialData.router.location} />, {
  145. router: initialData.router,
  146. organization: initialData.organization,
  147. });
  148. const grid = await screen.findByTestId('grid-editable');
  149. expect(await within(grid).findByText('Span Operation')).toBeInTheDocument();
  150. expect(await within(grid).findByText('Span Name')).toBeInTheDocument();
  151. expect(await within(grid).findByText('Frequency')).toBeInTheDocument();
  152. expect(await within(grid).findByText(label)).toBeInTheDocument();
  153. expect(await within(grid).findByText('Total Self Time')).toBeInTheDocument();
  154. });
  155. });
  156. it('renders the right avg occurrence header', async function () {
  157. const initialData = initializeData({query: {sort: SpanSortOthers.AVG_OCCURRENCE}});
  158. render(<TransactionSpans location={initialData.router.location} />, {
  159. router: initialData.router,
  160. organization: initialData.organization,
  161. });
  162. const grid = await screen.findByTestId('grid-editable');
  163. expect(await within(grid).findByText('Span Operation')).toBeInTheDocument();
  164. expect(await within(grid).findByText('Span Name')).toBeInTheDocument();
  165. expect(await within(grid).findByText('Average Occurrences')).toBeInTheDocument();
  166. expect(await within(grid).findByText('Frequency')).toBeInTheDocument();
  167. expect(await within(grid).findByText('P75 Self Time')).toBeInTheDocument();
  168. expect(await within(grid).findByText('Total Self Time')).toBeInTheDocument();
  169. });
  170. });
  171. describe('Spans Tab V2', function () {
  172. it('does not propagate transaction search query and properly tokenizes span query', async function () {
  173. const initialData = initializeData({
  174. query: {query: 'http.method:POST', spansQuery: 'span.op:db span.action:SELECT'},
  175. additionalFeatures: [
  176. 'performance-view',
  177. 'performance-spans-new-ui',
  178. 'insights-initial-modules',
  179. ],
  180. });
  181. render(<TransactionSpans location={initialData.router.location} />, {
  182. router: initialData.router,
  183. organization: initialData.organization,
  184. });
  185. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  186. const searchTokens = await screen.findAllByTestId('filter-token');
  187. expect(searchTokens).toHaveLength(2);
  188. expect(searchTokens[0]).toHaveTextContent('span.op:db');
  189. expect(searchTokens[1]).toHaveTextContent('span.action:SELECT');
  190. expect(await screen.findByTestId('smart-search-bar')).not.toHaveTextContent(
  191. 'http.method:POST'
  192. );
  193. });
  194. });
  195. });