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';
|
|
|
|
import { metricsGroupsAPIResponse, mockApiEndpoint } from './mock_data';
|
2017-06-20 04:50:31 -04:00
|
|
|
|
2017-08-30 12:11:19 -04:00
|
|
|
describe('Dashboard', () => {
|
2017-06-20 04:50:31 -04:00
|
|
|
const fixtureName = 'environments/metrics/metrics.html.raw';
|
2017-08-30 12:11:19 -04:00
|
|
|
let DashboardComponent;
|
2017-06-20 04:50:31 -04:00
|
|
|
let component;
|
|
|
|
preloadFixtures(fixtureName);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures(fixtureName);
|
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', () => {
|
2017-08-30 12:11:19 -04:00
|
|
|
component = new DashboardComponent({
|
2017-06-20 04:50:31 -04:00
|
|
|
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', () => {
|
2017-11-22 11:33:53 -05:00
|
|
|
let mock;
|
2017-06-20 04:50:31 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
document.querySelector('#prometheus-graphs').setAttribute('data-has-metrics', 'true');
|
2017-11-22 11:33:53 -05:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onGet(mockApiEndpoint).reply(200, {
|
|
|
|
metricsGroupsAPIResponse,
|
|
|
|
});
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2017-11-22 11:33:53 -05:00
|
|
|
mock.reset();
|
2017-06-20 04:50:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows up a loading state', (done) => {
|
2017-08-30 12:11:19 -04:00
|
|
|
component = new DashboardComponent({
|
2017-06-20 04:50:31 -04:00
|
|
|
el: document.querySelector('#prometheus-graphs'),
|
|
|
|
});
|
|
|
|
component.$mount();
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.state).toEqual('loading');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|