2020-06-23 00:09:42 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Dashboard from '~/monitoring/components/dashboard.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import DashboardPage from '~/monitoring/pages/dashboard_page.vue';
|
|
|
|
import { createStore } from '~/monitoring/stores';
|
2023-06-20 00:43:36 +05:30
|
|
|
import { assertProps } from 'helpers/assert_props';
|
2020-07-28 23:09:34 +05:30
|
|
|
import { dashboardProps } from '../fixture_data';
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
describe('monitoring/pages/dashboard_page', () => {
|
|
|
|
let wrapper;
|
2020-07-28 23:09:34 +05:30
|
|
|
let store;
|
|
|
|
let $route;
|
|
|
|
|
|
|
|
const buildRouter = () => {
|
|
|
|
const dashboard = {};
|
|
|
|
$route = {
|
|
|
|
params: { dashboard },
|
|
|
|
query: { dashboard },
|
|
|
|
};
|
|
|
|
};
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
const buildWrapper = (props = {}) => {
|
|
|
|
wrapper = shallowMount(DashboardPage, {
|
2020-07-28 23:09:34 +05:30
|
|
|
store,
|
2020-06-23 00:09:42 +05:30
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
2020-07-28 23:09:34 +05:30
|
|
|
mocks: {
|
|
|
|
$route,
|
|
|
|
},
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
const findDashboardComponent = () => wrapper.findComponent(Dashboard);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
buildRouter();
|
|
|
|
store = createStore();
|
|
|
|
jest.spyOn(store, 'dispatch').mockResolvedValue();
|
|
|
|
});
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it('throws errors if dashboard props are not passed', () => {
|
2023-06-20 00:43:36 +05:30
|
|
|
expect(() => assertProps(DashboardPage, {})).toThrow('Missing required prop: "dashboardProps"');
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the dashboard page with dashboard component', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
buildWrapper({ dashboardProps });
|
|
|
|
|
|
|
|
const allProps = {
|
|
|
|
...dashboardProps,
|
|
|
|
// default props values
|
|
|
|
rearrangePanelsAvailable: false,
|
|
|
|
showHeader: true,
|
|
|
|
showPanels: true,
|
|
|
|
smallEmptyState: false,
|
|
|
|
};
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(findDashboardComponent().exists()).toBe(true);
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(allProps).toMatchObject(findDashboardComponent().props());
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|