data.spec.jsx 3.6 KB

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