2019-10-12 21:52:04 +05:30
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
|
|
import Vuex from 'vuex';
|
2020-05-24 23:13:21 +05:30
|
|
|
import DashboardPanel from '~/monitoring/components/dashboard_panel.vue';
|
2019-10-12 21:52:04 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2020-04-22 19:07:51 +05:30
|
|
|
import MetricEmbed from '~/monitoring/components/embeds/metric_embed.vue';
|
2019-10-12 21:52:04 +05:30
|
|
|
import { groups, initialState, metricsData, metricsWithData } from './mock_data';
|
2020-06-23 00:09:42 +05:30
|
|
|
import { setHTMLFixture } from 'helpers/fixtures';
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
describe('MetricEmbed', () => {
|
2019-10-12 21:52:04 +05:30
|
|
|
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() {
|
2020-04-22 19:07:51 +05:30
|
|
|
wrapper = shallowMount(MetricEmbed, {
|
2019-10-12 21:52:04 +05:30
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
dashboardUrl: TEST_HOST,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
setHTMLFixture('<div class="layout-page"></div>');
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
actions = {
|
2020-04-22 19:07:51 +05:30
|
|
|
setInitialState: jest.fn(),
|
2020-03-13 15:44:24 +05:30
|
|
|
setShowErrorBanner: 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-05-24 23:13:21 +05:30
|
|
|
expect(wrapper.find(DashboardPanel).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-05-24 23:13:21 +05:30
|
|
|
expect(wrapper.find(DashboardPanel).exists()).toBe(true);
|
|
|
|
expect(wrapper.findAll(DashboardPanel).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-05-24 23:13:21 +05:30
|
|
|
expect(wrapper.find(DashboardPanel).props('groupId')).toBe(TEST_HOST);
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
|
|
|
});
|