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

131 lines
4.4 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-03-17 18:26:18 +05:30
describe('Dashboard', () => {
let DashboardComponent;
2018-03-27 19:54:05 +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',
2018-05-09 12:01:36 +05:30
emptyNoDataSvgPath: '/path/to/no-data.svg',
2018-03-27 19:54:05 +05:30
emptyUnableToConnectSvgPath: '/path/to/unable-to-connect.svg',
2018-11-08 19:23:39 +05:30
environmentsEndpoint: '/root/hello-prometheus/environments/35',
currentEnvironmentName: 'production',
2018-03-27 19:54:05 +05:30
};
2017-09-10 17:25:29 +05:30
beforeEach(() => {
2018-03-27 19:54:05 +05:30
setFixtures('<div class="prometheus-graphs"></div>');
2018-03-17 18:26:18 +05:30
DashboardComponent = Vue.extend(Dashboard);
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', () => {
2018-03-17 18:26:18 +05:30
let mock;
2017-09-10 17:25:29 +05:30
beforeEach(() => {
2018-03-17 18:26:18 +05:30
mock = new MockAdapter(axios);
2018-03-27 19:54:05 +05:30
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
2017-09-10 17:25:29 +05:30
});
afterEach(() => {
2018-03-17 18:26:18 +05:30
mock.restore();
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');
expect(dropdownMenuEnvironments.length).toEqual(component.store.environmentsData.length);
done();
});
});
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',
);
expect(dropdownIsActiveElement.length).toEqual(1);
expect(dropdownIsActiveElement[0].textContent.trim()).toEqual(
component.currentEnvironmentName,
);
done();
});
});
2017-09-10 17:25:29 +05:30
});
});