debian-mirror-gitlab/spec/frontend/monitoring/pages/dashboard_page_spec.js

67 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-06-23 00:09:42 +05:30
import { shallowMount } from '@vue/test-utils';
2020-07-28 23:09:34 +05:30
import { createStore } from '~/monitoring/stores';
2020-06-23 00:09:42 +05:30
import DashboardPage from '~/monitoring/pages/dashboard_page.vue';
import Dashboard from '~/monitoring/components/dashboard.vue';
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
});
};
const findDashboardComponent = () => wrapper.find(Dashboard);
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
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', () => {
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
expect(findDashboardComponent()).toExist();
2020-07-28 23:09:34 +05:30
expect(allProps).toMatchObject(findDashboardComponent().props());
2020-06-23 00:09:42 +05:30
});
});