data.spec.jsx 3.7 KB

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