2017-06-20 04:50:31 -04:00
|
|
|
import Vue from 'vue';
|
2017-11-22 11:33:53 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2017-08-30 12:11:19 -04:00
|
|
|
import Dashboard from '~/monitoring/components/dashboard.vue';
|
2017-11-22 11:33:53 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2018-06-29 15:07:34 -04:00
|
|
|
import { metricsGroupsAPIResponse, mockApiEndpoint, environmentData } from './mock_data';
|
2017-06-20 04:50:31 -04:00
|
|
|
|
2017-08-30 12:11:19 -04:00
|
|
|
describe('Dashboard', () => {
|
|
|
|
let DashboardComponent;
|
2018-03-06 12:05:48 -05:00
|
|
|
|
2018-03-05 18:39:56 -05:00
|
|
|
const propsData = {
|
2018-03-06 04:38:42 -05:00
|
|
|
hasMetrics: false,
|
2018-03-05 18:39:56 -05:00
|
|
|
documentationPath: '/path/to/docs',
|
|
|
|
settingsPath: '/path/to/settings',
|
|
|
|
clustersPath: '/path/to/clusters',
|
|
|
|
tagsPath: '/path/to/tags',
|
|
|
|
projectPath: '/path/to/project',
|
|
|
|
metricsEndpoint: mockApiEndpoint,
|
2018-03-06 12:05:48 -05:00
|
|
|
deploymentEndpoint: null,
|
2018-03-05 18:39:56 -05:00
|
|
|
emptyGettingStartedSvgPath: '/path/to/getting-started.svg',
|
|
|
|
emptyLoadingSvgPath: '/path/to/loading.svg',
|
2018-03-19 23:14:02 -04:00
|
|
|
emptyNoDataSvgPath: '/path/to/no-data.svg',
|
2018-03-05 18:39:56 -05:00
|
|
|
emptyUnableToConnectSvgPath: '/path/to/unable-to-connect.svg',
|
2018-06-29 15:07:34 -04:00
|
|
|
environmentsEndpoint: '/root/hello-prometheus/environments/35',
|
|
|
|
currentEnvironmentName: 'production',
|
2018-03-05 18:39:56 -05:00
|
|
|
};
|
|
|
|
|
2017-06-20 04:50:31 -04:00
|
|
|
beforeEach(() => {
|
2018-03-06 12:09:16 -05:00
|
|
|
setFixtures('<div class="prometheus-graphs"></div>');
|
2017-08-30 12:11:19 -04:00
|
|
|
DashboardComponent = Vue.extend(Dashboard);
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('no metrics are available yet', () => {
|
|
|
|
it('shows a getting started empty state when no metrics are present', () => {
|
2018-03-06 12:05:48 -05:00
|
|
|
const component = new DashboardComponent({
|
2018-03-06 12:09:16 -05:00
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
2018-03-05 18:39:56 -05:00
|
|
|
propsData,
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
2018-03-06 12:09:16 -05:00
|
|
|
expect(component.$el.querySelector('.prometheus-graphs')).toBe(null);
|
2017-06-20 04:50:31 -04:00
|
|
|
expect(component.state).toEqual('gettingStarted');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('requests information to the server', () => {
|
2017-11-22 11:33:53 -05:00
|
|
|
let mock;
|
2017-06-20 04:50:31 -04:00
|
|
|
beforeEach(() => {
|
2017-11-22 11:33:53 -05:00
|
|
|
mock = new MockAdapter(axios);
|
2018-03-06 12:05:48 -05:00
|
|
|
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-01-23 06:42:02 -05:00
|
|
|
mock.restore();
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
2018-06-29 15:07:34 -04:00
|
|
|
it('shows up a loading state', done => {
|
2018-03-06 12:05:48 -05:00
|
|
|
const component = new DashboardComponent({
|
2018-03-06 12:09:16 -05:00
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
2018-03-06 04:38:42 -05:00
|
|
|
propsData: { ...propsData, hasMetrics: true },
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
2018-03-06 12:05:48 -05:00
|
|
|
|
2017-06-20 04:50:31 -04:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.state).toEqual('loading');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-03-06 12:05:48 -05:00
|
|
|
|
2018-06-29 15:07:34 -04:00
|
|
|
it('hides the legend when showLegend is false', done => {
|
2018-03-06 12:05:48 -05:00
|
|
|
const component = new DashboardComponent({
|
2018-03-06 12:09:16 -05:00
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
2018-03-06 12:05:48 -05:00
|
|
|
propsData: { ...propsData, hasMetrics: true, showLegend: false },
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(component.showEmptyState).toEqual(false);
|
2018-03-06 12:23:09 -05:00
|
|
|
expect(component.$el.querySelector('.legend-group')).toEqual(null);
|
2018-03-06 12:05:48 -05:00
|
|
|
expect(component.$el.querySelector('.prometheus-graph-group')).toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-29 15:07:34 -04:00
|
|
|
it('hides the group panels when showPanels is false', done => {
|
2018-03-06 12:05:48 -05:00
|
|
|
const component = new DashboardComponent({
|
2018-03-06 12:09:16 -05:00
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
2018-03-06 12:05:48 -05:00
|
|
|
propsData: { ...propsData, hasMetrics: true, showPanels: false },
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(component.showEmptyState).toEqual(false);
|
2018-03-06 12:23:09 -05:00
|
|
|
expect(component.$el.querySelector('.prometheus-panel')).toEqual(null);
|
2018-03-06 12:05:48 -05:00
|
|
|
expect(component.$el.querySelector('.prometheus-graph-group')).toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-06-29 15:07:34 -04:00
|
|
|
|
|
|
|
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-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
});
|