2022-01-21 15:13:54 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Vue from 'vue';
|
2020-07-15 21:09:26 +00:00
|
|
|
import VueRouter from 'vue-router';
|
2021-02-14 18:09:20 +00:00
|
|
|
import Dashboard from '~/monitoring/components/dashboard.vue';
|
2020-07-15 21:09:26 +00:00
|
|
|
import DashboardPage from '~/monitoring/pages/dashboard_page.vue';
|
2020-07-30 06:09:55 +00:00
|
|
|
import PanelNewPage from '~/monitoring/pages/panel_new_page.vue';
|
2020-07-15 21:09:26 +00:00
|
|
|
import createRouter from '~/monitoring/router';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { createStore } from '~/monitoring/stores';
|
2020-07-15 21:09:26 +00:00
|
|
|
import { dashboardProps } from './fixture_data';
|
|
|
|
import { dashboardHeaderProps } from './mock_data';
|
|
|
|
|
2020-07-30 06:09:55 +00:00
|
|
|
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"/>`,
|
|
|
|
};
|
|
|
|
|
2020-07-15 21:09:26 +00:00
|
|
|
describe('Monitoring router', () => {
|
|
|
|
let router;
|
|
|
|
let store;
|
|
|
|
|
|
|
|
const createWrapper = (basePath, routeArg) => {
|
2022-01-21 15:13:54 +00:00
|
|
|
Vue.use(VueRouter);
|
2020-07-15 21:09:26 +00:00
|
|
|
|
|
|
|
router = createRouter(basePath);
|
|
|
|
if (routeArg !== undefined) {
|
|
|
|
router.push(routeArg);
|
|
|
|
}
|
|
|
|
|
2020-07-30 06:09:55 +00:00
|
|
|
return mount(MockApp, {
|
2020-07-15 21:09:26 +00:00
|
|
|
store,
|
|
|
|
router,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore();
|
|
|
|
jest.spyOn(store, 'dispatch').mockResolvedValue();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
window.location.hash = '';
|
|
|
|
});
|
|
|
|
|
2020-07-30 06:09:55 +00:00
|
|
|
describe('support legacy URLs with full dashboard path to visit dashboard page', () => {
|
2020-07-15 21:09:26 +00:00
|
|
|
it.each`
|
2020-07-30 06:09:55 +00:00
|
|
|
path | currentDashboard
|
2020-07-15 21:09:26 +00:00
|
|
|
${'/dashboard.yml'} | ${'dashboard.yml'}
|
|
|
|
${'/folder1/dashboard.yml'} | ${'folder1/dashboard.yml'}
|
|
|
|
${'/?dashboard=dashboard.yml'} | ${'dashboard.yml'}
|
2020-07-30 06:09:55 +00:00
|
|
|
`('"$path" renders page with dashboard "$currentDashboard"', ({ path, currentDashboard }) => {
|
|
|
|
const wrapper = createWrapper(LEGACY_BASE_PATH, path);
|
2020-07-15 21:09:26 +00:00
|
|
|
|
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('monitoringDashboard/setCurrentDashboard', {
|
|
|
|
currentDashboard,
|
|
|
|
});
|
|
|
|
|
2022-08-16 03:11:31 +00:00
|
|
|
expect(wrapper.findComponent(DashboardPage).exists()).toBe(true);
|
|
|
|
expect(wrapper.findComponent(DashboardPage).findComponent(Dashboard).exists()).toBe(true);
|
2020-07-15 21:09:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-30 06:09:55 +00:00
|
|
|
describe('supports URLs to visit dashboard page', () => {
|
2020-07-15 21:09:26 +00:00
|
|
|
it.each`
|
2020-07-30 06:09:55 +00:00
|
|
|
path | currentDashboard
|
2020-07-15 21:09:26 +00:00
|
|
|
${'/'} | ${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-07-30 06:09:55 +00:00
|
|
|
`('"$path" renders page with dashboard "$currentDashboard"', ({ path, currentDashboard }) => {
|
|
|
|
const wrapper = createWrapper(BASE_PATH, path);
|
2020-07-15 21:09:26 +00:00
|
|
|
|
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('monitoringDashboard/setCurrentDashboard', {
|
|
|
|
currentDashboard,
|
|
|
|
});
|
|
|
|
|
2022-08-16 03:11:31 +00:00
|
|
|
expect(wrapper.findComponent(DashboardPage).exists()).toBe(true);
|
|
|
|
expect(wrapper.findComponent(DashboardPage).findComponent(Dashboard).exists()).toBe(true);
|
2020-07-30 06:09:55 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('supports URLs to visit new panel page', () => {
|
|
|
|
it.each`
|
|
|
|
path | currentDashboard
|
|
|
|
${'/panel/new'} | ${undefined}
|
|
|
|
${'/dashboard.yml/panel/new'} | ${'dashboard.yml'}
|
2020-10-29 09:08:38 +00:00
|
|
|
${'/config/prometheus/common_metrics.yml/panel/new'} | ${'config/prometheus/common_metrics.yml'}
|
|
|
|
${'/config%2Fprometheus%2Fcommon_metrics.yml/panel/new'} | ${'config/prometheus/common_metrics.yml'}
|
2020-07-30 06:09:55 +00:00
|
|
|
`('"$path" renders page with dashboard "$currentDashboard"', ({ path, currentDashboard }) => {
|
|
|
|
const wrapper = createWrapper(BASE_PATH, path);
|
|
|
|
|
|
|
|
expect(wrapper.vm.$route.params.dashboard).toBe(currentDashboard);
|
2022-08-16 03:11:31 +00:00
|
|
|
expect(wrapper.findComponent(PanelNewPage).exists()).toBe(true);
|
2020-07-15 21:09:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|