Welcome to mirror list, hosted at ThFree Co, Russian Federation.

router_spec.js « monitoring « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b97c8ed1258d299c5a4ef75d4af00471e959396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { mount, createLocalVue } from '@vue/test-utils';
import VueRouter from 'vue-router';
import DashboardPage from '~/monitoring/pages/dashboard_page.vue';
import PanelNewPage from '~/monitoring/pages/panel_new_page.vue';
import Dashboard from '~/monitoring/components/dashboard.vue';
import { createStore } from '~/monitoring/stores';
import createRouter from '~/monitoring/router';
import { dashboardProps } from './fixture_data';
import { dashboardHeaderProps } from './mock_data';

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"/>`,
};

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);
    }

    return mount(MockApp, {
      localVue,
      store,
      router,
    });
  };

  beforeEach(() => {
    store = createStore();
    jest.spyOn(store, 'dispatch').mockResolvedValue();
  });

  afterEach(() => {
    window.location.hash = '';
  });

  describe('support legacy URLs with full dashboard path to visit dashboard page', () => {
    it.each`
      path                           | currentDashboard
      ${'/dashboard.yml'}            | ${'dashboard.yml'}
      ${'/folder1/dashboard.yml'}    | ${'folder1/dashboard.yml'}
      ${'/?dashboard=dashboard.yml'} | ${'dashboard.yml'}
    `('"$path" renders page with dashboard "$currentDashboard"', ({ path, currentDashboard }) => {
      const wrapper = createWrapper(LEGACY_BASE_PATH, path);

      expect(store.dispatch).toHaveBeenCalledWith('monitoringDashboard/setCurrentDashboard', {
        currentDashboard,
      });

      expect(wrapper.find(DashboardPage).exists()).toBe(true);
      expect(
        wrapper
          .find(DashboardPage)
          .find(Dashboard)
          .exists(),
      ).toBe(true);
    });
  });

  describe('supports URLs to visit dashboard page', () => {
    it.each`
      path                                        | currentDashboard
      ${'/'}                                      | ${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'}
    `('"$path" renders page with dashboard "$currentDashboard"', ({ path, currentDashboard }) => {
      const wrapper = createWrapper(BASE_PATH, path);

      expect(store.dispatch).toHaveBeenCalledWith('monitoringDashboard/setCurrentDashboard', {
        currentDashboard,
      });

      expect(wrapper.find(DashboardPage).exists()).toBe(true);
      expect(
        wrapper
          .find(DashboardPage)
          .find(Dashboard)
          .exists(),
      ).toBe(true);
    });
  });

  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);
    });
  });
});