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

98 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import { GlHeatmap } from '@gitlab/ui/dist/charts';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
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-10-24 23:57:45 +05:30
import { heatmapGraphData } from '../../graph_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);
2020-10-24 23:57:45 +05:30
const graphData = heatmapGraphData();
2020-06-23 00:09:42 +05:30
const createWrapper = (props = {}) => {
wrapper = shallowMount(Heatmap, {
2019-12-26 22:10:19 +05:30
propsData: {
2020-10-24 23:57:45 +05:30
graphData: heatmapGraphData(),
2019-12-26 22:10:19 +05:30
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', () => {
beforeEach(() => {
createWrapper();
});
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('should display a label on the x axis', () => {
2020-10-24 23:57:45 +05:30
expect(wrapper.vm.xAxisName).toBe(graphData.xLabel);
2020-06-23 00:09:42 +05:30
});
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', () => {
2020-10-24 23:57:45 +05:30
expect(wrapper.vm.yAxisName).toBe(graphData.y_label);
2020-06-23 00:09:42 +05:30
});
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);
2020-10-24 23:57:45 +05:30
expect(wrapper.vm.chartData.length).toBe(6);
2020-06-23 00:09:42 +05:30
});
it('returns a series of labels for the x axis', () => {
const { xAxisLabels } = wrapper.vm;
2020-10-24 23:57:45 +05:30
expect(xAxisLabels.length).toBe(2);
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('y axis labels', () => {
2020-10-24 23:57:45 +05:30
const gmtLabels = ['8:10 PM', '8:12 PM', '8:14 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', () => {
2020-10-24 23:57:45 +05:30
const ptLabels = ['1:10 PM', '1:12 PM', '1:14 PM'];
2020-06-23 00:09:42 +05:30
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
});
});
});
});