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 = {
|
2020-03-13 15:44:24 +05:30
|
|
|
setFeatureFlags: jest.fn(),
|
|
|
|
setShowErrorBanner: jest.fn(),
|
|
|
|
setEndpoints: jest.fn(),
|
|
|
|
setTimeRange: jest.fn(),
|
|
|
|
fetchDashboard: jest.fn(),
|
2019-10-12 21:52:04 +05:30
|
|
|
};
|
|
|
|
|
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(() => {
|
2020-04-08 14:13:33 +05:30
|
|
|
store.state.monitoringDashboard.dashboard.panelGroups = groups;
|
|
|
|
store.state.monitoringDashboard.dashboard.panelGroups[0].panels = metricsData;
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
metricsWithDataGetter.mockReturnValue(metricsWithData);
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
mountComponent();
|
|
|
|
});
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it('calls actions to fetch data', () => {
|
|
|
|
const expectedTimeRangePayload = expect.objectContaining({
|
|
|
|
start: expect.any(String),
|
|
|
|
end: expect.any(String),
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(actions.setTimeRange).toHaveBeenCalledTimes(1);
|
|
|
|
expect(actions.setTimeRange.mock.calls[0][1]).toEqual(expectedTimeRangePayload);
|
|
|
|
|
|
|
|
expect(actions.fetchDashboard).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
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
|
|
|
});
|
|
|
|
});
|