2020-03-13 15:44:24 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import { createLocalVue } from '@vue/test-utils';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import Dashboard from '~/monitoring/components/dashboard.vue';
|
|
|
|
import { createStore } from '~/monitoring/stores';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-04-22 19:07:51 +05:30
|
|
|
import { mockApiEndpoint, propsData } from '../mock_data';
|
|
|
|
import { metricsDashboardPayload } from '../fixture_data';
|
|
|
|
import { setupStoreWithData } from '../store_utils';
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
|
|
|
|
describe('Dashboard', () => {
|
|
|
|
let DashboardComponent;
|
|
|
|
let mock;
|
|
|
|
let store;
|
|
|
|
let component;
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(`
|
|
|
|
<div class="prometheus-graphs"></div>
|
|
|
|
<div class="layout-page"></div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
store = createStore();
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
DashboardComponent = localVue.extend(Dashboard);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
if (component) {
|
|
|
|
component.$destroy();
|
|
|
|
}
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
}
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('responds to window resizes', () => {
|
|
|
|
let promPanel;
|
|
|
|
let promGroup;
|
|
|
|
let panelToggle;
|
|
|
|
let chart;
|
|
|
|
beforeEach(() => {
|
|
|
|
mock.onGet(mockApiEndpoint).reply(200, metricsDashboardPayload);
|
|
|
|
|
|
|
|
component = new DashboardComponent({
|
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
hasMetrics: true,
|
|
|
|
showPanels: true,
|
|
|
|
},
|
|
|
|
store,
|
|
|
|
});
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
setupStoreWithData(component.$store);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
return Vue.nextTick().then(() => {
|
2020-04-08 14:13:33 +05:30
|
|
|
[promPanel] = component.$el.querySelectorAll('.prometheus-panel');
|
2020-03-13 15:44:24 +05:30
|
|
|
promGroup = promPanel.querySelector('.prometheus-graph-group');
|
|
|
|
panelToggle = promPanel.querySelector('.js-graph-group-toggle');
|
|
|
|
chart = promGroup.querySelector('.position-relative svg');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('setting chart size to zero when panel group is hidden', () => {
|
|
|
|
expect(promGroup.style.display).toBe('');
|
|
|
|
expect(chart.clientWidth).toBeGreaterThan(0);
|
|
|
|
|
|
|
|
panelToggle.click();
|
|
|
|
return Vue.nextTick().then(() => {
|
|
|
|
expect(promGroup.style.display).toBe('none');
|
|
|
|
expect(chart.clientWidth).toBe(0);
|
|
|
|
promPanel.style.width = '500px';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('expanding chart panel group after resize displays chart', () => {
|
|
|
|
panelToggle.click();
|
|
|
|
|
|
|
|
expect(chart.clientWidth).toBeGreaterThan(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|