constants.spec.jsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import EventView from 'sentry/utils/discover/eventView';
  2. import {createRuleFromEventView} from 'sentry/views/alerts/rules/metric/constants';
  3. import {Dataset, EventTypes} from 'sentry/views/alerts/rules/metric/types';
  4. describe('createRuleFromEventView()', () => {
  5. it('sets transaction dataset from event.type:transaction', () => {
  6. const eventView = new EventView({
  7. query: 'title:"nothing" event.type:transaction',
  8. });
  9. const rule = createRuleFromEventView(eventView);
  10. expect(rule.dataset).toBe(Dataset.TRANSACTIONS);
  11. });
  12. it('sets error dataset from event.type:error', () => {
  13. const eventView = new EventView({
  14. query: 'title:"nothing" event.type:error',
  15. });
  16. const rule = createRuleFromEventView(eventView);
  17. expect(rule.dataset).toBe(Dataset.ERRORS);
  18. expect(rule.eventTypes).toEqual([EventTypes.ERROR]);
  19. });
  20. it('removes event.type from query', () => {
  21. const eventView = new EventView({
  22. query: 'title:"nothing" event.type:error',
  23. });
  24. const rule = createRuleFromEventView(eventView);
  25. expect(rule.query).toBe('title:"nothing"');
  26. });
  27. it('gets environment from EventView', () => {
  28. const eventView = new EventView({
  29. environment: ['beta'],
  30. });
  31. const rule = createRuleFromEventView(eventView);
  32. expect(rule.environment).toBe('beta');
  33. });
  34. it('gets aggregate from EventView.yAxis', () => {
  35. const eventView = new EventView({
  36. yAxis: 'count_unique(user)',
  37. });
  38. const rule = createRuleFromEventView(eventView);
  39. expect(rule.aggregate).toBe(eventView.yAxis);
  40. });
  41. it('gets dataset and eventtypes from query', () => {
  42. const eventView = new EventView({
  43. query: 'event.type:error or event.type:default something',
  44. });
  45. const rule = createRuleFromEventView(eventView);
  46. expect(rule.dataset).toBe(Dataset.ERRORS);
  47. expect(rule.eventTypes).toEqual([EventTypes.ERROR, EventTypes.DEFAULT]);
  48. });
  49. it('allows pXX transaction querys', () => {
  50. const eventView = EventView.fromSavedQuery({
  51. id: undefined,
  52. query: 'event.type:transaction',
  53. yAxis: 'p95()',
  54. fields: ['p95()'],
  55. });
  56. const rule = createRuleFromEventView(eventView);
  57. expect(rule.aggregate).toBe('p95(transaction.duration)');
  58. });
  59. });