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

684 lines
20 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
2019-10-12 21:52:04 +05:30
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlToast } from '@gitlab/ui';
2019-12-21 20:55:43 +05:30
import VueDraggable from 'vuedraggable';
2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
import Dashboard from '~/monitoring/components/dashboard.vue';
2019-09-04 21:01:54 +05:30
import * as types from '~/monitoring/stores/mutation_types';
import { createStore } from '~/monitoring/stores';
2018-03-17 18:26:18 +05:30
import axios from '~/lib/utils/axios_utils';
2019-10-12 21:52:04 +05:30
import MonitoringMock, {
2019-09-04 21:01:54 +05:30
metricsGroupsAPIResponse,
mockApiEndpoint,
environmentData,
singleGroupResponse,
2019-09-30 21:07:59 +05:30
dashboardGitResponse,
2019-12-04 20:38:33 +05:30
} from '../mock_data';
2017-09-10 17:25:29 +05:30
2019-10-12 21:52:04 +05:30
const localVue = createLocalVue();
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,
2019-09-04 21:01:54 +05:30
deploymentsEndpoint: null,
2018-12-05 23:21:45 +05:30
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',
2019-07-31 22:56:46 +05:30
customMetricsAvailable: false,
customMetricsPath: '',
validateQueryPath: '',
2018-12-05 23:21:45 +05:30
};
2019-12-21 20:55:43 +05:30
const resetSpy = spy => {
if (spy) {
spy.calls.reset();
}
};
2018-12-05 23:21:45 +05:30
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;
2019-09-04 21:01:54 +05:30
let store;
let component;
2019-10-12 21:52:04 +05:30
let mockGraphData;
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
2019-09-04 21:01:54 +05:30
store = createStore();
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(() => {
2019-10-12 21:52:04 +05:30
if (component) {
component.$destroy();
}
2019-03-02 22:35:43 +05:30
mock.restore();
});
2017-09-10 17:25:29 +05:30
describe('no metrics are available yet', () => {
2019-09-30 21:07:59 +05:30
beforeEach(() => {
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2018-03-27 19:54:05 +05:30
el: document.querySelector('.prometheus-graphs'),
2019-09-04 21:01:54 +05:30
propsData: { ...propsData },
store,
2017-09-10 17:25:29 +05:30
});
2019-09-30 21:07:59 +05:30
});
2017-09-10 17:25:29 +05:30
2019-09-30 21:07:59 +05:30
it('shows a getting started empty state when no metrics are present', () => {
2018-03-27 19:54:05 +05:30
expect(component.$el.querySelector('.prometheus-graphs')).toBe(null);
2019-09-04 21:01:54 +05:30
expect(component.emptyState).toEqual('gettingStarted');
2017-09-10 17:25:29 +05:30
});
2019-09-30 21:07:59 +05:30
it('shows the environment selector', () => {
expect(component.$el.querySelector('.js-environments-dropdown')).toBeTruthy();
});
});
describe('no data found', () => {
it('shows the environment selector dropdown', () => {
component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: { ...propsData, showEmptyState: true },
store,
});
expect(component.$el.querySelector('.js-environments-dropdown')).toBeTruthy();
});
2017-09-10 17:25:29 +05:30
});
describe('requests information to the server', () => {
2019-12-21 20:55:43 +05:30
let spy;
2017-09-10 17:25:29 +05:30
beforeEach(() => {
2018-03-27 19:54:05 +05:30
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
2017-09-10 17:25:29 +05:30
});
2019-12-21 20:55:43 +05:30
afterEach(() => {
resetSpy(spy);
});
2018-11-08 19:23:39 +05:30
it('shows up a loading state', done => {
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2018-03-27 19:54:05 +05:30
el: document.querySelector('.prometheus-graphs'),
2019-09-04 21:01:54 +05:30
propsData: { ...propsData, hasMetrics: true },
store,
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(() => {
2019-09-04 21:01:54 +05:30
expect(component.emptyState).toEqual('loading');
2017-09-10 17:25:29 +05:30
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 => {
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2018-03-27 19:54:05 +05:30
el: document.querySelector('.prometheus-graphs'),
2019-07-07 11:18:12 +05:30
propsData: {
...propsData,
hasMetrics: true,
showLegend: false,
},
2019-09-04 21:01:54 +05:30
store,
2018-03-27 19:54:05 +05:30
});
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 => {
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2018-03-27 19:54:05 +05:30
el: document.querySelector('.prometheus-graphs'),
2019-07-07 11:18:12 +05:30
propsData: {
...propsData,
hasMetrics: true,
showPanels: false,
},
2019-09-04 21:01:54 +05:30
store,
2018-03-27 19:54:05 +05:30
});
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
2019-07-07 11:18:12 +05:30
it('renders the environments dropdown with a number of environments', done => {
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2018-11-08 19:23:39 +05:30
el: document.querySelector('.prometheus-graphs'),
2019-07-07 11:18:12 +05:30
propsData: {
...propsData,
hasMetrics: true,
showPanels: false,
},
2019-09-04 21:01:54 +05:30
store,
2018-11-08 19:23:39 +05:30
});
2019-09-04 21:01:54 +05:30
component.$store.commit(
`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`,
environmentData,
);
component.$store.commit(
`monitoringDashboard/${types.RECEIVE_METRICS_DATA_SUCCESS}`,
singleGroupResponse,
);
2018-11-08 19:23:39 +05:30
2019-09-30 21:07:59 +05:30
Vue.nextTick()
.then(() => {
const dropdownMenuEnvironments = component.$el.querySelectorAll(
'.js-environments-dropdown .dropdown-item',
);
2018-12-13 13:39:08 +05:30
2019-09-30 21:07:59 +05:30
expect(component.environments.length).toEqual(environmentData.length);
expect(dropdownMenuEnvironments.length).toEqual(component.environments.length);
Array.from(dropdownMenuEnvironments).forEach((value, index) => {
if (environmentData[index].metrics_path) {
expect(value).toHaveAttr('href', environmentData[index].metrics_path);
}
});
done();
})
.catch(done.fail);
2018-11-08 19:23:39 +05:30
});
2019-07-07 11:18:12 +05:30
it('hides the environments dropdown list when there is no environments', done => {
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2018-12-13 13:39:08 +05:30
el: document.querySelector('.prometheus-graphs'),
2019-07-07 11:18:12 +05:30
propsData: {
...propsData,
hasMetrics: true,
showPanels: false,
},
2019-09-04 21:01:54 +05:30
store,
2018-12-13 13:39:08 +05:30
});
2019-09-04 21:01:54 +05:30
component.$store.commit(`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`, []);
component.$store.commit(
`monitoringDashboard/${types.RECEIVE_METRICS_DATA_SUCCESS}`,
singleGroupResponse,
);
2018-12-13 13:39:08 +05:30
2019-09-04 21:01:54 +05:30
Vue.nextTick()
.then(() => {
const dropdownMenuEnvironments = component.$el.querySelectorAll(
'.js-environments-dropdown .dropdown-item',
);
2018-12-13 13:39:08 +05:30
2019-09-04 21:01:54 +05:30
expect(dropdownMenuEnvironments.length).toEqual(0);
done();
})
.catch(done.fail);
2018-12-13 13:39:08 +05:30
});
2019-07-31 22:56:46 +05:30
it('renders the environments dropdown with a single active element', done => {
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2018-11-08 19:23:39 +05:30
el: document.querySelector('.prometheus-graphs'),
2019-07-07 11:18:12 +05:30
propsData: {
...propsData,
hasMetrics: true,
showPanels: false,
},
2019-09-04 21:01:54 +05:30
store,
2018-11-08 19:23:39 +05:30
});
2019-09-04 21:01:54 +05:30
component.$store.commit(
`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`,
environmentData,
);
component.$store.commit(
`monitoringDashboard/${types.RECEIVE_METRICS_DATA_SUCCESS}`,
singleGroupResponse,
);
2018-11-08 19:23:39 +05:30
2019-09-04 21:01:54 +05:30
Vue.nextTick()
.then(() => {
const dropdownItems = component.$el.querySelectorAll(
2019-09-30 21:07:59 +05:30
'.js-environments-dropdown .dropdown-item.active',
2019-09-04 21:01:54 +05:30
);
2018-12-13 13:39:08 +05:30
2019-09-04 21:01:54 +05:30
expect(dropdownItems.length).toEqual(1);
done();
})
.catch(done.fail);
2019-07-07 11:18:12 +05:30
});
it('hides the dropdown', done => {
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2019-07-07 11:18:12 +05:30
el: document.querySelector('.prometheus-graphs'),
propsData: {
...propsData,
hasMetrics: true,
showPanels: false,
environmentsEndpoint: '',
},
2019-09-04 21:01:54 +05:30
store,
2019-07-07 11:18:12 +05:30
});
Vue.nextTick(() => {
const dropdownIsActiveElement = component.$el.querySelectorAll('.environments');
expect(dropdownIsActiveElement.length).toEqual(0);
done();
});
});
2019-12-21 20:55:43 +05:30
it('renders the datetimepicker dropdown', done => {
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2019-07-07 11:18:12 +05:30
el: document.querySelector('.prometheus-graphs'),
propsData: {
...propsData,
hasMetrics: true,
showPanels: false,
},
2019-09-04 21:01:54 +05:30
store,
2019-07-07 11:18:12 +05:30
});
setTimeout(() => {
2019-12-21 20:55:43 +05:30
expect(component.$el.querySelector('.js-time-window-dropdown')).not.toBeNull();
2019-07-07 11:18:12 +05:30
done();
});
});
2019-09-04 21:01:54 +05:30
it('fetches the metrics data with proper time window', done => {
component = new DashboardComponent({
2019-07-07 11:18:12 +05:30
el: document.querySelector('.prometheus-graphs'),
propsData: {
...propsData,
hasMetrics: true,
showPanels: false,
},
2019-09-04 21:01:54 +05:30
store,
2019-07-07 11:18:12 +05:30
});
2019-09-04 21:01:54 +05:30
spyOn(component.$store, 'dispatch').and.stub();
2019-10-12 21:52:04 +05:30
const getTimeDiffSpy = spyOnDependency(Dashboard, 'getTimeDiff').and.callThrough();
2019-07-07 11:18:12 +05:30
2019-09-04 21:01:54 +05:30
component.$store.commit(
`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`,
environmentData,
);
2019-07-07 11:18:12 +05:30
2019-09-04 21:01:54 +05:30
component.$mount();
Vue.nextTick()
.then(() => {
expect(component.$store.dispatch).toHaveBeenCalled();
2019-10-12 21:52:04 +05:30
expect(getTimeDiffSpy).toHaveBeenCalled();
2019-09-04 21:01:54 +05:30
done();
})
.catch(done.fail);
2018-11-08 19:23:39 +05:30
});
2019-07-31 22:56:46 +05:30
it('shows a specific time window selected from the url params', done => {
2019-12-21 20:55:43 +05:30
const start = '2019-10-01T18:27:47.000Z';
const end = '2019-10-01T18:57:47.000Z';
2019-10-12 21:52:04 +05:30
spyOnDependency(Dashboard, 'getTimeDiff').and.returnValue({
start,
end,
});
spyOnDependency(Dashboard, 'getParameterValues').and.callFake(param => {
if (param === 'start') return [start];
if (param === 'end') return [end];
return [];
});
2019-07-31 22:56:46 +05:30
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2019-07-31 22:56:46 +05:30
el: document.querySelector('.prometheus-graphs'),
2019-09-04 21:01:54 +05:30
propsData: { ...propsData, hasMetrics: true },
store,
2019-07-31 22:56:46 +05:30
});
setTimeout(() => {
2019-09-04 21:01:54 +05:30
const selectedTimeWindow = component.$el.querySelector('.js-time-window-dropdown .active');
2019-07-31 22:56:46 +05:30
expect(selectedTimeWindow.textContent.trim()).toEqual('30 minutes');
done();
});
});
2019-12-21 20:55:43 +05:30
it('shows an error message if invalid url parameters are passed', done => {
2019-07-31 22:56:46 +05:30
spyOnDependency(Dashboard, 'getParameterValues').and.returnValue([
'<script>alert("XSS")</script>',
]);
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2019-07-31 22:56:46 +05:30
el: document.querySelector('.prometheus-graphs'),
2019-09-04 21:01:54 +05:30
propsData: { ...propsData, hasMetrics: true },
store,
2019-07-31 22:56:46 +05:30
});
2019-12-21 20:55:43 +05:30
spy = spyOn(component, 'showInvalidDateError');
component.$mount();
2019-07-31 22:56:46 +05:30
2019-12-21 20:55:43 +05:30
component.$nextTick(() => {
expect(component.showInvalidDateError).toHaveBeenCalled();
2019-07-31 22:56:46 +05:30
done();
});
});
2017-09-10 17:25:29 +05:30
});
2018-12-05 23:21:45 +05:30
2019-12-21 20:55:43 +05:30
describe('drag and drop function', () => {
let wrapper;
let expectedPanelCount; // also called metrics, naming to be improved: https://gitlab.com/gitlab-org/gitlab/issues/31565
const findDraggables = () => wrapper.findAll(VueDraggable);
const findEnabledDraggables = () => findDraggables().filter(f => !f.attributes('disabled'));
const findDraggablePanels = () => wrapper.findAll('.js-draggable-panel');
const findRearrangeButton = () => wrapper.find('.js-rearrange-button');
beforeEach(done => {
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
expectedPanelCount = metricsGroupsAPIResponse.data.reduce(
(acc, d) => d.metrics.length + acc,
0,
);
store.dispatch('monitoringDashboard/setFeatureFlags', { additionalPanelTypesEnabled: true });
wrapper = shallowMount(DashboardComponent, {
localVue,
sync: false,
propsData: { ...propsData, hasMetrics: true },
store,
});
// not using $nextTicket becuase we must wait for the dashboard
// to be populated with the mock data results.
setTimeout(done);
});
it('wraps vuedraggable', () => {
expect(findDraggablePanels().exists()).toBe(true);
expect(findDraggablePanels().length).toEqual(expectedPanelCount);
});
it('is disabled by default', () => {
expect(findRearrangeButton().exists()).toBe(false);
expect(findEnabledDraggables().length).toBe(0);
});
describe('when rearrange is enabled', () => {
beforeEach(done => {
wrapper.setProps({ rearrangePanelsAvailable: true });
wrapper.vm.$nextTick(done);
});
it('displays rearrange button', () => {
expect(findRearrangeButton().exists()).toBe(true);
});
describe('when rearrange button is clicked', () => {
const findFirstDraggableRemoveButton = () =>
findDraggablePanels()
.at(0)
.find('.js-draggable-remove');
beforeEach(done => {
findRearrangeButton().vm.$emit('click');
wrapper.vm.$nextTick(done);
});
it('it enables draggables', () => {
expect(findRearrangeButton().attributes('pressed')).toBeTruthy();
expect(findEnabledDraggables()).toEqual(findDraggables());
});
it('shows a remove button, which removes a panel', done => {
expect(findFirstDraggableRemoveButton().isEmpty()).toBe(false);
expect(findDraggablePanels().length).toEqual(expectedPanelCount);
findFirstDraggableRemoveButton().trigger('click');
wrapper.vm.$nextTick(() => {
// At present graphs will not be removed in backend
// See https://gitlab.com/gitlab-org/gitlab/issues/27835
expect(findDraggablePanels().length).toEqual(expectedPanelCount - 1);
done();
});
});
it('it disables draggables when clicked again', done => {
findRearrangeButton().vm.$emit('click');
wrapper.vm.$nextTick(() => {
expect(findRearrangeButton().attributes('pressed')).toBeFalsy();
expect(findEnabledDraggables().length).toBe(0);
done();
});
});
});
});
afterEach(() => {
wrapper.destroy();
});
});
// https://gitlab.com/gitlab-org/gitlab-ce/issues/66922
2019-12-04 20:38:33 +05:30
// eslint-disable-next-line jasmine/no-disabled-tests
xdescribe('link to chart', () => {
2019-10-12 21:52:04 +05:30
let wrapper;
const currentDashboard = 'TEST_DASHBOARD';
localVue.use(GlToast);
const link = () => wrapper.find('.js-chart-link');
const clipboardText = () => link().element.dataset.clipboardText;
beforeEach(done => {
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
wrapper = shallowMount(DashboardComponent, {
localVue,
sync: false,
attachToDocument: true,
propsData: { ...propsData, hasMetrics: true, currentDashboard },
store,
});
setTimeout(done);
});
afterEach(() => {
wrapper.destroy();
});
it('adds a copy button to the dropdown', () => {
expect(link().text()).toContain('Generate link to chart');
});
it('contains a link to the dashboard', () => {
expect(clipboardText()).toContain(`dashboard=${currentDashboard}`);
expect(clipboardText()).toContain(`group=`);
expect(clipboardText()).toContain(`title=`);
expect(clipboardText()).toContain(`y_label=`);
});
it('undefined parameter is stripped', done => {
wrapper.setProps({ currentDashboard: undefined });
wrapper.vm.$nextTick(() => {
expect(clipboardText()).not.toContain(`dashboard=`);
expect(clipboardText()).toContain(`y_label=`);
done();
});
});
it('null parameter is stripped', done => {
wrapper.setProps({ currentDashboard: null });
wrapper.vm.$nextTick(() => {
expect(clipboardText()).not.toContain(`dashboard=`);
expect(clipboardText()).toContain(`y_label=`);
done();
});
});
it('creates a toast when clicked', () => {
spyOn(wrapper.vm.$toast, 'show').and.stub();
link().vm.$emit('click');
expect(wrapper.vm.$toast.show).toHaveBeenCalled();
});
});
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 => {
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
2018-12-05 23:21:45 +05:30
el: document.querySelector('.prometheus-graphs'),
2019-07-07 11:18:12 +05:30
propsData: {
...propsData,
hasMetrics: true,
showPanels: false,
},
2019-09-04 21:01:54 +05:30
store,
2018-12-05 23:21:45 +05:30
});
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);
});
});
2019-07-31 22:56:46 +05:30
describe('external dashboard link', () => {
beforeEach(() => {
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
2019-09-04 21:01:54 +05:30
component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: {
...propsData,
hasMetrics: true,
showPanels: false,
showTimeWindowDropdown: false,
externalDashboardUrl: '/mockUrl',
},
store,
2019-07-31 22:56:46 +05:30
});
});
2019-09-04 21:01:54 +05:30
it('shows the link', done => {
setTimeout(() => {
expect(component.$el.querySelector('.js-external-dashboard-link').innerText).toContain(
'View full dashboard',
);
done();
2019-07-31 22:56:46 +05:30
});
});
});
2019-09-30 21:07:59 +05:30
describe('Dashboard dropdown', () => {
beforeEach(() => {
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
component = new DashboardComponent({
el: document.querySelector('.prometheus-graphs'),
propsData: {
...propsData,
hasMetrics: true,
showPanels: false,
},
store,
});
component.$store.dispatch('monitoringDashboard/setFeatureFlags', {
prometheusEndpoint: false,
});
component.$store.commit(
`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`,
environmentData,
);
component.$store.commit(
`monitoringDashboard/${types.RECEIVE_METRICS_DATA_SUCCESS}`,
singleGroupResponse,
);
component.$store.commit(
`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`,
dashboardGitResponse,
);
});
it('shows the dashboard dropdown', done => {
setTimeout(() => {
const dashboardDropdown = component.$el.querySelector('.js-dashboards-dropdown');
expect(dashboardDropdown).not.toEqual(null);
done();
});
});
});
2019-10-12 21:52:04 +05:30
describe('when downloading metrics data as CSV', () => {
beforeEach(() => {
component = new DashboardComponent({
propsData: {
...propsData,
},
store,
});
store.commit(
`monitoringDashboard/${types.RECEIVE_METRICS_DATA_SUCCESS}`,
MonitoringMock.data,
);
[mockGraphData] = component.$store.state.monitoringDashboard.groups[0].metrics;
});
describe('csvText', () => {
it('converts metrics data from json to csv', () => {
const header = `timestamp,${mockGraphData.y_label}`;
const data = mockGraphData.queries[0].result[0].values;
const firstRow = `${data[0][0]},${data[0][1]}`;
expect(component.csvText(mockGraphData)).toMatch(`^${header}\r\n${firstRow}`);
});
});
describe('downloadCsv', () => {
it('produces a link with a Blob', () => {
expect(component.downloadCsv(mockGraphData)).toContain(`blob:`);
});
});
});
2017-09-10 17:25:29 +05:30
});