debian-mirror-gitlab/spec/frontend/monitoring/embed/embed_spec.js

90 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-10-12 21:52:04 +05:30
import { createLocalVue, shallowMount } from '@vue/test-utils';
import Vuex from 'vuex';
2020-01-01 13:55:28 +05:30
import PanelType from 'ee_else_ce/monitoring/components/panel_type.vue';
2019-10-12 21:52:04 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2020-01-01 13:55:28 +05:30
import Embed from '~/monitoring/components/embed.vue';
2019-10-12 21:52:04 +05:30
import { groups, initialState, metricsData, metricsWithData } from './mock_data';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Embed', () => {
let wrapper;
let store;
let actions;
2020-01-01 13:55:28 +05:30
let metricsWithDataGetter;
2019-10-12 21:52:04 +05:30
function mountComponent() {
wrapper = shallowMount(Embed, {
localVue,
store,
propsData: {
dashboardUrl: TEST_HOST,
},
});
}
beforeEach(() => {
actions = {
setFeatureFlags: () => {},
setShowErrorBanner: () => {},
setEndpoints: () => {},
fetchMetricsData: () => {},
};
2020-01-01 13:55:28 +05:30
metricsWithDataGetter = jest.fn();
2019-10-12 21:52:04 +05:30
store = new Vuex.Store({
modules: {
monitoringDashboard: {
namespaced: true,
actions,
2020-01-01 13:55:28 +05:30
getters: {
metricsWithData: () => metricsWithDataGetter,
},
2019-10-12 21:52:04 +05:30
state: initialState,
},
},
});
});
afterEach(() => {
2020-01-01 13:55:28 +05:30
metricsWithDataGetter.mockClear();
2019-10-12 21:52:04 +05:30
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);
2020-01-01 13:55:28 +05:30
expect(wrapper.find(PanelType).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;
2020-01-01 13:55:28 +05:30
store.state.monitoringDashboard.dashboard.panel_groups[0].panels = metricsData;
metricsWithDataGetter.mockReturnValue(metricsWithData);
2019-10-12 21:52:04 +05:30
mountComponent();
});
it('shows a chart when metrics are present', () => {
expect(wrapper.find('.metrics-embed').exists()).toBe(true);
2020-01-01 13:55:28 +05:30
expect(wrapper.find(PanelType).exists()).toBe(true);
expect(wrapper.findAll(PanelType).length).toBe(2);
2019-10-12 21:52:04 +05:30
});
2019-12-21 20:55:43 +05:30
it('includes groupId with dashboardUrl', () => {
2020-01-01 13:55:28 +05:30
expect(wrapper.find(PanelType).props('groupId')).toBe(TEST_HOST);
2019-12-21 20:55:43 +05:30
});
2019-10-12 21:52:04 +05:30
});
});