data.spec.jsx 4.1 KB

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