2020-04-10 11:09:50 -04:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2020-04-13 05:09:51 -04:00
|
|
|
import CustomMetrics from '~/prometheus_metrics/custom_metrics';
|
2020-04-10 11:09:50 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import PANEL_STATE from '~/prometheus_metrics/constants';
|
2020-05-19 20:08:20 -04:00
|
|
|
import { metrics1 as metrics } from './mock_data';
|
2020-04-10 11:09:50 -04:00
|
|
|
|
|
|
|
describe('PrometheusMetrics', () => {
|
|
|
|
const FIXTURE = 'services/prometheus/prometheus_service.html';
|
|
|
|
const customMetricsEndpoint =
|
|
|
|
'http://test.host/frontend-fixtures/services-project/prometheus/metrics';
|
|
|
|
let mock;
|
|
|
|
preloadFixtures(FIXTURE);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onGet(customMetricsEndpoint).reply(200, {
|
|
|
|
metrics,
|
|
|
|
});
|
|
|
|
loadFixtures(FIXTURE);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Custom Metrics', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
let customMetrics;
|
2020-04-10 11:09:50 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics = new CustomMetrics('.js-prometheus-metrics-monitoring');
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should initialize wrapper element refs on the class object', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$wrapperCustomMetrics).not.toBeNull();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsPanel).not.toBeNull();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsCount).not.toBeNull();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading).not.toBeNull();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty).not.toBeNull();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsList).not.toBeNull();
|
|
|
|
expect(customMetrics.$newCustomMetricButton).not.toBeNull();
|
|
|
|
expect(customMetrics.$flashCustomMetricsContainer).not.toBeNull();
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should contain api endpoints', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.activeCustomMetricsEndpoint).toEqual(customMetricsEndpoint);
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show loading state when called with `loading`', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.LOADING);
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toEqual(false);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toBeTruthy();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBeTruthy();
|
2020-04-10 11:09:50 -04:00
|
|
|
expect(
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
|
2020-04-10 11:09:50 -04:00
|
|
|
).toBeTruthy();
|
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toBeTruthy();
|
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show metrics list when called with `list`', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.LIST);
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toBeTruthy();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toEqual(false);
|
2020-04-10 11:09:50 -04:00
|
|
|
expect(
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
|
2020-04-10 11:09:50 -04:00
|
|
|
).toBeTruthy();
|
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
|
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show empty state when called with `empty`', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.EMPTY);
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toEqual(false);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBeTruthy();
|
2020-04-10 11:09:50 -04:00
|
|
|
expect(
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
|
2020-04-10 11:09:50 -04:00
|
|
|
).toBeTruthy();
|
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
|
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toEqual(false);
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show monitored metrics list', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.customMetrics = metrics;
|
|
|
|
customMetrics.populateCustomMetrics();
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
const $metricsListLi = customMetrics.$monitoredCustomMetricsList.find('li');
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toEqual(false);
|
2020-04-10 11:09:50 -04:00
|
|
|
expect(
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
|
2020-04-10 11:09:50 -04:00
|
|
|
).toBeTruthy();
|
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
|
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
|
2020-04-10 11:09:50 -04:00
|
|
|
|
|
|
|
expect($metricsListLi.length).toEqual(metrics.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show the NO-INTEGRATION empty state', () => {
|
2020-04-13 05:09:51 -04:00
|
|
|
customMetrics.setNoIntegrationActiveState();
|
2020-04-10 11:09:50 -04:00
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toEqual(false);
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toEqual(
|
2020-04-10 11:09:50 -04:00
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
2020-04-13 05:09:51 -04:00
|
|
|
expect(customMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
|
|
|
|
expect(customMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBeTruthy();
|
|
|
|
expect(customMetrics.$newCustomMetricButton.hasClass('hidden')).toBeTruthy();
|
|
|
|
expect(customMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
|
2020-04-10 11:09:50 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|