Commit e0156b14 authored by Miguel Rincon's avatar Miguel Rincon

Use bar generated data instead of hardcoded data

Mock bar chart's data with generated data instead of hardcoded data
parent e8c7d7ed
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlBarChart } from '@gitlab/ui/dist/charts'; import { GlBarChart } from '@gitlab/ui/dist/charts';
import Bar from '~/monitoring/components/charts/bar.vue'; import Bar from '~/monitoring/components/charts/bar.vue';
import { barMockData } from '../../mock_data'; import { barGraphData } from '../../graph_data';
jest.mock('~/lib/utils/icon_utils', () => ({ jest.mock('~/lib/utils/icon_utils', () => ({
getSvgIconPathContent: jest.fn().mockResolvedValue('mockSvgPathContent'), getSvgIconPathContent: jest.fn().mockResolvedValue('mockSvgPathContent'),
...@@ -10,11 +10,14 @@ jest.mock('~/lib/utils/icon_utils', () => ({ ...@@ -10,11 +10,14 @@ jest.mock('~/lib/utils/icon_utils', () => ({
describe('Bar component', () => { describe('Bar component', () => {
let barChart; let barChart;
let store; let store;
let graphData;
beforeEach(() => { beforeEach(() => {
graphData = barGraphData();
barChart = shallowMount(Bar, { barChart = shallowMount(Bar, {
propsData: { propsData: {
graphData: barMockData, graphData,
}, },
store, store,
}); });
...@@ -31,7 +34,7 @@ describe('Bar component', () => { ...@@ -31,7 +34,7 @@ describe('Bar component', () => {
beforeEach(() => { beforeEach(() => {
glbarChart = barChart.find(GlBarChart); glbarChart = barChart.find(GlBarChart);
chartData = barChart.vm.chartData[barMockData.metrics[0].label]; chartData = barChart.vm.chartData[graphData.metrics[0].label];
}); });
it('is a Vue instance', () => { it('is a Vue instance', () => {
...@@ -39,7 +42,7 @@ describe('Bar component', () => { ...@@ -39,7 +42,7 @@ describe('Bar component', () => {
}); });
it('should display a label on the x axis', () => { it('should display a label on the x axis', () => {
expect(glbarChart.vm.xAxisTitle).toBe(barMockData.xLabel); expect(glbarChart.props('xAxisTitle')).toBe(graphData.xLabel);
}); });
it('should return chartData as array of arrays', () => { it('should return chartData as array of arrays', () => {
......
...@@ -15,10 +15,14 @@ import { ...@@ -15,10 +15,14 @@ import {
mockNamespace, mockNamespace,
mockNamespacedData, mockNamespacedData,
mockTimeRange, mockTimeRange,
barMockData,
} from '../mock_data'; } from '../mock_data';
import { dashboardProps, graphData, graphDataEmpty } from '../fixture_data'; import { dashboardProps, graphData, graphDataEmpty } from '../fixture_data';
import { anomalyGraphData, singleStatGraphData, heatmapGraphData } from '../graph_data'; import {
anomalyGraphData,
singleStatGraphData,
heatmapGraphData,
barGraphData,
} from '../graph_data';
import { panelTypes } from '~/monitoring/constants'; import { panelTypes } from '~/monitoring/constants';
...@@ -240,7 +244,7 @@ describe('Dashboard Panel', () => { ...@@ -240,7 +244,7 @@ describe('Dashboard Panel', () => {
${dataWithType(panelTypes.COLUMN)} | ${MonitorColumnChart} | ${false} ${dataWithType(panelTypes.COLUMN)} | ${MonitorColumnChart} | ${false}
${dataWithType(panelTypes.STACKED_COLUMN)} | ${MonitorStackedColumnChart} | ${false} ${dataWithType(panelTypes.STACKED_COLUMN)} | ${MonitorStackedColumnChart} | ${false}
${heatmapGraphData()} | ${MonitorHeatmapChart} | ${false} ${heatmapGraphData()} | ${MonitorHeatmapChart} | ${false}
${barMockData} | ${MonitorBarChart} | ${false} ${barGraphData()} | ${MonitorBarChart} | ${false}
`('when $data.type data is provided', ({ data, component, hasCtxMenu }) => { `('when $data.type data is provided', ({ data, component, hasCtxMenu }) => {
const attrs = { attr1: 'attr1Value', attr2: 'attr2Value' }; const attrs = { attr1: 'attr1Value', attr2: 'attr2Value' };
......
...@@ -259,3 +259,16 @@ export const stackedColumnGraphData = (panelOptions = {}, dataOptions = {}) => { ...@@ -259,3 +259,16 @@ export const stackedColumnGraphData = (panelOptions = {}, dataOptions = {}) => {
type: panelTypes.STACKED_COLUMN, type: panelTypes.STACKED_COLUMN,
}; };
}; };
/**
* Generates bar mock graph data according to options
*
* @param {Object} panelOptions - Panel options as in YML.
* @param {Object} dataOptions
*/
export const barGraphData = (panelOptions = {}, dataOptions = {}) => {
return {
...timeSeriesGraphData(panelOptions, dataOptions),
type: panelTypes.BAR,
};
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment