utils.spec.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {getFields, mapErrors} from 'sentry/views/dashboards/widgetBuilder/utils';
  2. describe('WidgetBuilder utils', function () {
  3. describe('mapErrors', function () {
  4. it('able to handle string and string[] validation errors', () => {
  5. const flatValidation = mapErrors(
  6. {
  7. queries: [{fields: 'just a string'}],
  8. another: [{fields: ['another string']}],
  9. },
  10. {}
  11. );
  12. expect(flatValidation).toEqual({
  13. queries: [{fields: 'just a string'}],
  14. another: [{fields: 'another string'}],
  15. });
  16. });
  17. });
  18. describe('getFields', function () {
  19. it('splits simple fields by comma', function () {
  20. const testFieldsString = 'title,transaction';
  21. const actual = getFields(testFieldsString);
  22. expect(actual).toEqual(['title', 'transaction']);
  23. });
  24. it('splits aggregate fields by comma', function () {
  25. const testFieldsString = 'p75(),p95()';
  26. const actual = getFields(testFieldsString);
  27. expect(actual).toEqual(['p75()', 'p95()']);
  28. });
  29. it('does not split aggregates with inner commas', function () {
  30. const testFieldsString = 'p75(),count_if(transaction.duration,equal,200),p95()';
  31. const actual = getFields(testFieldsString);
  32. expect(actual).toEqual([
  33. 'p75()',
  34. 'count_if(transaction.duration,equal,200)',
  35. 'p95()',
  36. ]);
  37. });
  38. });
  39. });