data.spec.tsx 4.5 KB

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