2017-06-20 04:50:31 -04:00
|
|
|
import Vue from 'vue';
|
2017-08-30 12:11:19 -04:00
|
|
|
import Graph from '~/monitoring/components/graph.vue';
|
2017-06-20 04:50:31 -04:00
|
|
|
import MonitoringMixins from '~/monitoring/mixins/monitoring_mixins';
|
2018-03-21 15:36:43 -04:00
|
|
|
import {
|
|
|
|
deploymentData,
|
|
|
|
convertDatesMultipleSeries,
|
|
|
|
singleRowMetricsMultipleSeries,
|
|
|
|
} from './mock_data';
|
2017-06-20 04:50:31 -04:00
|
|
|
|
2017-12-04 16:39:07 -05:00
|
|
|
const tagsPath = 'http://test.host/frontend-fixtures/environments-project/tags';
|
|
|
|
const projectPath = 'http://test.host/frontend-fixtures/environments-project';
|
2018-03-21 15:36:43 -04:00
|
|
|
const createComponent = propsData => {
|
2017-08-30 12:11:19 -04:00
|
|
|
const Component = Vue.extend(Graph);
|
2017-06-20 04:50:31 -04:00
|
|
|
|
|
|
|
return new Component({
|
|
|
|
propsData,
|
|
|
|
}).$mount();
|
|
|
|
};
|
|
|
|
|
2018-06-06 07:02:47 -04:00
|
|
|
const convertedMetrics = convertDatesMultipleSeries(singleRowMetricsMultipleSeries);
|
2017-08-28 21:49:14 -04:00
|
|
|
|
2017-08-30 12:11:19 -04:00
|
|
|
describe('Graph', () => {
|
2017-06-20 04:50:31 -04:00
|
|
|
beforeEach(() => {
|
2017-08-30 12:11:19 -04:00
|
|
|
spyOn(MonitoringMixins.methods, 'formatDeployments').and.returnValue({});
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('has a title', () => {
|
|
|
|
const component = createComponent({
|
2017-08-30 21:28:44 -04:00
|
|
|
graphData: convertedMetrics[1],
|
2017-06-20 04:50:31 -04:00
|
|
|
updateAspectRatio: false,
|
|
|
|
deploymentData,
|
2017-12-04 16:39:07 -05:00
|
|
|
tagsPath,
|
|
|
|
projectPath,
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
2018-06-06 07:02:47 -04:00
|
|
|
expect(component.$el.querySelector('.prometheus-graph-title').innerText.trim()).toBe(
|
2018-03-21 15:36:43 -04:00
|
|
|
component.graphData.title,
|
|
|
|
);
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Computed props', () => {
|
|
|
|
it('axisTransform translates an element Y position depending of its height', () => {
|
|
|
|
const component = createComponent({
|
2017-08-30 21:28:44 -04:00
|
|
|
graphData: convertedMetrics[1],
|
2017-06-20 04:50:31 -04:00
|
|
|
updateAspectRatio: false,
|
|
|
|
deploymentData,
|
2017-12-04 16:39:07 -05:00
|
|
|
tagsPath,
|
|
|
|
projectPath,
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const transformedHeight = `${component.graphHeight - 100}`;
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-06-06 07:02:47 -04:00
|
|
|
expect(component.axisTransform.indexOf(transformedHeight)).not.toEqual(-1);
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
2017-10-05 13:00:20 -04:00
|
|
|
it('outerViewBox gets a width and height property based on the DOM size of the element', () => {
|
2017-06-20 04:50:31 -04:00
|
|
|
const component = createComponent({
|
2017-08-30 21:28:44 -04:00
|
|
|
graphData: convertedMetrics[1],
|
2017-06-20 04:50:31 -04:00
|
|
|
updateAspectRatio: false,
|
|
|
|
deploymentData,
|
2017-12-04 16:39:07 -05:00
|
|
|
tagsPath,
|
|
|
|
projectPath,
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
2017-10-05 13:00:20 -04:00
|
|
|
const viewBoxArray = component.outerViewBox.split(' ');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-05 13:00:20 -04:00
|
|
|
expect(typeof component.outerViewBox).toEqual('string');
|
2017-06-20 04:50:31 -04:00
|
|
|
expect(viewBoxArray[2]).toEqual(component.graphWidth.toString());
|
2018-03-21 15:36:43 -04:00
|
|
|
expect(viewBoxArray[3]).toEqual((component.graphHeight - 50).toString());
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-07-04 13:29:53 -04:00
|
|
|
it('has a title for the y-axis and the chart legend that comes from the backend', () => {
|
2017-07-03 11:43:56 -04:00
|
|
|
const component = createComponent({
|
2017-08-30 21:28:44 -04:00
|
|
|
graphData: convertedMetrics[1],
|
2017-07-03 11:43:56 -04:00
|
|
|
updateAspectRatio: false,
|
|
|
|
deploymentData,
|
2017-12-04 16:39:07 -05:00
|
|
|
tagsPath,
|
|
|
|
projectPath,
|
2017-07-03 11:43:56 -04:00
|
|
|
});
|
|
|
|
|
2017-08-30 12:11:19 -04:00
|
|
|
expect(component.yAxisLabel).toEqual(component.graphData.y_label);
|
|
|
|
expect(component.legendTitle).toEqual(component.graphData.queries[0].label);
|
2017-07-03 11:43:56 -04:00
|
|
|
});
|
2017-10-05 04:52:06 -04:00
|
|
|
|
|
|
|
it('sets the currentData object based on the hovered data index', () => {
|
|
|
|
const component = createComponent({
|
|
|
|
graphData: convertedMetrics[1],
|
|
|
|
updateAspectRatio: false,
|
|
|
|
deploymentData,
|
|
|
|
graphIdentifier: 0,
|
|
|
|
hoverData: {
|
|
|
|
hoveredDate: new Date('Sun Aug 27 2017 06:11:51 GMT-0500 (CDT)'),
|
|
|
|
currentDeployXPos: null,
|
|
|
|
},
|
2017-12-04 16:39:07 -05:00
|
|
|
tagsPath,
|
|
|
|
projectPath,
|
2017-10-05 04:52:06 -04:00
|
|
|
});
|
|
|
|
|
2018-09-07 02:05:10 -04:00
|
|
|
// simulate moving mouse over data series
|
|
|
|
component.seriesUnderMouse = component.timeSeries;
|
|
|
|
|
2017-10-05 04:52:06 -04:00
|
|
|
component.positionFlag();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-05 04:52:06 -04:00
|
|
|
expect(component.currentData).toBe(component.timeSeries[0].values[10]);
|
|
|
|
});
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|