Commit 866a0673 authored by Himanshu Kapoor's avatar Himanshu Kapoor

Migrate prometheus_metrics specs to Jest

Migrate spec/javascripts/prometheus_metrics specs from Karma to Jest.
parent dfaf03f3
......@@ -2,7 +2,7 @@ import MockAdapter from 'axios-mock-adapter';
import CustomMetrics from '~/prometheus_metrics/custom_metrics';
import axios from '~/lib/utils/axios_utils';
import PANEL_STATE from '~/prometheus_metrics/constants';
import metrics from './mock_data';
import { metrics1 as metrics } from './mock_data';
describe('PrometheusMetrics', () => {
const FIXTURE = 'services/prometheus/prometheus_service.html';
......
const metrics = [
export const metrics1 = [
{
edit_path: '/root/prometheus-test/prometheus/metrics/3/edit',
id: 3,
......@@ -19,4 +19,44 @@ const metrics = [
},
];
export default metrics;
export const metrics2 = [
{
group: 'Kubernetes',
priority: 1,
active_metrics: 4,
metrics_missing_requirements: 0,
},
{
group: 'HAProxy',
priority: 2,
active_metrics: 3,
metrics_missing_requirements: 0,
},
{
group: 'Apache',
priority: 3,
active_metrics: 5,
metrics_missing_requirements: 0,
},
];
export const missingVarMetrics = [
{
group: 'Kubernetes',
priority: 1,
active_metrics: 4,
metrics_missing_requirements: 0,
},
{
group: 'HAProxy',
priority: 2,
active_metrics: 3,
metrics_missing_requirements: 1,
},
{
group: 'Apache',
priority: 3,
active_metrics: 5,
metrics_missing_requirements: 3,
},
];
......@@ -2,7 +2,7 @@ import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import PrometheusMetrics from '~/prometheus_metrics/prometheus_metrics';
import PANEL_STATE from '~/prometheus_metrics/constants';
import { metrics, missingVarMetrics } from './mock_data';
import { metrics2 as metrics, missingVarMetrics } from './mock_data';
describe('PrometheusMetrics', () => {
const FIXTURE = 'services/prometheus/prometheus_service.html';
......@@ -126,7 +126,7 @@ describe('PrometheusMetrics', () => {
}
beforeEach(() => {
spyOn(axios, 'get').and.callThrough();
jest.spyOn(axios, 'get');
prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring');
......@@ -145,7 +145,7 @@ describe('PrometheusMetrics', () => {
expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeFalsy();
expect(axios.get).toHaveBeenCalledWith(prometheusMetrics.activeMetricsEndpoint);
setTimeout(() => {
setImmediate(() => {
expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeTruthy();
done();
});
......@@ -156,7 +156,7 @@ describe('PrometheusMetrics', () => {
prometheusMetrics.loadActiveMetrics();
setTimeout(() => {
setImmediate(() => {
expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeTruthy();
expect(prometheusMetrics.$monitoredMetricsEmpty.hasClass('hidden')).toBeFalsy();
done();
......@@ -164,12 +164,12 @@ describe('PrometheusMetrics', () => {
});
it('should populate metrics list once response is loaded', done => {
spyOn(prometheusMetrics, 'populateActiveMetrics');
jest.spyOn(prometheusMetrics, 'populateActiveMetrics').mockImplementation();
mockSuccess();
prometheusMetrics.loadActiveMetrics();
setTimeout(() => {
setImmediate(() => {
expect(prometheusMetrics.populateActiveMetrics).toHaveBeenCalledWith(metrics);
done();
});
......
export const metrics = [
{
group: 'Kubernetes',
priority: 1,
active_metrics: 4,
metrics_missing_requirements: 0,
},
{
group: 'HAProxy',
priority: 2,
active_metrics: 3,
metrics_missing_requirements: 0,
},
{
group: 'Apache',
priority: 3,
active_metrics: 5,
metrics_missing_requirements: 0,
},
];
export const missingVarMetrics = [
{
group: 'Kubernetes',
priority: 1,
active_metrics: 4,
metrics_missing_requirements: 0,
},
{
group: 'HAProxy',
priority: 2,
active_metrics: 3,
metrics_missing_requirements: 1,
},
{
group: 'Apache',
priority: 3,
active_metrics: 5,
metrics_missing_requirements: 3,
},
];
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment