gitlab-org--gitlab-foss/spec/javascripts/monitoring/graph_spec.js

108 lines
3.2 KiB
JavaScript
Raw Normal View History

import Vue from 'vue';
import Graph from '~/monitoring/components/graph.vue';
import MonitoringMixins from '~/monitoring/mixins/monitoring_mixins';
import {
deploymentData,
convertDatesMultipleSeries,
singleRowMetricsMultipleSeries,
} from './mock_data';
const tagsPath = 'http://test.host/frontend-fixtures/environments-project/tags';
const projectPath = 'http://test.host/frontend-fixtures/environments-project';
const createComponent = propsData => {
const Component = Vue.extend(Graph);
return new Component({
propsData,
}).$mount();
};
const convertedMetrics = convertDatesMultipleSeries(singleRowMetricsMultipleSeries);
describe('Graph', () => {
beforeEach(() => {
spyOn(MonitoringMixins.methods, 'formatDeployments').and.returnValue({});
});
it('has a title', () => {
const component = createComponent({
2017-08-30 21:28:44 -04:00
graphData: convertedMetrics[1],
updateAspectRatio: false,
deploymentData,
tagsPath,
projectPath,
});
expect(component.$el.querySelector('.prometheus-graph-title').innerText.trim()).toBe(
component.graphData.title,
);
});
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],
updateAspectRatio: false,
deploymentData,
tagsPath,
projectPath,
});
const transformedHeight = `${component.graphHeight - 100}`;
2018-10-09 14:03:09 -04:00
expect(component.axisTransform.indexOf(transformedHeight)).not.toEqual(-1);
});
2017-10-05 13:00:20 -04:00
it('outerViewBox gets a width and height property based on the DOM size of the element', () => {
const component = createComponent({
2017-08-30 21:28:44 -04:00
graphData: convertedMetrics[1],
updateAspectRatio: false,
deploymentData,
tagsPath,
projectPath,
});
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');
expect(viewBoxArray[2]).toEqual(component.graphWidth.toString());
expect(viewBoxArray[3]).toEqual((component.graphHeight - 50).toString());
});
});
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', () => {
const component = createComponent({
2017-08-30 21:28:44 -04:00
graphData: convertedMetrics[1],
updateAspectRatio: false,
deploymentData,
tagsPath,
projectPath,
});
expect(component.yAxisLabel).toEqual(component.graphData.y_label);
expect(component.legendTitle).toEqual(component.graphData.queries[0].label);
});
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,
},
tagsPath,
projectPath,
});
2018-09-07 02:05:10 -04:00
// simulate moving mouse over data series
component.seriesUnderMouse = component.timeSeries;
component.positionFlag();
2018-10-09 14:03:09 -04:00
expect(component.currentData).toBe(component.timeSeries[0].values[10]);
});
});