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';
|
2019-03-12 14:55:43 -04:00
|
|
|
import { timeWindows } from '~/monitoring/constants';
|
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
|
|
|
|
2018-10-05 12:26:16 -04:00
|
|
|
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;
|
|
|
|
|
2017-08-30 12:11:19 -04:00
|
|
|
describe('Dashboard', () => {
|
|
|
|
let DashboardComponent;
|
2019-02-03 18:50:04 -05:00
|
|
|
let mock;
|
2018-03-06 12:05:48 -05:00
|
|
|
|
2017-06-20 04:50:31 -04:00
|
|
|
beforeEach(() => {
|
2018-09-13 15:33:31 -04:00
|
|
|
setFixtures(`
|
|
|
|
<div class="prometheus-graphs"></div>
|
2019-01-23 18:06:40 -05:00
|
|
|
<div class="layout-page"></div>
|
2018-09-13 15:33:31 -04:00
|
|
|
`);
|
2019-02-03 18:50:04 -05:00
|
|
|
|
2019-03-25 23:41:17 -04:00
|
|
|
window.gon = {
|
|
|
|
...window.gon,
|
|
|
|
ee: false,
|
|
|
|
};
|
|
|
|
|
2019-02-03 18:50:04 -05:00
|
|
|
mock = new MockAdapter(axios);
|
2017-08-30 12:11:19 -04:00
|
|
|
DashboardComponent = Vue.extend(Dashboard);
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
2019-02-03 18:50:04 -05:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
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'),
|
2019-04-02 16:02:29 -04:00
|
|
|
propsData: { ...propsData, showTimeWindowDropdown: false },
|
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', () => {
|
|
|
|
beforeEach(() => {
|
2018-03-06 12:05:48 -05:00
|
|
|
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
|
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'),
|
2019-04-02 16:02:29 -04:00
|
|
|
propsData: { ...propsData, hasMetrics: true, showTimeWindowDropdown: false },
|
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'),
|
2019-04-02 16:02:29 -04:00
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
hasMetrics: true,
|
|
|
|
showLegend: false,
|
|
|
|
showTimeWindowDropdown: false,
|
|
|
|
},
|
2018-03-06 12:05:48 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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'),
|
2019-04-02 16:02:29 -04:00
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
hasMetrics: true,
|
|
|
|
showPanels: false,
|
|
|
|
showTimeWindowDropdown: false,
|
|
|
|
},
|
2018-03-06 12:05:48 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-03-20 18:36:07 -04:00
|
|
|
it('renders the environments dropdown with a number of environments', done => {
|
2018-06-29 15:07:34 -04:00
|
|
|
const component = new DashboardComponent({
|
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
2019-04-02 16:02:29 -04:00
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
hasMetrics: true,
|
|
|
|
showPanels: false,
|
|
|
|
showTimeWindowDropdown: false,
|
|
|
|
},
|
2018-06-29 15:07:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
component.store.storeEnvironmentsData(environmentData);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2019-03-20 18:36:07 -04:00
|
|
|
const dropdownMenuEnvironments = component.$el.querySelectorAll(
|
|
|
|
'.js-environments-dropdown .dropdown-item',
|
|
|
|
);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-06-29 15:07:34 -04:00
|
|
|
expect(dropdownMenuEnvironments.length).toEqual(component.store.environmentsData.length);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-20 18:36:07 -04:00
|
|
|
it('hides the environments dropdown list when there is no environments', done => {
|
2018-10-26 11:31:04 -04:00
|
|
|
const component = new DashboardComponent({
|
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
2019-04-02 16:02:29 -04:00
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
hasMetrics: true,
|
|
|
|
showPanels: false,
|
|
|
|
showTimeWindowDropdown: false,
|
|
|
|
},
|
2018-10-26 11:31:04 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
component.store.storeEnvironmentsData([]);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2019-03-20 18:36:07 -04:00
|
|
|
const dropdownMenuEnvironments = component.$el.querySelectorAll(
|
2019-03-28 17:29:36 -04:00
|
|
|
'.js-environments-dropdown .dropdown-item',
|
2019-03-20 18:36:07 -04:00
|
|
|
);
|
2018-10-26 11:31:04 -04:00
|
|
|
|
|
|
|
expect(dropdownMenuEnvironments.length).toEqual(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-20 18:36:07 -04:00
|
|
|
it('renders the environments dropdown with a single is-active element', done => {
|
2018-06-29 15:07:34 -04:00
|
|
|
const component = new DashboardComponent({
|
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
2019-04-02 16:02:29 -04:00
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
hasMetrics: true,
|
|
|
|
showPanels: false,
|
|
|
|
showTimeWindowDropdown: false,
|
|
|
|
},
|
2018-06-29 15:07:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
component.store.storeEnvironmentsData(environmentData);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2019-03-20 18:36:07 -04:00
|
|
|
const dropdownItems = component.$el.querySelectorAll(
|
2019-04-23 09:35:39 -04:00
|
|
|
'.js-environments-dropdown .dropdown-item.is-active',
|
2018-06-29 15:07:34 -04:00
|
|
|
);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-03-20 18:36:07 -04:00
|
|
|
expect(dropdownItems.length).toEqual(1);
|
|
|
|
expect(dropdownItems[0].textContent.trim()).toEqual(component.currentEnvironmentName);
|
2019-03-25 23:41:17 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('hides the dropdown', done => {
|
|
|
|
const component = new DashboardComponent({
|
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
hasMetrics: true,
|
|
|
|
showPanels: false,
|
|
|
|
environmentsEndpoint: '',
|
2019-04-02 16:02:29 -04:00
|
|
|
showTimeWindowDropdown: false,
|
2019-03-25 23:41:17 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const dropdownIsActiveElement = component.$el.querySelectorAll('.environments');
|
|
|
|
|
|
|
|
expect(dropdownIsActiveElement.length).toEqual(0);
|
2018-06-29 15:07:34 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-03-12 14:55:43 -04:00
|
|
|
|
2019-04-02 16:02:29 -04:00
|
|
|
it('does not show the time window dropdown when the feature flag is not set', done => {
|
2019-04-01 14:38:26 -04:00
|
|
|
const component = new DashboardComponent({
|
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
2019-04-02 16:02:29 -04:00
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
hasMetrics: true,
|
|
|
|
showPanels: false,
|
|
|
|
showTimeWindowDropdown: false,
|
|
|
|
},
|
2019-04-01 14:38:26 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
const timeWindowDropdown = component.$el.querySelector('.js-time-window-dropdown');
|
|
|
|
|
|
|
|
expect(timeWindowDropdown).toBeNull();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-03 18:10:39 -04:00
|
|
|
it('renders the time window dropdown with a set of options', done => {
|
2019-03-12 14:55:43 -04:00
|
|
|
const component = new DashboardComponent({
|
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
2019-04-02 16:02:29 -04:00
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
hasMetrics: true,
|
|
|
|
showPanels: false,
|
|
|
|
showTimeWindowDropdown: true,
|
|
|
|
},
|
2019-03-12 14:55:43 -04:00
|
|
|
});
|
|
|
|
const numberOfTimeWindows = Object.keys(timeWindows).length;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2019-03-20 15:52:24 -04:00
|
|
|
const timeWindowDropdown = component.$el.querySelector('.js-time-window-dropdown');
|
2019-03-12 14:55:43 -04:00
|
|
|
const timeWindowDropdownEls = component.$el.querySelectorAll(
|
2019-03-20 15:52:24 -04:00
|
|
|
'.js-time-window-dropdown .dropdown-item',
|
2019-03-12 14:55:43 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(timeWindowDropdown).not.toBeNull();
|
|
|
|
expect(timeWindowDropdownEls.length).toEqual(numberOfTimeWindows);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
2018-09-13 15:33:31 -04:00
|
|
|
|
|
|
|
describe('when the window resizes', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
|
|
|
|
jasmine.clock().install();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jasmine.clock().uninstall();
|
|
|
|
});
|
|
|
|
|
2019-01-23 18:06:40 -05:00
|
|
|
it('sets elWidth to page width when the sidebar is resized', done => {
|
2018-09-13 15:33:31 -04:00
|
|
|
const component = new DashboardComponent({
|
|
|
|
el: document.querySelector('.prometheus-graphs'),
|
2019-04-02 16:02:29 -04:00
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
hasMetrics: true,
|
|
|
|
showPanels: false,
|
|
|
|
showTimeWindowDropdown: false,
|
|
|
|
},
|
2018-09-13 15:33:31 -04:00
|
|
|
});
|
|
|
|
|
2019-01-23 18:06:40 -05:00
|
|
|
expect(component.elWidth).toEqual(0);
|
2018-09-13 15:33:31 -04:00
|
|
|
|
2019-01-23 18:06:40 -05:00
|
|
|
const pageLayoutEl = document.querySelector('.layout-page');
|
|
|
|
pageLayoutEl.classList.add('page-with-icon-sidebar');
|
2018-09-13 15:33:31 -04:00
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
jasmine.clock().tick(1000);
|
|
|
|
return Vue.nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
2019-01-23 18:06:40 -05:00
|
|
|
expect(component.elWidth).toEqual(pageLayoutEl.clientWidth);
|
2018-09-13 15:33:31 -04:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|