suspectSpansQuery.spec.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import {render} from 'sentry-test/reactTestingLibrary';
  2. import EventView from 'sentry/utils/discover/eventView';
  3. import SuspectSpansQuery from 'sentry/utils/performance/suspectSpans/suspectSpansQuery';
  4. import {
  5. SpanSortOthers,
  6. SpanSortPercentiles,
  7. } from 'sentry/views/performance/transactionSummary/transactionSpans/types';
  8. describe('SuspectSpansQuery', function () {
  9. let eventView, location;
  10. beforeEach(function () {
  11. eventView = EventView.fromSavedQuery({
  12. id: '',
  13. name: '',
  14. version: 2,
  15. fields: [...Object.values(SpanSortOthers), ...Object.values(SpanSortPercentiles)],
  16. projects: [],
  17. environment: [],
  18. });
  19. location = {
  20. pathname: '/',
  21. query: {},
  22. };
  23. });
  24. it('fetches data on mount', function () {
  25. const getMock = MockApiClient.addMockResponse({
  26. url: '/organizations/test-org/events-spans-performance/',
  27. // just asserting that the data is being fetched, no need for actual data here
  28. body: [],
  29. });
  30. render(
  31. <SuspectSpansQuery
  32. location={location}
  33. orgSlug="test-org"
  34. eventView={eventView}
  35. spanOps={[]}
  36. >
  37. {() => null}
  38. </SuspectSpansQuery>
  39. );
  40. expect(getMock).toHaveBeenCalledTimes(1);
  41. });
  42. it('fetches data with the right op filter', function () {
  43. const getMock = MockApiClient.addMockResponse({
  44. url: '/organizations/test-org/events-spans-performance/',
  45. // just asserting that the data is being fetched, no need for actual data here
  46. body: [],
  47. match: [MockApiClient.matchQuery({spanOp: ['op1']})],
  48. });
  49. render(
  50. <SuspectSpansQuery
  51. location={location}
  52. orgSlug="test-org"
  53. eventView={eventView}
  54. spanOps={['op1']}
  55. >
  56. {() => null}
  57. </SuspectSpansQuery>
  58. );
  59. expect(getMock).toHaveBeenCalledTimes(1);
  60. });
  61. it('fetches data with the right group filter', function () {
  62. const getMock = MockApiClient.addMockResponse({
  63. url: '/organizations/test-org/events-spans-performance/',
  64. // just asserting that the data is being fetched, no need for actual data here
  65. body: [],
  66. match: [MockApiClient.matchQuery({spanGroup: ['aaaaaaaaaaaaaaaa']})],
  67. });
  68. render(
  69. <SuspectSpansQuery
  70. location={location}
  71. orgSlug="test-org"
  72. eventView={eventView}
  73. spanGroups={['aaaaaaaaaaaaaaaa']}
  74. >
  75. {() => null}
  76. </SuspectSpansQuery>
  77. );
  78. expect(getMock).toHaveBeenCalledTimes(1);
  79. });
  80. it('fetches data with the right per suspect param', function () {
  81. const getMock = MockApiClient.addMockResponse({
  82. url: '/organizations/test-org/events-spans-performance/',
  83. // just asserting that the data is being fetched, no need for actual data here
  84. body: [],
  85. match: [MockApiClient.matchQuery({perSuspect: 1})],
  86. });
  87. render(
  88. <SuspectSpansQuery
  89. location={location}
  90. orgSlug="test-org"
  91. eventView={eventView}
  92. perSuspect={1}
  93. >
  94. {() => null}
  95. </SuspectSpansQuery>
  96. );
  97. expect(getMock).toHaveBeenCalledTimes(1);
  98. });
  99. });