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

56 lines
1.6 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';
import { metricsGroupsAPIResponse, mockApiEndpoint } from './mock_data';
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
describe('Dashboard', () => {
2017-09-10 17:25:29 +05:30
const fixtureName = 'environments/metrics/metrics.html.raw';
2018-03-17 18:26:18 +05:30
let DashboardComponent;
2017-09-10 17:25:29 +05:30
let component;
preloadFixtures(fixtureName);
beforeEach(() => {
loadFixtures(fixtureName);
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-17 18:26:18 +05:30
component = new DashboardComponent({
2017-09-10 17:25:29 +05:30
el: document.querySelector('#prometheus-graphs'),
});
component.$mount();
expect(component.$el.querySelector('#prometheus-graphs')).toBe(null);
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(() => {
document.querySelector('#prometheus-graphs').setAttribute('data-has-metrics', 'true');
2018-03-17 18:26:18 +05:30
mock = new MockAdapter(axios);
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
});
it('shows up a loading state', (done) => {
2018-03-17 18:26:18 +05:30
component = new DashboardComponent({
2017-09-10 17:25:29 +05:30
el: document.querySelector('#prometheus-graphs'),
});
component.$mount();
Vue.nextTick(() => {
expect(component.state).toEqual('loading');
done();
});
});
});
});