debian-mirror-gitlab/spec/frontend/monitoring/components/charts/heatmap_spec.js

103 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import { shallowMount } from '@vue/test-utils';
import { GlHeatmap } from '@gitlab/ui/dist/charts';
2020-06-23 00:09:42 +05:30
import timezoneMock from 'timezone-mock';
2019-12-26 22:10:19 +05:30
import Heatmap from '~/monitoring/components/charts/heatmap.vue';
2020-01-01 13:55:28 +05:30
import { graphDataPrometheusQueryRangeMultiTrack } from '../../mock_data';
2019-12-26 22:10:19 +05:30
describe('Heatmap component', () => {
2020-06-23 00:09:42 +05:30
let wrapper;
2019-12-26 22:10:19 +05:30
let store;
2020-06-23 00:09:42 +05:30
const findChart = () => wrapper.find(GlHeatmap);
const createWrapper = (props = {}) => {
wrapper = shallowMount(Heatmap, {
2019-12-26 22:10:19 +05:30
propsData: {
graphData: graphDataPrometheusQueryRangeMultiTrack,
containerWidth: 100,
2020-06-23 00:09:42 +05:30
...props,
2019-12-26 22:10:19 +05:30
},
store,
});
2020-06-23 00:09:42 +05:30
};
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
describe('wrapped chart', () => {
let glHeatmapChart;
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
beforeEach(() => {
createWrapper();
glHeatmapChart = findChart();
});
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
afterEach(() => {
wrapper.destroy();
});
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
it('is a Vue instance', () => {
expect(glHeatmapChart.isVueInstance()).toBe(true);
});
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
it('should display a label on the x axis', () => {
expect(wrapper.vm.xAxisName).toBe(graphDataPrometheusQueryRangeMultiTrack.x_label);
});
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
it('should display a label on the y axis', () => {
expect(wrapper.vm.yAxisName).toBe(graphDataPrometheusQueryRangeMultiTrack.y_label);
});
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
// According to the echarts docs https://echarts.apache.org/en/option.html#series-heatmap.data
// each row of the heatmap chart is represented by an array inside another parent array
// e.g. [[0, 0, 10]], the format represents the column, the row and finally the value
// corresponding to the cell
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
it('should return chartData with a length of x by y, with a length of 3 per array', () => {
const row = wrapper.vm.chartData[0];
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
expect(row.length).toBe(3);
expect(wrapper.vm.chartData.length).toBe(30);
});
it('returns a series of labels for the x axis', () => {
const { xAxisLabels } = wrapper.vm;
expect(xAxisLabels.length).toBe(5);
});
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
describe('y axis labels', () => {
const gmtLabels = ['3:00 PM', '4:00 PM', '5:00 PM', '6:00 PM', '7:00 PM', '8:00 PM'];
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
it('y-axis labels are formatted in AM/PM format', () => {
expect(findChart().props('yAxisLabels')).toEqual(gmtLabels);
2019-12-26 22:10:19 +05:30
});
2020-06-23 00:09:42 +05:30
describe('when in PT timezone', () => {
const ptLabels = ['8:00 AM', '9:00 AM', '10:00 AM', '11:00 AM', '12:00 PM', '1:00 PM'];
const utcLabels = gmtLabels; // Identical in this case
beforeAll(() => {
timezoneMock.register('US/Pacific');
});
afterAll(() => {
timezoneMock.unregister();
});
it('by default, y-axis is formatted in PT', () => {
createWrapper();
expect(findChart().props('yAxisLabels')).toEqual(ptLabels);
});
it('when the chart uses local timezone, y-axis is formatted in PT', () => {
createWrapper({ timezone: 'LOCAL' });
expect(findChart().props('yAxisLabels')).toEqual(ptLabels);
});
2019-12-26 22:10:19 +05:30
2020-06-23 00:09:42 +05:30
it('when the chart uses UTC, y-axis is formatted in UTC', () => {
createWrapper({ timezone: 'UTC' });
expect(findChart().props('yAxisLabels')).toEqual(utcLabels);
});
2019-12-26 22:10:19 +05:30
});
});
});
});