data_processor.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { DataProcessor } from '../data_processor';
  2. describe('Graph DataProcessor', function() {
  3. const panel: any = {
  4. xaxis: {},
  5. };
  6. const processor = new DataProcessor(panel);
  7. describe('Given default xaxis options and query that returns docs', () => {
  8. beforeEach(() => {
  9. panel.xaxis.mode = 'time';
  10. panel.xaxis.name = 'hostname';
  11. panel.xaxis.values = [];
  12. processor.getSeriesList({
  13. dataList: [
  14. {
  15. type: 'docs',
  16. datapoints: [{ hostname: 'server1', avg: 10 }],
  17. },
  18. ],
  19. });
  20. });
  21. it('Should automatically set xaxis mode to field', () => {
  22. expect(panel.xaxis.mode).toBe('field');
  23. });
  24. });
  25. describe('getDataFieldNames(', () => {
  26. const dataList = [
  27. {
  28. type: 'docs',
  29. datapoints: [
  30. {
  31. hostname: 'server1',
  32. valueField: 11,
  33. nested: {
  34. prop1: 'server2',
  35. value2: 23,
  36. },
  37. },
  38. ],
  39. },
  40. ];
  41. it('Should return all field names', () => {
  42. const fields = processor.getDataFieldNames(dataList, false);
  43. expect(fields).toContain('hostname');
  44. expect(fields).toContain('valueField');
  45. expect(fields).toContain('nested.prop1');
  46. expect(fields).toContain('nested.value2');
  47. });
  48. it('Should return all number fields', () => {
  49. const fields = processor.getDataFieldNames(dataList, true);
  50. expect(fields).toContain('valueField');
  51. expect(fields).toContain('nested.value2');
  52. });
  53. });
  54. });