2019-10-12 21:52:04 +05:30
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import Embed from '~/monitoring/components/embed.vue';
|
2019-12-04 20:38:33 +05:30
|
|
|
import MonitorTimeSeriesChart from '~/monitoring/components/charts/time_series.vue';
|
2019-10-12 21:52:04 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
|
|
|
import { groups, initialState, metricsData, metricsWithData } from './mock_data';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
describe('Embed', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
let actions;
|
|
|
|
|
|
|
|
function mountComponent() {
|
|
|
|
wrapper = shallowMount(Embed, {
|
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
dashboardUrl: TEST_HOST,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
actions = {
|
|
|
|
setFeatureFlags: () => {},
|
|
|
|
setShowErrorBanner: () => {},
|
|
|
|
setEndpoints: () => {},
|
|
|
|
fetchMetricsData: () => {},
|
|
|
|
};
|
|
|
|
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
monitoringDashboard: {
|
|
|
|
namespaced: true,
|
|
|
|
actions,
|
|
|
|
state: initialState,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('no metrics are available yet', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows an empty state when no metrics are present', () => {
|
|
|
|
expect(wrapper.find('.metrics-embed').exists()).toBe(true);
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(wrapper.find(MonitorTimeSeriesChart).exists()).toBe(false);
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('metrics are available', () => {
|
|
|
|
beforeEach(() => {
|
2019-12-26 22:10:19 +05:30
|
|
|
store.state.monitoringDashboard.dashboard.panel_groups = groups;
|
|
|
|
store.state.monitoringDashboard.dashboard.panel_groups[0].metrics = metricsData;
|
2019-10-12 21:52:04 +05:30
|
|
|
store.state.monitoringDashboard.metricsWithData = metricsWithData;
|
|
|
|
|
|
|
|
mountComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows a chart when metrics are present', () => {
|
|
|
|
wrapper.setProps({});
|
|
|
|
expect(wrapper.find('.metrics-embed').exists()).toBe(true);
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(wrapper.find(MonitorTimeSeriesChart).exists()).toBe(true);
|
|
|
|
expect(wrapper.findAll(MonitorTimeSeriesChart).length).toBe(2);
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
it('includes groupId with dashboardUrl', () => {
|
|
|
|
expect(wrapper.find(MonitorTimeSeriesChart).props('groupId')).toBe(TEST_HOST);
|
|
|
|
});
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
|
|
|
});
|