Commit 2f5848ad authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'jestodus-monitor-ee-specs' into 'master'

Migrate ee specs for monitor from karma to jest

See merge request gitlab-org/gitlab!22926
parents f4393ced 78193665
...@@ -7,8 +7,8 @@ import { ...@@ -7,8 +7,8 @@ import {
mockApiEndpoint, mockApiEndpoint,
mockedQueryResultPayload, mockedQueryResultPayload,
environmentData, environmentData,
} from 'spec/monitoring/mock_data'; } from '../../../../../spec/frontend/monitoring/mock_data';
import propsData from 'spec/monitoring/components/dashboard_resize_spec'; import { propsData } from '../../../../../spec/frontend/monitoring/init_utils';
import CustomMetricsFormFields from 'ee/custom_metrics/components/custom_metrics_form_fields.vue'; import CustomMetricsFormFields from 'ee/custom_metrics/components/custom_metrics_form_fields.vue';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import { createStore } from '~/monitoring/stores'; import { createStore } from '~/monitoring/stores';
...@@ -27,10 +27,7 @@ describe('Dashboard', () => { ...@@ -27,10 +27,7 @@ describe('Dashboard', () => {
const createComponent = (props = {}) => { const createComponent = (props = {}) => {
wrapper = shallowMount(localVue.extend(Component), { wrapper = shallowMount(localVue.extend(Component), {
propsData: { propsData: { ...propsData, ...props },
...propsData,
...props,
},
stubs: { stubs: {
GlButton, GlButton,
}, },
...@@ -44,18 +41,12 @@ describe('Dashboard', () => { ...@@ -44,18 +41,12 @@ describe('Dashboard', () => {
<div class="prometheus-graphs"></div> <div class="prometheus-graphs"></div>
<div class="layout-page"></div> <div class="layout-page"></div>
`); `);
window.gon = { ...window.gon, ee: true };
window.gon = {
...window.gon,
ee: true,
};
store = createStore(); store = createStore();
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse); mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
Component = localVue.extend(Dashboard); Component = localVue.extend(Dashboard);
}); });
afterEach(() => { afterEach(() => {
mock.restore(); mock.restore();
}); });
...@@ -76,50 +67,26 @@ describe('Dashboard', () => { ...@@ -76,50 +67,26 @@ describe('Dashboard', () => {
} }
describe('add custom metrics', () => { describe('add custom metrics', () => {
const defaultProps = {
customMetricsPath: '/endpoint',
hasMetrics: true,
documentationPath: '/path/to/docs',
settingsPath: '/path/to/settings',
clustersPath: '/path/to/clusters',
projectPath: '/path/to/project',
metricsEndpoint: mockApiEndpoint,
tagsPath: '/path/to/tags',
emptyGettingStartedSvgPath: '/path/to/getting-started.svg',
emptyLoadingSvgPath: '/path/to/loading.svg',
emptyNoDataSvgPath: '/path/to/no-data.svg',
emptyNoDataSmallSvgPath: '/path/to/no-data-small.svg',
emptyUnableToConnectSvgPath: '/path/to/unable-to-connect.svg',
environmentsEndpoint: '/root/hello-prometheus/environments/35',
currentEnvironmentName: 'production',
prometheusAlertsAvailable: true,
alertsEndpoint: '/endpoint',
};
describe('when not available', () => { describe('when not available', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
customMetricsAvailable: false, hasMetrics: true,
...defaultProps, customMetricsPath: '/endpoint',
}); });
}); });
it('does not render add button on the dashboard', () => { it('does not render add button on the dashboard', () => {
expect(findAddMetricButton()).toBeUndefined(); expect(findAddMetricButton()).toBeUndefined();
}); });
}); });
describe('when available', () => { describe('when available', () => {
let origPage; let origPage;
beforeEach(done => { beforeEach(done => {
spyOn(Tracking, 'event'); jest.spyOn(Tracking, 'event').mockReturnValue();
createComponent({ createComponent({
hasMetrics: true,
customMetricsPath: '/endpoint',
customMetricsAvailable: true, customMetricsAvailable: true,
...defaultProps,
}); });
setupComponentStore(wrapper); setupComponentStore(wrapper);
origPage = document.body.dataset.page; origPage = document.body.dataset.page;
...@@ -127,7 +94,6 @@ describe('Dashboard', () => { ...@@ -127,7 +94,6 @@ describe('Dashboard', () => {
wrapper.vm.$nextTick(done); wrapper.vm.$nextTick(done);
}); });
afterEach(() => { afterEach(() => {
document.body.dataset.page = origPage; document.body.dataset.page = origPage;
}); });
...@@ -140,10 +106,11 @@ describe('Dashboard', () => { ...@@ -140,10 +106,11 @@ describe('Dashboard', () => {
expect(wrapper.find(GlModal).exists()).toBe(true); expect(wrapper.find(GlModal).exists()).toBe(true);
expect(wrapper.find(GlModal).attributes().modalid).toBe('add-metric'); expect(wrapper.find(GlModal).attributes().modalid).toBe('add-metric');
}); });
it('adding new metric is tracked', done => { it('adding new metric is tracked', done => {
const submitButton = wrapper.vm.$refs.submitCustomMetricsFormBtn; const submitButton = wrapper.vm.$refs.submitCustomMetricsFormBtn;
wrapper.setData({ formIsValid: true }); wrapper.setData({
formIsValid: true,
});
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
submitButton.$el.click(); submitButton.$el.click();
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
...@@ -160,7 +127,6 @@ describe('Dashboard', () => { ...@@ -160,7 +127,6 @@ describe('Dashboard', () => {
}); });
}); });
}); });
it('renders custom metrics form fields', () => { it('renders custom metrics form fields', () => {
expect(wrapper.find(CustomMetricsFormFields).exists()).toBe(true); expect(wrapper.find(CustomMetricsFormFields).exists()).toBe(true);
}); });
......
...@@ -7,75 +7,74 @@ describe('alertsValidator', () => { ...@@ -7,75 +7,74 @@ describe('alertsValidator', () => {
threshold: 5, threshold: 5,
metricId: '8', metricId: '8',
}; };
it('requires all alerts to have an alert path', () => { it('requires all alerts to have an alert path', () => {
const { operator, threshold, metricId } = validAlert; const { operator, threshold, metricId } = validAlert;
const input = { [validAlert.alert_path]: { operator, threshold, metricId } }; const input = {
[validAlert.alert_path]: {
operator,
threshold,
metricId,
},
};
expect(alertsValidator(input)).toEqual(false); expect(alertsValidator(input)).toEqual(false);
}); });
it('requires that the object key matches the alert path', () => { it('requires that the object key matches the alert path', () => {
const input = { undefined: validAlert }; const input = {
undefined: validAlert,
};
expect(alertsValidator(input)).toEqual(false); expect(alertsValidator(input)).toEqual(false);
}); });
it('requires all alerts to have a metric id', () => { it('requires all alerts to have a metric id', () => {
const input = { [validAlert.alert_path]: { ...validAlert, metricId: undefined } }; const input = {
[validAlert.alert_path]: { ...validAlert, metricId: undefined },
};
expect(alertsValidator(input)).toEqual(false); expect(alertsValidator(input)).toEqual(false);
}); });
it('requires the metricId to be a string', () => { it('requires the metricId to be a string', () => {
const input = { [validAlert.alert_path]: { ...validAlert, metricId: 8 } }; const input = {
[validAlert.alert_path]: { ...validAlert, metricId: 8 },
};
expect(alertsValidator(input)).toEqual(false); expect(alertsValidator(input)).toEqual(false);
}); });
it('requires all alerts to have an operator', () => { it('requires all alerts to have an operator', () => {
const input = { [validAlert.alert_path]: { ...validAlert, operator: '' } }; const input = {
[validAlert.alert_path]: { ...validAlert, operator: '' },
};
expect(alertsValidator(input)).toEqual(false); expect(alertsValidator(input)).toEqual(false);
}); });
it('requires all alerts to have an numeric threshold', () => { it('requires all alerts to have an numeric threshold', () => {
const input = { [validAlert.alert_path]: { ...validAlert, threshold: '60' } }; const input = {
[validAlert.alert_path]: { ...validAlert, threshold: '60' },
};
expect(alertsValidator(input)).toEqual(false); expect(alertsValidator(input)).toEqual(false);
}); });
it('correctly identifies a valid alerts object', () => { it('correctly identifies a valid alerts object', () => {
const input = { [validAlert.alert_path]: validAlert }; const input = {
[validAlert.alert_path]: validAlert,
};
expect(alertsValidator(input)).toEqual(true); expect(alertsValidator(input)).toEqual(true);
}); });
}); });
describe('queriesValidator', () => { describe('queriesValidator', () => {
const validQuery = { metricId: '8', alert_path: 'alert', label: 'alert-label' }; const validQuery = {
metricId: '8',
alert_path: 'alert',
label: 'alert-label',
};
it('requires all alerts to have a metric id', () => { it('requires all alerts to have a metric id', () => {
const input = [{ ...validQuery, metricId: undefined }]; const input = [{ ...validQuery, metricId: undefined }];
expect(queriesValidator(input)).toEqual(false); expect(queriesValidator(input)).toEqual(false);
}); });
it('requires the metricId to be a string', () => { it('requires the metricId to be a string', () => {
const input = [{ ...validQuery, metricId: 8 }]; const input = [{ ...validQuery, metricId: 8 }];
expect(queriesValidator(input)).toEqual(false); expect(queriesValidator(input)).toEqual(false);
}); });
it('requires all queries to have a label', () => { it('requires all queries to have a label', () => {
const input = [{ ...validQuery, label: undefined }]; const input = [{ ...validQuery, label: undefined }];
expect(queriesValidator(input)).toEqual(false); expect(queriesValidator(input)).toEqual(false);
}); });
it('correctly identifies a valid queries array', () => { it('correctly identifies a valid queries array', () => {
const input = [validQuery]; const input = [validQuery];
expect(queriesValidator(input)).toEqual(true); expect(queriesValidator(input)).toEqual(true);
}); });
}); });
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