data.spec.jsx 4.1 KB

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