2019-03-02 22:35:43 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2019-05-30 16:15:17 +05:30
|
|
|
import { GlAreaChart } from '@gitlab/ui/dist/charts';
|
2019-03-02 22:35:43 +05:30
|
|
|
import { shallowWrapperContainsSlotText } from 'spec/helpers/vue_test_utils_helper';
|
|
|
|
import Area from '~/monitoring/components/charts/area.vue';
|
|
|
|
import MonitoringStore from '~/monitoring/stores/monitoring_store';
|
|
|
|
import MonitoringMock, { deploymentData } from '../mock_data';
|
|
|
|
|
|
|
|
describe('Area component', () => {
|
|
|
|
const mockWidgets = 'mockWidgets';
|
|
|
|
let mockGraphData;
|
|
|
|
let areaChart;
|
|
|
|
let spriteSpy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const store = new MonitoringStore();
|
|
|
|
store.storeMetrics(MonitoringMock.data);
|
|
|
|
store.storeDeploymentData(deploymentData);
|
|
|
|
|
|
|
|
[mockGraphData] = store.groups[0].metrics;
|
|
|
|
|
|
|
|
areaChart = shallowMount(Area, {
|
|
|
|
propsData: {
|
|
|
|
graphData: mockGraphData,
|
|
|
|
containerWidth: 0,
|
|
|
|
deploymentData: store.deploymentData,
|
|
|
|
},
|
|
|
|
slots: {
|
|
|
|
default: mockWidgets,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
spriteSpy = spyOnDependency(Area, 'getSvgIconPathContent').and.callFake(
|
2019-05-30 16:15:17 +05:30
|
|
|
() => new Promise(resolve => resolve()),
|
2019-03-02 22:35:43 +05:30
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
areaChart.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders chart title', () => {
|
|
|
|
expect(areaChart.find({ ref: 'graphTitle' }).text()).toBe(mockGraphData.title);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('contains graph widgets from slot', () => {
|
|
|
|
expect(areaChart.find({ ref: 'graphWidgets' }).text()).toBe(mockWidgets);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('wrapped components', () => {
|
|
|
|
describe('GitLab UI area chart', () => {
|
|
|
|
let glAreaChart;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
glAreaChart = areaChart.find(GlAreaChart);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is a Vue instance', () => {
|
|
|
|
expect(glAreaChart.isVueInstance()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('receives data properties needed for proper chart render', () => {
|
|
|
|
const props = glAreaChart.props();
|
|
|
|
|
|
|
|
expect(props.data).toBe(areaChart.vm.chartData);
|
|
|
|
expect(props.option).toBe(areaChart.vm.chartOptions);
|
|
|
|
expect(props.formatTooltipText).toBe(areaChart.vm.formatTooltipText);
|
2019-05-30 16:15:17 +05:30
|
|
|
expect(props.thresholds).toBe(areaChart.props('alertData'));
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('recieves a tooltip title', () => {
|
|
|
|
const mockTitle = 'mockTitle';
|
|
|
|
areaChart.vm.tooltip.title = mockTitle;
|
|
|
|
|
|
|
|
expect(shallowWrapperContainsSlotText(glAreaChart, 'tooltipTitle', mockTitle)).toBe(true);
|
|
|
|
});
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it('recieves tooltip content', () => {
|
|
|
|
const mockContent = 'mockContent';
|
|
|
|
areaChart.vm.tooltip.content = mockContent;
|
|
|
|
|
|
|
|
expect(shallowWrapperContainsSlotText(glAreaChart, 'tooltipContent', mockContent)).toBe(
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
describe('when tooltip is showing deployment data', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
areaChart.vm.tooltip.isDeployment = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses deployment title', () => {
|
|
|
|
expect(shallowWrapperContainsSlotText(glAreaChart, 'tooltipTitle', 'Deployed')).toBe(
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders commit sha in tooltip content', () => {
|
|
|
|
const mockSha = 'mockSha';
|
|
|
|
areaChart.vm.tooltip.sha = mockSha;
|
|
|
|
|
|
|
|
expect(shallowWrapperContainsSlotText(glAreaChart, 'tooltipContent', mockSha)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('formatTooltipText', () => {
|
|
|
|
const mockDate = deploymentData[0].created_at;
|
|
|
|
const generateSeriesData = type => ({
|
|
|
|
seriesData: [
|
|
|
|
{
|
|
|
|
componentSubType: type,
|
|
|
|
value: [mockDate, 5.55555],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
value: mockDate,
|
|
|
|
});
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
describe('series is of line type', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
areaChart.vm.formatTooltipText(generateSeriesData('line'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('formats tooltip title', () => {
|
|
|
|
expect(areaChart.vm.tooltip.title).toBe('31 May 2017, 9:23PM');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('formats tooltip content', () => {
|
2019-05-30 16:15:17 +05:30
|
|
|
expect(areaChart.vm.tooltip.content).toBe('CPU (Cores) 5.556');
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
describe('series is of scatter type', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
areaChart.vm.formatTooltipText(generateSeriesData('scatter'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('formats tooltip title', () => {
|
|
|
|
expect(areaChart.vm.tooltip.title).toBe('31 May 2017, 9:23PM');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('formats tooltip sha', () => {
|
|
|
|
expect(areaChart.vm.tooltip.sha).toBe('f5bcd1d9');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
describe('getScatterSymbol', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
beforeEach(() => {
|
2019-05-30 16:15:17 +05:30
|
|
|
areaChart.vm.getScatterSymbol();
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it('gets rocket svg path content for use as deployment data symbol', () => {
|
|
|
|
expect(spriteSpy).toHaveBeenCalledWith('rocket');
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onResize', () => {
|
|
|
|
const mockWidth = 233;
|
2019-05-30 16:15:17 +05:30
|
|
|
const mockHeight = 144;
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(Element.prototype, 'getBoundingClientRect').and.callFake(() => ({
|
|
|
|
width: mockWidth,
|
2019-05-30 16:15:17 +05:30
|
|
|
height: mockHeight,
|
2019-03-02 22:35:43 +05:30
|
|
|
}));
|
|
|
|
areaChart.vm.onResize();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets area chart width', () => {
|
|
|
|
expect(areaChart.vm.width).toBe(mockWidth);
|
|
|
|
});
|
2019-05-30 16:15:17 +05:30
|
|
|
|
|
|
|
it('sets area chart height', () => {
|
|
|
|
expect(areaChart.vm.height).toBe(mockHeight);
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('computed', () => {
|
|
|
|
describe('chartData', () => {
|
|
|
|
it('utilizes all data points', () => {
|
2019-05-30 16:15:17 +05:30
|
|
|
expect(Object.keys(areaChart.vm.chartData)).toEqual(['Cores']);
|
|
|
|
expect(areaChart.vm.chartData.Cores.length).toBe(297);
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('creates valid data', () => {
|
2019-05-30 16:15:17 +05:30
|
|
|
const data = areaChart.vm.chartData.Cores;
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
expect(
|
|
|
|
data.filter(([time, value]) => new Date(time).getTime() > 0 && typeof value === 'number')
|
|
|
|
.length,
|
|
|
|
).toBe(data.length);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('scatterSeries', () => {
|
|
|
|
it('utilizes deployment data', () => {
|
|
|
|
expect(areaChart.vm.scatterSeries.data).toEqual([
|
|
|
|
['2017-05-31T21:23:37.881Z', 0],
|
|
|
|
['2017-05-30T20:08:04.629Z', 0],
|
|
|
|
['2017-05-30T17:42:38.409Z', 0],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
describe('xAxisLabel', () => {
|
|
|
|
it('constructs a label for the chart x-axis', () => {
|
|
|
|
expect(areaChart.vm.xAxisLabel).toBe('Core Usage');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
describe('yAxisLabel', () => {
|
|
|
|
it('constructs a label for the chart y-axis', () => {
|
2019-05-30 16:15:17 +05:30
|
|
|
expect(areaChart.vm.yAxisLabel).toBe('CPU (Cores)');
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|