utils.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {Dataset, SessionsAggregate} from 'sentry/views/alerts/rules/metric/types';
  2. import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils';
  3. describe('Wizard utils', function () {
  4. it('extracts lcp alert', function () {
  5. expect(
  6. getAlertTypeFromAggregateDataset({
  7. aggregate: 'p95(measurements.lcp)',
  8. dataset: Dataset.TRANSACTIONS,
  9. })
  10. ).toEqual('lcp');
  11. expect(
  12. getAlertTypeFromAggregateDataset({
  13. aggregate: 'percentile(measurements.lcp,0.7)',
  14. dataset: Dataset.TRANSACTIONS,
  15. })
  16. ).toEqual('lcp');
  17. expect(
  18. getAlertTypeFromAggregateDataset({
  19. aggregate: 'avg(measurements.lcp)',
  20. dataset: Dataset.TRANSACTIONS,
  21. })
  22. ).toEqual('lcp');
  23. });
  24. it('extracts duration alert', function () {
  25. expect(
  26. getAlertTypeFromAggregateDataset({
  27. aggregate: 'p95(transaction.duration)',
  28. dataset: Dataset.TRANSACTIONS,
  29. })
  30. ).toEqual('trans_duration');
  31. expect(
  32. getAlertTypeFromAggregateDataset({
  33. aggregate: 'percentile(transaction.duration,0.3)',
  34. dataset: Dataset.TRANSACTIONS,
  35. })
  36. ).toEqual('trans_duration');
  37. expect(
  38. getAlertTypeFromAggregateDataset({
  39. aggregate: 'avg(transaction.duration)',
  40. dataset: Dataset.TRANSACTIONS,
  41. })
  42. ).toEqual('trans_duration');
  43. });
  44. it('extracts throughput alert', function () {
  45. expect(
  46. getAlertTypeFromAggregateDataset({
  47. aggregate: 'count()',
  48. dataset: Dataset.TRANSACTIONS,
  49. })
  50. ).toEqual('throughput');
  51. });
  52. it('extracts user error alert', function () {
  53. expect(
  54. getAlertTypeFromAggregateDataset({
  55. aggregate: 'count_unique(user)',
  56. dataset: Dataset.ERRORS,
  57. })
  58. ).toEqual('users_experiencing_errors');
  59. });
  60. it('extracts error count alert', function () {
  61. expect(
  62. getAlertTypeFromAggregateDataset({
  63. aggregate: 'count()',
  64. dataset: Dataset.ERRORS,
  65. })
  66. ).toEqual('num_errors');
  67. });
  68. it('extracts crash free sessions alert', function () {
  69. expect(
  70. getAlertTypeFromAggregateDataset({
  71. aggregate: SessionsAggregate.CRASH_FREE_SESSIONS,
  72. dataset: Dataset.SESSIONS,
  73. })
  74. ).toEqual('crash_free_sessions');
  75. });
  76. it('extracts crash free users alert', function () {
  77. expect(
  78. getAlertTypeFromAggregateDataset({
  79. aggregate: SessionsAggregate.CRASH_FREE_USERS,
  80. dataset: Dataset.SESSIONS,
  81. })
  82. ).toEqual('crash_free_users');
  83. });
  84. it('extracts crash free users alert from metrics', function () {
  85. expect(
  86. getAlertTypeFromAggregateDataset({
  87. aggregate: SessionsAggregate.CRASH_FREE_USERS,
  88. dataset: Dataset.METRICS,
  89. })
  90. ).toBe('crash_free_users');
  91. });
  92. it('defaults to custom', function () {
  93. expect(
  94. getAlertTypeFromAggregateDataset({
  95. aggregate: 'count_unique(tags[sentry:user])',
  96. dataset: Dataset.TRANSACTIONS,
  97. })
  98. ).toEqual('custom');
  99. expect(
  100. getAlertTypeFromAggregateDataset({
  101. aggregate: 'p95(measurements.fp)',
  102. dataset: Dataset.TRANSACTIONS,
  103. })
  104. ).toEqual('custom');
  105. expect(
  106. getAlertTypeFromAggregateDataset({
  107. aggregate: 'p95(measurements.ttfb)',
  108. dataset: Dataset.TRANSACTIONS,
  109. })
  110. ).toEqual('custom');
  111. });
  112. });