data.spec.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import {
  2. MEPState,
  3. METRIC_SEARCH_SETTING_PARAM,
  4. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  5. import {
  6. DEFAULT_STATS_PERIOD,
  7. generatePerformanceEventView,
  8. } from 'sentry/views/performance/data';
  9. describe('generatePerformanceEventView()', function () {
  10. const organization = TestStubs.Organization();
  11. it('generates default values', function () {
  12. const result = generatePerformanceEventView(
  13. TestStubs.location({query: {}}),
  14. [],
  15. {},
  16. organization
  17. );
  18. expect(result.id).toBeUndefined();
  19. expect(result.name).toEqual('Performance');
  20. expect(result.fields.length).toBeGreaterThanOrEqual(7);
  21. expect(result.query).toEqual('');
  22. expect(result.getQueryWithAdditionalConditions()).toEqual('event.type:transaction');
  23. expect(result.sorts).toEqual([{kind: 'desc', field: 'tpm'}]);
  24. expect(result.statsPeriod).toEqual(DEFAULT_STATS_PERIOD);
  25. });
  26. it('applies sort from location', function () {
  27. const result = generatePerformanceEventView(
  28. TestStubs.location({query: {sort: ['-p50', '-count']}}),
  29. [],
  30. {},
  31. organization
  32. );
  33. expect(result.sorts).toEqual([{kind: 'desc', field: 'p50'}]);
  34. expect(result.statsPeriod).toEqual(DEFAULT_STATS_PERIOD);
  35. });
  36. it('does not override statsPeriod from location', function () {
  37. const result = generatePerformanceEventView(
  38. TestStubs.location({query: {statsPeriod: ['90d', '45d']}}),
  39. [],
  40. {},
  41. organization
  42. );
  43. expect(result.start).toBeUndefined();
  44. expect(result.end).toBeUndefined();
  45. expect(result.statsPeriod).toEqual('90d');
  46. });
  47. it('does not apply range when start and end are present', function () {
  48. const result = generatePerformanceEventView(
  49. TestStubs.location({
  50. query: {start: '2020-04-25T12:00:00', end: '2020-05-25T12:00:00'},
  51. }),
  52. [],
  53. {},
  54. organization
  55. );
  56. expect(result.start).toEqual('2020-04-25T12:00:00.000');
  57. expect(result.end).toEqual('2020-05-25T12:00:00.000');
  58. expect(result.statsPeriod).toBeUndefined();
  59. });
  60. it('converts bare query into transaction name wildcard', function () {
  61. const result = generatePerformanceEventView(
  62. TestStubs.location({query: {query: 'things.update'}}),
  63. [],
  64. {},
  65. organization
  66. );
  67. expect(result.query).toEqual(expect.stringContaining('transaction:*things.update*'));
  68. expect(result.getQueryWithAdditionalConditions()).toEqual(
  69. expect.stringContaining('event.type:transaction')
  70. );
  71. });
  72. it('bare query overwrites transaction condition', function () {
  73. const result = generatePerformanceEventView(
  74. TestStubs.location({query: {query: 'things.update transaction:thing.gone'}}),
  75. [],
  76. {},
  77. organization
  78. );
  79. expect(result.query).toEqual(expect.stringContaining('transaction:*things.update*'));
  80. expect(result.getQueryWithAdditionalConditions()).toEqual(
  81. expect.stringContaining('event.type:transaction')
  82. );
  83. expect(result.query).toEqual(expect.not.stringContaining('transaction:thing.gone'));
  84. });
  85. it('retains tag filter conditions', function () {
  86. const result = generatePerformanceEventView(
  87. TestStubs.location({query: {query: 'key:value tag:value'}}),
  88. [],
  89. {},
  90. organization
  91. );
  92. expect(result.query).toEqual(expect.stringContaining('key:value'));
  93. expect(result.query).toEqual(expect.stringContaining('tag:value'));
  94. expect(result.getQueryWithAdditionalConditions()).toEqual(
  95. expect.stringContaining('event.type:transaction')
  96. );
  97. });
  98. it('gets the right column', function () {
  99. const result = generatePerformanceEventView(
  100. TestStubs.location({query: {query: 'key:value tag:value'}}),
  101. [],
  102. {},
  103. organization
  104. );
  105. expect(result.fields).toEqual(
  106. expect.arrayContaining([expect.objectContaining({field: 'user_misery()'})])
  107. );
  108. expect(result.fields).toEqual(
  109. expect.arrayContaining([expect.objectContaining({field: 'count_miserable(user)'})])
  110. );
  111. expect(result.fields).toEqual(
  112. expect.arrayContaining([expect.objectContaining({field: 'apdex()'})])
  113. );
  114. });
  115. it('removes unsupported tokens for limited search', function () {
  116. const result = generatePerformanceEventView(
  117. TestStubs.location({
  118. query: {
  119. query: 'tag:value transaction:*auth*',
  120. [METRIC_SEARCH_SETTING_PARAM]: MEPState.METRICS_ONLY,
  121. },
  122. }),
  123. [],
  124. {withStaticFilters: true},
  125. organization
  126. );
  127. expect(result.query).toEqual('transaction:*auth*');
  128. });
  129. });