2017-12-19 16:06:54 +01:00
|
|
|
import { DataProcessor } from "../data_processor";
|
2016-09-23 17:12:10 +02:00
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
describe("Graph DataProcessor", function() {
|
2016-09-23 17:12:10 +02:00
|
|
|
var panel: any = {
|
|
|
|
|
xaxis: {}
|
|
|
|
|
};
|
2017-11-27 12:14:57 +01:00
|
|
|
|
2016-09-23 17:12:10 +02:00
|
|
|
var processor = new DataProcessor(panel);
|
|
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
describe("Given default xaxis options and query that returns docs", () => {
|
2016-09-23 17:12:10 +02:00
|
|
|
beforeEach(() => {
|
2017-12-19 16:06:54 +01:00
|
|
|
panel.xaxis.mode = "time";
|
|
|
|
|
panel.xaxis.name = "hostname";
|
2016-09-23 17:12:10 +02:00
|
|
|
panel.xaxis.values = [];
|
|
|
|
|
|
2017-11-27 12:14:57 +01:00
|
|
|
processor.getSeriesList({
|
2016-09-23 17:12:10 +02:00
|
|
|
dataList: [
|
|
|
|
|
{
|
2017-12-19 16:06:54 +01:00
|
|
|
type: "docs",
|
|
|
|
|
datapoints: [{ hostname: "server1", avg: 10 }]
|
2016-09-23 17:12:10 +02:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
it("Should automatically set xaxis mode to field", () => {
|
|
|
|
|
expect(panel.xaxis.mode).toBe("field");
|
2016-09-23 17:12:10 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
describe("getDataFieldNames(", () => {
|
|
|
|
|
var dataList = [
|
|
|
|
|
{
|
|
|
|
|
type: "docs",
|
|
|
|
|
datapoints: [
|
|
|
|
|
{
|
|
|
|
|
hostname: "server1",
|
|
|
|
|
valueField: 11,
|
|
|
|
|
nested: {
|
|
|
|
|
prop1: "server2",
|
|
|
|
|
value2: 23
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
it("Should return all field names", () => {
|
2016-09-24 13:08:58 +02:00
|
|
|
var fields = processor.getDataFieldNames(dataList, false);
|
2017-12-19 16:06:54 +01:00
|
|
|
expect(fields).toContain("hostname");
|
|
|
|
|
expect(fields).toContain("valueField");
|
|
|
|
|
expect(fields).toContain("nested.prop1");
|
|
|
|
|
expect(fields).toContain("nested.value2");
|
2016-09-24 13:08:58 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
it("Should return all number fields", () => {
|
2016-09-24 13:08:58 +02:00
|
|
|
var fields = processor.getDataFieldNames(dataList, true);
|
2017-12-19 16:06:54 +01:00
|
|
|
expect(fields).toContain("valueField");
|
|
|
|
|
expect(fields).toContain("nested.value2");
|
2016-09-24 13:08:58 +02:00
|
|
|
});
|
|
|
|
|
});
|
2016-09-23 17:12:10 +02:00
|
|
|
});
|