debian-mirror-gitlab/spec/javascripts/monitoring/dashboard_spec.js

189 lines
5.9 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
import Dashboard from '~/monitoring/components/dashboard.vue';
import axios from '~/lib/utils/axios_utils';
2018-11-08 19:23:39 +05:30
import { metricsGroupsAPIResponse, mockApiEndpoint, environmentData } from './mock_data';
2017-09-10 17:25:29 +05:30
2018-12-05 23:21:45 +05:30
const propsData = {
hasMetrics: false,
documentationPath: '/path/to/docs',
settingsPath: '/path/to/settings',
clustersPath: '/path/to/clusters',
tagsPath: '/path/to/tags',
projectPath: '/path/to/project',
metricsEndpoint: mockApiEndpoint,
deploymentEndpoint: null,
emptyGettingStartedSvgPath: '/path/to/getting-started.svg',
emptyLoadingSvgPath: '/path/to/loading.svg',
emptyNoDataSvgPath: '/path/to/no-data.svg',
emptyUnableToConnectSvgPath: '/path/to/unable-to-connect.svg',
environmentsEndpoint: '/root/hello-prometheus/environments/35',
currentEnvironmentName: 'production',
};
export default propsData;
2018-03-17 18:26:18 +05:30
describe('Dashboard', () => {
let DashboardComponent;
2019-03-02 22:35:43 +05:30
let mock;
2018-03-27 19:54:05 +05:30
2017-09-10 17:25:29 +05:30
beforeEach(() => {
2018-12-05 23:21:45 +05:30
setFixtures(`
<div class="prometheus-graphs"></div>
2019-03-02 22:35:43 +05:30
<div class="layout-page"></div>
2018-12-05 23:21:45 +05:30
`);
2019-03-02 22:35:43 +05:30
mock = new MockAdapter(axios);
2018-03-17 18:26:18 +05:30
DashboardComponent = Vue.extend(Dashboard);
2017-09-10 17:25:29 +05:30
});
2019-03-02 22:35:43 +05:30
afterEach(() => {
mock.restore();
});
2017-09-10 17:25:29 +05:30
describe('no metrics are available yet', () => {
it('shows a getting started empty state when no metrics are present', () => {
2018-03-27 19:54:05 +05:30
const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData,
2017-09-10 17:25:29 +05:30
});
2018-03-27 19:54:05 +05:30
expect(component.$el.querySelector('.prometheus-graphs')).toBe(null);
2017-09-10 17:25:29 +05:30
expect(component.state).toEqual('gettingStarted');
});
});
describe('requests information to the server', () => {
beforeEach(() => {
2018-03-27 19:54:05 +05:30
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
2017-09-10 17:25:29 +05:30
});
2018-11-08 19:23:39 +05:30
it('shows up a loading state', done => {
2018-03-27 19:54:05 +05:30
const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, hasMetrics: true },
2017-09-10 17:25:29 +05:30
});
2018-03-27 19:54:05 +05:30
2017-09-10 17:25:29 +05:30
Vue.nextTick(() => {
expect(component.state).toEqual('loading');
done();
});
});
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
it('hides the legend when showLegend is false', done => {
2018-03-27 19:54:05 +05:30
const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, hasMetrics: true, showLegend: false },
});
setTimeout(() => {
expect(component.showEmptyState).toEqual(false);
expect(component.$el.querySelector('.legend-group')).toEqual(null);
expect(component.$el.querySelector('.prometheus-graph-group')).toBeTruthy();
done();
});
});
2018-11-08 19:23:39 +05:30
it('hides the group panels when showPanels is false', done => {
2018-03-27 19:54:05 +05:30
const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, hasMetrics: true, showPanels: false },
});
setTimeout(() => {
expect(component.showEmptyState).toEqual(false);
expect(component.$el.querySelector('.prometheus-panel')).toEqual(null);
expect(component.$el.querySelector('.prometheus-graph-group')).toBeTruthy();
done();
});
});
2018-11-08 19:23:39 +05:30
it('renders the dropdown with a number of environments', done => {
const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, hasMetrics: true, showPanels: false },
});
component.store.storeEnvironmentsData(environmentData);
setTimeout(() => {
const dropdownMenuEnvironments = component.$el.querySelectorAll('.dropdown-menu ul li a');
2018-12-13 13:39:08 +05:30
2018-11-08 19:23:39 +05:30
expect(dropdownMenuEnvironments.length).toEqual(component.store.environmentsData.length);
done();
});
});
2018-12-13 13:39:08 +05:30
it('hides the dropdown list when there is no environments', done => {
const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, hasMetrics: true, showPanels: false },
});
component.store.storeEnvironmentsData([]);
setTimeout(() => {
const dropdownMenuEnvironments = component.$el.querySelectorAll('.dropdown-menu ul');
expect(dropdownMenuEnvironments.length).toEqual(0);
done();
});
});
2018-11-08 19:23:39 +05:30
it('renders the dropdown with a single is-active element', done => {
const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, hasMetrics: true, showPanels: false },
});
component.store.storeEnvironmentsData(environmentData);
setTimeout(() => {
const dropdownIsActiveElement = component.$el.querySelectorAll(
'.dropdown-menu ul li a.is-active',
);
2018-12-13 13:39:08 +05:30
2018-11-08 19:23:39 +05:30
expect(dropdownIsActiveElement.length).toEqual(1);
expect(dropdownIsActiveElement[0].textContent.trim()).toEqual(
component.currentEnvironmentName,
);
done();
});
});
2017-09-10 17:25:29 +05:30
});
2018-12-05 23:21:45 +05:30
describe('when the window resizes', () => {
beforeEach(() => {
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
jasmine.clock().install();
});
afterEach(() => {
jasmine.clock().uninstall();
});
2019-03-02 22:35:43 +05:30
it('sets elWidth to page width when the sidebar is resized', done => {
2018-12-05 23:21:45 +05:30
const component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, hasMetrics: true, showPanels: false },
});
2019-03-02 22:35:43 +05:30
expect(component.elWidth).toEqual(0);
2018-12-05 23:21:45 +05:30
2019-03-02 22:35:43 +05:30
const pageLayoutEl = document.querySelector('.layout-page');
pageLayoutEl.classList.add('page-with-icon-sidebar');
2018-12-05 23:21:45 +05:30
Vue.nextTick()
.then(() => {
jasmine.clock().tick(1000);
return Vue.nextTick();
})
.then(() => {
2019-03-02 22:35:43 +05:30
expect(component.elWidth).toEqual(pageLayoutEl.clientWidth);
2018-12-05 23:21:45 +05:30
done();
})
.catch(done.fail);
});
});
2017-09-10 17:25:29 +05:30
});