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
|
import { shallowMount } from '@vue/test-utils';
import { createStore } from '~/monitoring/stores';
import DashboardPage from '~/monitoring/pages/dashboard_page.vue';
import Dashboard from '~/monitoring/components/dashboard.vue';
import { dashboardProps } from '../fixture_data';
describe('monitoring/pages/dashboard_page', () => {
let wrapper;
let store;
let $route;
const buildRouter = () => {
const dashboard = {};
$route = {
params: { dashboard },
query: { dashboard },
};
};
const buildWrapper = (props = {}) => {
wrapper = shallowMount(DashboardPage, {
store,
propsData: {
...props,
},
mocks: {
$route,
},
});
};
const findDashboardComponent = () => wrapper.find(Dashboard);
beforeEach(() => {
buildRouter();
store = createStore();
jest.spyOn(store, 'dispatch').mockResolvedValue();
});
afterEach(() => {
if (wrapper) {
wrapper.destroy();
wrapper = null;
}
});
it('throws errors if dashboard props are not passed', () => {
expect(() => buildWrapper()).toThrow('Missing required prop: "dashboardProps"');
});
it('renders the dashboard page with dashboard component', () => {
buildWrapper({ dashboardProps });
const allProps = {
...dashboardProps,
// default props values
rearrangePanelsAvailable: false,
showHeader: true,
showPanels: true,
smallEmptyState: false,
};
expect(findDashboardComponent()).toExist();
expect(allProps).toMatchObject(findDashboardComponent().props());
});
});
|