data_processor_specs.ts 1.6 KB

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