2020-07-28 23:09:34 +05:30
|
|
|
import { mount, createLocalVue } from '@vue/test-utils';
|
|
|
|
import VueRouter from 'vue-router';
|
2021-03-11 19:13:27 +05:30
|
|
|
import Dashboard from '~/monitoring/components/dashboard.vue';
|
2020-07-28 23:09:34 +05:30
|
|
|
import DashboardPage from '~/monitoring/pages/dashboard_page.vue';
|
2020-10-24 23:57:45 +05:30
|
|
|
import PanelNewPage from '~/monitoring/pages/panel_new_page.vue';
|
2020-07-28 23:09:34 +05:30
|
|
|
import createRouter from '~/monitoring/router';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { createStore } from '~/monitoring/stores';
|
2020-07-28 23:09:34 +05:30
|
|
|
import { dashboardProps } from './fixture_data';
|
|
|
|
import { dashboardHeaderProps } from './mock_data';
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
const LEGACY_BASE_PATH = '/project/my-group/test-project/-/environments/71146/metrics';
|
|
|
|
const BASE_PATH = '/project/my-group/test-project/-/metrics';
|
|
|
|
|
|
|
|
const MockApp = {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
dashboardProps: { ...dashboardProps, ...dashboardHeaderProps },
|
|
|
|
};
|
|
|
|
},
|
|
|
|
template: `<router-view :dashboard-props="dashboardProps"/>`,
|
|
|
|
};
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
const provide = { hasManagedPrometheus: false };
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe('Monitoring router', () => {
|
|
|
|
let router;
|
|
|
|
let store;
|
|
|
|
|
|
|
|
const createWrapper = (basePath, routeArg) => {
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(VueRouter);
|
|
|
|
|
|
|
|
router = createRouter(basePath);
|
|
|
|
if (routeArg !== undefined) {
|
|
|
|
router.push(routeArg);
|
|
|
|
}
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
return mount(MockApp, {
|
2020-07-28 23:09:34 +05:30
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
router,
|
2021-06-08 01:23:25 +05:30
|
|
|
provide,
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore();
|
|
|
|
jest.spyOn(store, 'dispatch').mockResolvedValue();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
window.location.hash = '';
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('support legacy URLs with full dashboard path to visit dashboard page', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
it.each`
|
2020-10-24 23:57:45 +05:30
|
|
|
path | currentDashboard
|
2020-07-28 23:09:34 +05:30
|
|
|
${'/dashboard.yml'} | ${'dashboard.yml'}
|
|
|
|
${'/folder1/dashboard.yml'} | ${'folder1/dashboard.yml'}
|
|
|
|
${'/?dashboard=dashboard.yml'} | ${'dashboard.yml'}
|
2020-10-24 23:57:45 +05:30
|
|
|
`('"$path" renders page with dashboard "$currentDashboard"', ({ path, currentDashboard }) => {
|
|
|
|
const wrapper = createWrapper(LEGACY_BASE_PATH, path);
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('monitoringDashboard/setCurrentDashboard', {
|
|
|
|
currentDashboard,
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(wrapper.find(DashboardPage).exists()).toBe(true);
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find(DashboardPage).find(Dashboard).exists()).toBe(true);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('supports URLs to visit dashboard page', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
it.each`
|
2020-10-24 23:57:45 +05:30
|
|
|
path | currentDashboard
|
2020-07-28 23:09:34 +05:30
|
|
|
${'/'} | ${null}
|
|
|
|
${'/dashboard.yml'} | ${'dashboard.yml'}
|
|
|
|
${'/folder1/dashboard.yml'} | ${'folder1/dashboard.yml'}
|
|
|
|
${'/folder1%2Fdashboard.yml'} | ${'folder1/dashboard.yml'}
|
|
|
|
${'/dashboard.yml'} | ${'dashboard.yml'}
|
|
|
|
${'/config/prometheus/common_metrics.yml'} | ${'config/prometheus/common_metrics.yml'}
|
|
|
|
${'/config/prometheus/pod_metrics.yml'} | ${'config/prometheus/pod_metrics.yml'}
|
|
|
|
${'/config%2Fprometheus%2Fpod_metrics.yml'} | ${'config/prometheus/pod_metrics.yml'}
|
2020-10-24 23:57:45 +05:30
|
|
|
`('"$path" renders page with dashboard "$currentDashboard"', ({ path, currentDashboard }) => {
|
|
|
|
const wrapper = createWrapper(BASE_PATH, path);
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('monitoringDashboard/setCurrentDashboard', {
|
|
|
|
currentDashboard,
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(wrapper.find(DashboardPage).exists()).toBe(true);
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find(DashboardPage).find(Dashboard).exists()).toBe(true);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('supports URLs to visit new panel page', () => {
|
|
|
|
it.each`
|
|
|
|
path | currentDashboard
|
|
|
|
${'/panel/new'} | ${undefined}
|
|
|
|
${'/dashboard.yml/panel/new'} | ${'dashboard.yml'}
|
|
|
|
${'/config/prometheus/common_metrics.yml/panel/new'} | ${'config/prometheus/common_metrics.yml'}
|
|
|
|
${'/config%2Fprometheus%2Fcommon_metrics.yml/panel/new'} | ${'config/prometheus/common_metrics.yml'}
|
|
|
|
`('"$path" renders page with dashboard "$currentDashboard"', ({ path, currentDashboard }) => {
|
|
|
|
const wrapper = createWrapper(BASE_PATH, path);
|
|
|
|
|
|
|
|
expect(wrapper.vm.$route.params.dashboard).toBe(currentDashboard);
|
|
|
|
expect(wrapper.find(PanelNewPage).exists()).toBe(true);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|