index.spec.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import {STANDARD_SEARCH_FIELD_KEYS} from 'sentry/utils/onDemandMetrics/constants';
  2. import {createOnDemandFilterWarning, isOnDemandQueryString} from '.';
  3. describe('isOnDemandQueryString', () => {
  4. it('should return true for a query that contains non-standard query keys', () => {
  5. expect(isOnDemandQueryString('transaction.duration:>1')).toBeTruthy();
  6. expect(isOnDemandQueryString('device.name:foo')).toBeTruthy();
  7. expect(isOnDemandQueryString('geo.region:>US')).toBeTruthy();
  8. expect(isOnDemandQueryString('foo:bar')).toBeTruthy();
  9. });
  10. it('should return false for an alert that has only standard fields', () => {
  11. expect(isOnDemandQueryString('release:1.0')).toBeFalsy();
  12. expect(isOnDemandQueryString('browser.name:chrome')).toBeFalsy();
  13. });
  14. });
  15. describe('createOnDemandFilterWarning', () => {
  16. it('should return the warning if the query key is not a standard search key', () => {
  17. const message = "This filter isn't supported";
  18. const getOnDemandFilterWarning = createOnDemandFilterWarning(message);
  19. expect(getOnDemandFilterWarning('transaction.duration')).toBe(message);
  20. expect(getOnDemandFilterWarning('user.email')).toBe(message);
  21. expect(getOnDemandFilterWarning('device.family')).toBe(message);
  22. expect(getOnDemandFilterWarning('foo.bar')).toBe(message);
  23. });
  24. it('should return null if the query key is a standard search key', () => {
  25. const message = "This filter isn't supported";
  26. const getOnDemandFilterWarning = createOnDemandFilterWarning(message);
  27. STANDARD_SEARCH_FIELD_KEYS.forEach(key => {
  28. expect(getOnDemandFilterWarning(key)).toBe(null);
  29. });
  30. });
  31. });