2020-06-16 11:08:32 -04:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Dashboard from '~/monitoring/components/dashboard.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import DashboardPage from '~/monitoring/pages/dashboard_page.vue';
|
|
|
|
import { createStore } from '~/monitoring/stores';
|
2020-07-02 11:09:08 -04:00
|
|
|
import { dashboardProps } from '../fixture_data';
|
2020-06-16 11:08:32 -04:00
|
|
|
|
|
|
|
describe('monitoring/pages/dashboard_page', () => {
|
|
|
|
let wrapper;
|
2020-07-15 17:09:26 -04:00
|
|
|
let store;
|
|
|
|
let $route;
|
|
|
|
|
|
|
|
const buildRouter = () => {
|
|
|
|
const dashboard = {};
|
|
|
|
$route = {
|
|
|
|
params: { dashboard },
|
|
|
|
query: { dashboard },
|
|
|
|
};
|
|
|
|
};
|
2020-06-16 11:08:32 -04:00
|
|
|
|
|
|
|
const buildWrapper = (props = {}) => {
|
|
|
|
wrapper = shallowMount(DashboardPage, {
|
2020-07-15 17:09:26 -04:00
|
|
|
store,
|
2020-06-16 11:08:32 -04:00
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
2020-07-15 17:09:26 -04:00
|
|
|
mocks: {
|
|
|
|
$route,
|
|
|
|
},
|
2020-06-16 11:08:32 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-11-10 01:10:31 -05:00
|
|
|
const findDashboardComponent = () => wrapper.findComponent(Dashboard);
|
2020-06-16 11:08:32 -04:00
|
|
|
|
2020-07-15 17:09:26 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
buildRouter();
|
|
|
|
store = createStore();
|
|
|
|
jest.spyOn(store, 'dispatch').mockResolvedValue();
|
|
|
|
});
|
|
|
|
|
2020-06-16 11:08:32 -04:00
|
|
|
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-02 11:09:08 -04:00
|
|
|
buildWrapper({ dashboardProps });
|
|
|
|
|
|
|
|
const allProps = {
|
|
|
|
...dashboardProps,
|
|
|
|
// default props values
|
|
|
|
rearrangePanelsAvailable: false,
|
|
|
|
showHeader: true,
|
|
|
|
showPanels: true,
|
|
|
|
smallEmptyState: false,
|
|
|
|
};
|
2020-06-16 11:08:32 -04:00
|
|
|
|
2021-11-10 01:10:31 -05:00
|
|
|
expect(findDashboardComponent().exists()).toBe(true);
|
2020-07-02 11:09:08 -04:00
|
|
|
expect(allProps).toMatchObject(findDashboardComponent().props());
|
2020-06-16 11:08:32 -04:00
|
|
|
});
|
|
|
|
});
|