utils.spec.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {Widget, WidgetType} from '../../types';
  2. import {isOnDemandMetricWidget} from './utils';
  3. function widget(
  4. aggregates: string[],
  5. conditions: string,
  6. type: WidgetType = WidgetType.DISCOVER
  7. ) {
  8. const queries = aggregates.map(_ => ({
  9. aggregates,
  10. columns: [],
  11. conditions,
  12. name: '',
  13. orderby: '',
  14. }));
  15. return {
  16. widgetType: type,
  17. displayType: 'line',
  18. title: 'title',
  19. interval: '5m',
  20. queries,
  21. } as Widget;
  22. }
  23. describe('isOnDemandMetricWidget', () => {
  24. it('should return true for a widget that contains non standard fields', () => {
  25. expect(
  26. isOnDemandMetricWidget(widget(['count()'], 'transaction.duration:>1'))
  27. ).toBeTruthy();
  28. expect(isOnDemandMetricWidget(widget(['count()'], 'device.name:foo'))).toBeTruthy();
  29. expect(isOnDemandMetricWidget(widget(['count()'], 'geo.region:>US'))).toBeTruthy();
  30. });
  31. it('should return false for a widget that has only standard fields', () => {
  32. expect(isOnDemandMetricWidget(widget(['count()'], 'release:1.0'))).toBeFalsy();
  33. expect(isOnDemandMetricWidget(widget(['count()'], 'platform:foo'))).toBeFalsy();
  34. });
  35. it('should return false for a widget that has multiple or unsupported aggregates', () => {
  36. expect(
  37. isOnDemandMetricWidget(
  38. widget(['count()', 'count_unique()'], 'transaction.duration:>1')
  39. )
  40. ).toBeFalsy();
  41. expect(
  42. isOnDemandMetricWidget(widget(['apdex(100)'], 'transaction.duration:>1'))
  43. ).toBeFalsy();
  44. });
  45. });