data.spec.tsx 4.6 KB

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