responseUtils.test.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { cloneDeep } from 'lodash';
  2. import { ArrayVector, DataFrame, FieldType } from '@grafana/data';
  3. import { dataFrameHasLokiError } from './responseUtils';
  4. const frame: DataFrame = {
  5. length: 1,
  6. fields: [
  7. {
  8. name: 'Time',
  9. config: {},
  10. type: FieldType.time,
  11. values: new ArrayVector([1]),
  12. },
  13. {
  14. name: 'labels',
  15. config: {},
  16. type: FieldType.other,
  17. values: new ArrayVector([{ level: 'info' }]),
  18. },
  19. {
  20. name: 'Line',
  21. config: {},
  22. type: FieldType.string,
  23. values: new ArrayVector(['line1']),
  24. },
  25. ],
  26. };
  27. describe('dataframeHasParsingError', () => {
  28. it('handles frame with parsing error', () => {
  29. const input = cloneDeep(frame);
  30. input.fields[1].values = new ArrayVector([{ level: 'info', __error__: 'error' }]);
  31. expect(dataFrameHasLokiError(input)).toBe(true);
  32. });
  33. it('handles frame without parsing error', () => {
  34. const input = cloneDeep(frame);
  35. expect(dataFrameHasLokiError(input)).toBe(false);
  36. });
  37. });