data_processor.jest.ts 1.5 KB

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