2019-11-04 07:06:19 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2019-11-18 07:06:03 -05:00
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
2019-12-09 07:07:58 -05:00
|
|
|
import Tracking from '~/tracking';
|
2019-11-18 07:06:03 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-11-04 07:06:19 -05:00
|
|
|
import statusCodes from '~/lib/utils/http_status';
|
2020-02-26 19:09:19 -05:00
|
|
|
import * as commonUtils from '~/lib/utils/common_utils';
|
2019-11-26 16:06:38 -05:00
|
|
|
import createFlash from '~/flash';
|
2020-04-07 14:09:19 -04:00
|
|
|
import { defaultTimeRange } from '~/vue_shared/constants';
|
2020-04-08 17:09:50 -04:00
|
|
|
import { ENVIRONMENT_AVAILABLE_STATE } from '~/monitoring/constants';
|
2019-11-04 07:06:19 -05:00
|
|
|
|
2020-05-22 14:08:21 -04:00
|
|
|
import { createStore } from '~/monitoring/stores';
|
2019-11-18 07:06:03 -05:00
|
|
|
import * as types from '~/monitoring/stores/mutation_types';
|
|
|
|
import {
|
2020-05-07 11:09:29 -04:00
|
|
|
fetchData,
|
2019-11-18 07:06:03 -05:00
|
|
|
fetchDashboard,
|
|
|
|
receiveMetricsDashboardSuccess,
|
|
|
|
fetchDeploymentsData,
|
|
|
|
fetchEnvironmentsData,
|
2020-04-14 08:09:26 -04:00
|
|
|
fetchDashboardData,
|
2020-04-14 11:09:44 -04:00
|
|
|
fetchAnnotations,
|
2020-05-12 11:10:33 -04:00
|
|
|
toggleStarredValue,
|
2019-11-18 07:06:03 -05:00
|
|
|
fetchPrometheusMetric,
|
2020-04-01 17:07:56 -04:00
|
|
|
setInitialState,
|
2020-01-29 04:08:49 -05:00
|
|
|
filterEnvironments,
|
2020-04-29 11:09:58 -04:00
|
|
|
setExpandedPanel,
|
|
|
|
clearExpandedPanel,
|
2019-11-18 07:06:03 -05:00
|
|
|
setGettingStartedEmptyState,
|
2020-01-16 13:08:46 -05:00
|
|
|
duplicateSystemDashboard,
|
2020-05-15 20:08:12 -04:00
|
|
|
updateVariableValues,
|
2019-11-18 07:06:03 -05:00
|
|
|
} from '~/monitoring/stores/actions';
|
2020-04-21 11:21:10 -04:00
|
|
|
import {
|
|
|
|
gqClient,
|
|
|
|
parseEnvironmentsResponse,
|
|
|
|
parseAnnotationsResponse,
|
|
|
|
} from '~/monitoring/stores/utils';
|
2020-01-29 04:08:49 -05:00
|
|
|
import getEnvironments from '~/monitoring/queries/getEnvironments.query.graphql';
|
2020-04-14 11:09:44 -04:00
|
|
|
import getAnnotations from '~/monitoring/queries/getAnnotations.query.graphql';
|
2019-11-18 07:06:03 -05:00
|
|
|
import storeState from '~/monitoring/stores/state';
|
|
|
|
import {
|
|
|
|
deploymentData,
|
|
|
|
environmentData,
|
2020-04-14 11:09:44 -04:00
|
|
|
annotationsData,
|
2020-05-15 20:08:12 -04:00
|
|
|
mockTemplatingData,
|
2019-11-18 07:06:03 -05:00
|
|
|
dashboardGitResponse,
|
2020-03-04 04:08:20 -05:00
|
|
|
mockDashboardsErrorResponse,
|
2019-11-18 07:06:03 -05:00
|
|
|
} from '../mock_data';
|
2020-04-16 02:09:39 -04:00
|
|
|
import {
|
|
|
|
metricsDashboardResponse,
|
|
|
|
metricsDashboardViewModel,
|
|
|
|
metricsDashboardPanelCount,
|
|
|
|
} from '../fixture_data';
|
2019-11-18 07:06:03 -05:00
|
|
|
|
2019-11-26 16:06:38 -05:00
|
|
|
jest.mock('~/flash');
|
2019-11-04 07:06:19 -05:00
|
|
|
|
2019-11-26 16:06:38 -05:00
|
|
|
describe('Monitoring store actions', () => {
|
2020-02-26 19:09:19 -05:00
|
|
|
const { convertObjectPropsToCamelCase } = commonUtils;
|
|
|
|
|
2019-11-04 07:06:19 -05:00
|
|
|
let mock;
|
2020-05-22 14:08:21 -04:00
|
|
|
let store;
|
|
|
|
let state;
|
2020-02-26 19:09:19 -05:00
|
|
|
|
2019-11-04 07:06:19 -05:00
|
|
|
beforeEach(() => {
|
2020-05-22 14:08:21 -04:00
|
|
|
store = createStore();
|
|
|
|
state = store.state.monitoringDashboard;
|
2019-11-04 07:06:19 -05:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
2020-02-26 19:09:19 -05:00
|
|
|
jest.spyOn(commonUtils, 'backOff').mockImplementation(callback => {
|
2019-11-26 16:06:38 -05:00
|
|
|
const q = new Promise((resolve, reject) => {
|
|
|
|
const stop = arg => (arg instanceof Error ? reject(arg) : resolve(arg));
|
|
|
|
const next = () => callback(next, stop);
|
|
|
|
// Define a timeout based on a mock timer
|
|
|
|
setTimeout(() => {
|
|
|
|
callback(next, stop);
|
2019-11-04 07:06:19 -05:00
|
|
|
});
|
2019-11-26 16:06:38 -05:00
|
|
|
});
|
|
|
|
// Run all resolved promises in chain
|
|
|
|
jest.runOnlyPendingTimers();
|
|
|
|
return q;
|
2019-11-04 07:06:19 -05:00
|
|
|
});
|
|
|
|
});
|
2019-11-18 07:06:03 -05:00
|
|
|
afterEach(() => {
|
2019-11-26 16:06:38 -05:00
|
|
|
mock.reset();
|
|
|
|
|
2020-02-26 19:09:19 -05:00
|
|
|
commonUtils.backOff.mockReset();
|
2019-11-26 16:06:38 -05:00
|
|
|
createFlash.mockReset();
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
2019-11-26 16:06:38 -05:00
|
|
|
|
2020-05-07 11:09:29 -04:00
|
|
|
describe('fetchData', () => {
|
|
|
|
it('dispatches fetchEnvironmentsData and fetchEnvironmentsData', () => {
|
|
|
|
return testAction(
|
|
|
|
fetchData,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
2020-05-12 08:09:47 -04:00
|
|
|
[
|
|
|
|
{ type: 'fetchEnvironmentsData' },
|
|
|
|
{ type: 'fetchDashboard' },
|
|
|
|
{ type: 'fetchAnnotations' },
|
|
|
|
],
|
2020-05-07 11:09:29 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches when feature metricsDashboardAnnotations is on', () => {
|
|
|
|
const origGon = window.gon;
|
|
|
|
window.gon = { features: { metricsDashboardAnnotations: true } };
|
|
|
|
|
|
|
|
return testAction(
|
|
|
|
fetchData,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{ type: 'fetchEnvironmentsData' },
|
|
|
|
{ type: 'fetchDashboard' },
|
|
|
|
{ type: 'fetchAnnotations' },
|
|
|
|
],
|
|
|
|
).then(() => {
|
|
|
|
window.gon = origGon;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-18 07:06:03 -05:00
|
|
|
describe('fetchDeploymentsData', () => {
|
2020-04-07 14:09:19 -04:00
|
|
|
it('dispatches receiveDeploymentsDataSuccess on success', () => {
|
2019-11-18 07:06:03 -05:00
|
|
|
state.deploymentsEndpoint = '/success';
|
|
|
|
mock.onGet(state.deploymentsEndpoint).reply(200, {
|
|
|
|
deployments: deploymentData,
|
|
|
|
});
|
2020-04-07 14:09:19 -04:00
|
|
|
|
|
|
|
return testAction(
|
|
|
|
fetchDeploymentsData,
|
|
|
|
null,
|
2019-11-18 07:06:03 -05:00
|
|
|
state,
|
2020-04-07 14:09:19 -04:00
|
|
|
[],
|
|
|
|
[{ type: 'receiveDeploymentsDataSuccess', payload: deploymentData }],
|
|
|
|
);
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
2020-04-07 14:09:19 -04:00
|
|
|
it('dispatches receiveDeploymentsDataFailure on error', () => {
|
2019-11-18 07:06:03 -05:00
|
|
|
state.deploymentsEndpoint = '/error';
|
|
|
|
mock.onGet(state.deploymentsEndpoint).reply(500);
|
2020-04-07 14:09:19 -04:00
|
|
|
|
|
|
|
return testAction(
|
|
|
|
fetchDeploymentsData,
|
|
|
|
null,
|
2019-11-18 07:06:03 -05:00
|
|
|
state,
|
2020-04-07 14:09:19 -04:00
|
|
|
[],
|
|
|
|
[{ type: 'receiveDeploymentsDataFailure' }],
|
|
|
|
() => {
|
|
|
|
expect(createFlash).toHaveBeenCalled();
|
|
|
|
},
|
|
|
|
);
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
|
|
|
});
|
2020-01-29 04:08:49 -05:00
|
|
|
|
2019-11-18 07:06:03 -05:00
|
|
|
describe('fetchEnvironmentsData', () => {
|
2020-05-22 14:08:21 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
state.projectPath = 'gitlab-org/gitlab-test';
|
2020-01-29 04:08:49 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('setting SET_ENVIRONMENTS_FILTER should dispatch fetchEnvironmentsData', () => {
|
2020-04-14 11:09:44 -04:00
|
|
|
jest.spyOn(gqClient, 'mutate').mockReturnValue({
|
|
|
|
data: {
|
|
|
|
project: {
|
|
|
|
data: {
|
|
|
|
environments: [],
|
2020-01-29 04:08:49 -05:00
|
|
|
},
|
|
|
|
},
|
2020-04-14 11:09:44 -04:00
|
|
|
},
|
|
|
|
});
|
2020-01-29 04:08:49 -05:00
|
|
|
|
|
|
|
return testAction(
|
|
|
|
filterEnvironments,
|
|
|
|
{},
|
|
|
|
state,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'SET_ENVIRONMENTS_FILTER',
|
|
|
|
payload: {},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'fetchEnvironmentsData',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
2020-01-24 10:09:00 -05:00
|
|
|
|
2020-01-29 04:08:49 -05:00
|
|
|
it('fetch environments data call takes in search param', () => {
|
|
|
|
const mockMutate = jest.spyOn(gqClient, 'mutate');
|
|
|
|
const searchTerm = 'Something';
|
|
|
|
const mutationVariables = {
|
|
|
|
mutation: getEnvironments,
|
|
|
|
variables: {
|
|
|
|
projectPath: state.projectPath,
|
|
|
|
search: searchTerm,
|
2020-04-08 17:09:50 -04:00
|
|
|
states: [ENVIRONMENT_AVAILABLE_STATE],
|
2020-01-29 04:08:49 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
state.environmentsSearchTerm = searchTerm;
|
2020-04-08 17:09:50 -04:00
|
|
|
mockMutate.mockResolvedValue({});
|
2020-01-29 04:08:49 -05:00
|
|
|
|
2020-04-07 14:09:19 -04:00
|
|
|
return testAction(
|
|
|
|
fetchEnvironmentsData,
|
|
|
|
null,
|
2020-01-29 04:08:49 -05:00
|
|
|
state,
|
2020-04-07 14:09:19 -04:00
|
|
|
[],
|
2020-04-08 17:09:50 -04:00
|
|
|
[
|
|
|
|
{ type: 'requestEnvironmentsData' },
|
|
|
|
{ type: 'receiveEnvironmentsDataSuccess', payload: [] },
|
|
|
|
],
|
2020-04-07 14:09:19 -04:00
|
|
|
() => {
|
|
|
|
expect(mockMutate).toHaveBeenCalledWith(mutationVariables);
|
|
|
|
},
|
|
|
|
);
|
2020-01-29 04:08:49 -05:00
|
|
|
});
|
|
|
|
|
2020-04-07 14:09:19 -04:00
|
|
|
it('dispatches receiveEnvironmentsDataSuccess on success', () => {
|
2020-04-14 11:09:44 -04:00
|
|
|
jest.spyOn(gqClient, 'mutate').mockResolvedValue({
|
|
|
|
data: {
|
|
|
|
project: {
|
|
|
|
data: {
|
|
|
|
environments: environmentData,
|
2020-01-24 10:09:00 -05:00
|
|
|
},
|
|
|
|
},
|
2020-04-14 11:09:44 -04:00
|
|
|
},
|
|
|
|
});
|
2020-01-24 10:09:00 -05:00
|
|
|
|
2020-04-07 14:09:19 -04:00
|
|
|
return testAction(
|
|
|
|
fetchEnvironmentsData,
|
|
|
|
null,
|
2019-11-18 07:06:03 -05:00
|
|
|
state,
|
2020-04-07 14:09:19 -04:00
|
|
|
[],
|
|
|
|
[
|
|
|
|
{ type: 'requestEnvironmentsData' },
|
|
|
|
{
|
|
|
|
type: 'receiveEnvironmentsDataSuccess',
|
|
|
|
payload: parseEnvironmentsResponse(environmentData, state.projectPath),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
2020-01-24 10:09:00 -05:00
|
|
|
|
2020-04-07 14:09:19 -04:00
|
|
|
it('dispatches receiveEnvironmentsDataFailure on error', () => {
|
2020-04-14 11:09:44 -04:00
|
|
|
jest.spyOn(gqClient, 'mutate').mockRejectedValue({});
|
2020-01-24 10:09:00 -05:00
|
|
|
|
2020-04-07 14:09:19 -04:00
|
|
|
return testAction(
|
|
|
|
fetchEnvironmentsData,
|
|
|
|
null,
|
2019-11-18 07:06:03 -05:00
|
|
|
state,
|
2020-04-07 14:09:19 -04:00
|
|
|
[],
|
|
|
|
[{ type: 'requestEnvironmentsData' }, { type: 'receiveEnvironmentsDataFailure' }],
|
|
|
|
);
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
|
|
|
});
|
2020-01-29 04:08:49 -05:00
|
|
|
|
2020-04-14 11:09:44 -04:00
|
|
|
describe('fetchAnnotations', () => {
|
2020-05-22 14:08:21 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
state.timeRange = {
|
|
|
|
start: '2020-04-15T12:54:32.137Z',
|
|
|
|
end: '2020-08-15T12:54:32.137Z',
|
|
|
|
};
|
|
|
|
state.projectPath = 'gitlab-org/gitlab-test';
|
|
|
|
state.currentEnvironmentName = 'production';
|
|
|
|
state.currentDashboard = '.gitlab/dashboards/custom_dashboard.yml';
|
2020-04-14 11:09:44 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('fetches annotations data and dispatches receiveAnnotationsSuccess', () => {
|
|
|
|
const mockMutate = jest.spyOn(gqClient, 'mutate');
|
|
|
|
const mutationVariables = {
|
|
|
|
mutation: getAnnotations,
|
|
|
|
variables: {
|
|
|
|
projectPath: state.projectPath,
|
|
|
|
environmentName: state.currentEnvironmentName,
|
2020-04-21 11:21:10 -04:00
|
|
|
dashboardPath: state.currentDashboard,
|
|
|
|
startingFrom: state.timeRange.start,
|
2020-04-14 11:09:44 -04:00
|
|
|
},
|
|
|
|
};
|
2020-04-21 11:21:10 -04:00
|
|
|
const parsedResponse = parseAnnotationsResponse(annotationsData);
|
2020-04-14 11:09:44 -04:00
|
|
|
|
|
|
|
mockMutate.mockResolvedValue({
|
|
|
|
data: {
|
|
|
|
project: {
|
2020-04-21 11:21:10 -04:00
|
|
|
environments: {
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
metricsDashboard: {
|
|
|
|
annotations: {
|
|
|
|
nodes: parsedResponse,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-04-14 11:09:44 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return testAction(
|
|
|
|
fetchAnnotations,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
2020-04-21 11:21:10 -04:00
|
|
|
[{ type: 'receiveAnnotationsSuccess', payload: parsedResponse }],
|
2020-04-14 11:09:44 -04:00
|
|
|
() => {
|
|
|
|
expect(mockMutate).toHaveBeenCalledWith(mutationVariables);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches receiveAnnotationsFailure if the annotations API call fails', () => {
|
|
|
|
const mockMutate = jest.spyOn(gqClient, 'mutate');
|
|
|
|
const mutationVariables = {
|
|
|
|
mutation: getAnnotations,
|
|
|
|
variables: {
|
|
|
|
projectPath: state.projectPath,
|
|
|
|
environmentName: state.currentEnvironmentName,
|
2020-04-21 11:21:10 -04:00
|
|
|
dashboardPath: state.currentDashboard,
|
|
|
|
startingFrom: state.timeRange.start,
|
2020-04-14 11:09:44 -04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
mockMutate.mockRejectedValue({});
|
|
|
|
|
|
|
|
return testAction(
|
|
|
|
fetchAnnotations,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
2020-04-16 02:09:39 -04:00
|
|
|
[{ type: 'receiveAnnotationsFailure' }],
|
2020-04-14 11:09:44 -04:00
|
|
|
() => {
|
|
|
|
expect(mockMutate).toHaveBeenCalledWith(mutationVariables);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-12 11:10:33 -04:00
|
|
|
describe('Toggles starred value of current dashboard', () => {
|
|
|
|
let unstarredDashboard;
|
|
|
|
let starredDashboard;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state.isUpdatingStarredValue = false;
|
|
|
|
[unstarredDashboard, starredDashboard] = dashboardGitResponse;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleStarredValue', () => {
|
|
|
|
it('performs no changes if no dashboard is selected', () => {
|
|
|
|
return testAction(toggleStarredValue, null, state, [], []);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('performs no changes if already changing starred value', () => {
|
|
|
|
state.selectedDashboard = unstarredDashboard;
|
|
|
|
state.isUpdatingStarredValue = true;
|
|
|
|
return testAction(toggleStarredValue, null, state, [], []);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('stars dashboard if it is not starred', () => {
|
|
|
|
state.selectedDashboard = unstarredDashboard;
|
|
|
|
mock.onPost(unstarredDashboard.user_starred_path).reply(200);
|
|
|
|
|
|
|
|
return testAction(toggleStarredValue, null, state, [
|
|
|
|
{ type: types.REQUEST_DASHBOARD_STARRING },
|
|
|
|
{ type: types.RECEIVE_DASHBOARD_STARRING_SUCCESS, payload: true },
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('unstars dashboard if it is starred', () => {
|
|
|
|
state.selectedDashboard = starredDashboard;
|
|
|
|
mock.onPost(starredDashboard.user_starred_path).reply(200);
|
|
|
|
|
|
|
|
return testAction(toggleStarredValue, null, state, [
|
|
|
|
{ type: types.REQUEST_DASHBOARD_STARRING },
|
|
|
|
{ type: types.RECEIVE_DASHBOARD_STARRING_FAILURE },
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-01 17:07:56 -04:00
|
|
|
describe('Set initial state', () => {
|
|
|
|
it('should commit SET_INITIAL_STATE mutation', done => {
|
2019-11-18 07:06:03 -05:00
|
|
|
testAction(
|
2020-04-01 17:07:56 -04:00
|
|
|
setInitialState,
|
2019-11-18 07:06:03 -05:00
|
|
|
{
|
2020-05-22 14:08:21 -04:00
|
|
|
currentDashboard: '.gitlab/dashboards/dashboard.yml',
|
2019-11-18 07:06:03 -05:00
|
|
|
deploymentsEndpoint: 'deployments.json',
|
|
|
|
},
|
2020-05-22 14:08:21 -04:00
|
|
|
state,
|
2019-11-18 07:06:03 -05:00
|
|
|
[
|
|
|
|
{
|
2020-04-01 17:07:56 -04:00
|
|
|
type: types.SET_INITIAL_STATE,
|
2019-11-18 07:06:03 -05:00
|
|
|
payload: {
|
2020-05-22 14:08:21 -04:00
|
|
|
currentDashboard: '.gitlab/dashboards/dashboard.yml',
|
2019-11-18 07:06:03 -05:00
|
|
|
deploymentsEndpoint: 'deployments.json',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Set empty states', () => {
|
|
|
|
it('should commit SET_METRICS_ENDPOINT mutation', done => {
|
|
|
|
testAction(
|
|
|
|
setGettingStartedEmptyState,
|
|
|
|
null,
|
2020-05-22 14:08:21 -04:00
|
|
|
state,
|
2019-11-18 07:06:03 -05:00
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.SET_GETTING_STARTED_EMPTY_STATE,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-05-08 02:09:40 -04:00
|
|
|
|
2020-05-15 20:08:12 -04:00
|
|
|
describe('updateVariableValues', () => {
|
2020-05-13 17:08:55 -04:00
|
|
|
it('should commit UPDATE_VARIABLE_VALUES mutation', done => {
|
2020-05-08 02:09:40 -04:00
|
|
|
testAction(
|
2020-05-15 20:08:12 -04:00
|
|
|
updateVariableValues,
|
2020-05-08 02:09:40 -04:00
|
|
|
{ pod: 'POD' },
|
2020-05-22 14:08:21 -04:00
|
|
|
state,
|
2020-05-08 02:09:40 -04:00
|
|
|
[
|
|
|
|
{
|
2020-05-13 17:08:55 -04:00
|
|
|
type: types.UPDATE_VARIABLE_VALUES,
|
2020-05-08 02:09:40 -04:00
|
|
|
payload: { pod: 'POD' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-18 07:06:03 -05:00
|
|
|
describe('fetchDashboard', () => {
|
|
|
|
let dispatch;
|
2020-03-04 04:08:20 -05:00
|
|
|
let commit;
|
2019-11-18 07:06:03 -05:00
|
|
|
const response = metricsDashboardResponse;
|
|
|
|
beforeEach(() => {
|
|
|
|
dispatch = jest.fn();
|
2020-03-04 04:08:20 -05:00
|
|
|
commit = jest.fn();
|
2019-11-18 07:06:03 -05:00
|
|
|
state.dashboardEndpoint = '/dashboard';
|
|
|
|
});
|
2020-04-07 14:09:19 -04:00
|
|
|
|
|
|
|
it('on success, dispatches receive and success actions', () => {
|
2019-11-22 04:06:20 -05:00
|
|
|
document.body.dataset.page = 'projects:environments:metrics';
|
2019-11-18 07:06:03 -05:00
|
|
|
mock.onGet(state.dashboardEndpoint).reply(200, response);
|
2020-04-07 14:09:19 -04:00
|
|
|
|
|
|
|
return testAction(
|
|
|
|
fetchDashboard,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{ type: 'requestMetricsDashboard' },
|
|
|
|
{
|
|
|
|
type: 'receiveMetricsDashboardSuccess',
|
|
|
|
payload: { response },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
2019-12-11 04:08:12 -05:00
|
|
|
|
|
|
|
describe('on failure', () => {
|
|
|
|
let result;
|
|
|
|
beforeEach(() => {
|
|
|
|
const params = {};
|
|
|
|
result = () => {
|
2020-03-04 04:08:20 -05:00
|
|
|
mock.onGet(state.dashboardEndpoint).replyOnce(500, mockDashboardsErrorResponse);
|
|
|
|
return fetchDashboard({ state, commit, dispatch }, params);
|
2019-12-11 04:08:12 -05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-04-07 14:09:19 -04:00
|
|
|
it('dispatches a failure', done => {
|
2019-12-11 04:08:12 -05:00
|
|
|
result()
|
|
|
|
.then(() => {
|
2020-03-04 04:08:20 -05:00
|
|
|
expect(commit).toHaveBeenCalledWith(
|
|
|
|
types.SET_ALL_DASHBOARDS,
|
|
|
|
mockDashboardsErrorResponse.all_dashboards,
|
|
|
|
);
|
2019-12-11 04:08:12 -05:00
|
|
|
expect(dispatch).toHaveBeenCalledWith(
|
|
|
|
'receiveMetricsDashboardFailure',
|
|
|
|
new Error('Request failed with status code 500'),
|
|
|
|
);
|
|
|
|
expect(createFlash).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches a failure action when a message is returned', done => {
|
|
|
|
result()
|
|
|
|
.then(() => {
|
|
|
|
expect(dispatch).toHaveBeenCalledWith(
|
|
|
|
'receiveMetricsDashboardFailure',
|
|
|
|
new Error('Request failed with status code 500'),
|
|
|
|
);
|
2020-03-04 04:08:20 -05:00
|
|
|
expect(createFlash).toHaveBeenCalledWith(
|
|
|
|
expect.stringContaining(mockDashboardsErrorResponse.message),
|
|
|
|
);
|
2019-12-11 04:08:12 -05:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show a flash error when showErrorBanner is disabled', done => {
|
|
|
|
state.showErrorBanner = false;
|
|
|
|
|
|
|
|
result()
|
|
|
|
.then(() => {
|
|
|
|
expect(dispatch).toHaveBeenCalledWith(
|
|
|
|
'receiveMetricsDashboardFailure',
|
|
|
|
new Error('Request failed with status code 500'),
|
|
|
|
);
|
|
|
|
expect(createFlash).not.toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('receiveMetricsDashboardSuccess', () => {
|
|
|
|
let commit;
|
|
|
|
let dispatch;
|
2020-04-07 14:09:19 -04:00
|
|
|
|
2019-11-18 07:06:03 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
commit = jest.fn();
|
|
|
|
dispatch = jest.fn();
|
|
|
|
});
|
2020-04-07 14:09:19 -04:00
|
|
|
|
|
|
|
it('stores groups', () => {
|
2019-11-18 07:06:03 -05:00
|
|
|
const response = metricsDashboardResponse;
|
2020-04-07 14:09:19 -04:00
|
|
|
receiveMetricsDashboardSuccess({ state, commit, dispatch }, { response });
|
2019-11-18 07:06:03 -05:00
|
|
|
expect(commit).toHaveBeenCalledWith(
|
2020-04-07 14:09:19 -04:00
|
|
|
types.RECEIVE_METRICS_DASHBOARD_SUCCESS,
|
2020-02-26 19:09:19 -05:00
|
|
|
|
2020-01-14 07:07:41 -05:00
|
|
|
metricsDashboardResponse.dashboard,
|
2019-11-18 07:06:03 -05:00
|
|
|
);
|
2020-04-14 08:09:26 -04:00
|
|
|
expect(dispatch).toHaveBeenCalledWith('fetchDashboardData');
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
2020-05-15 20:08:12 -04:00
|
|
|
|
|
|
|
it('stores templating variables', () => {
|
|
|
|
const response = {
|
|
|
|
...metricsDashboardResponse.dashboard,
|
|
|
|
...mockTemplatingData.allVariableTypes.dashboard,
|
|
|
|
};
|
|
|
|
|
|
|
|
receiveMetricsDashboardSuccess(
|
|
|
|
{ state, commit, dispatch },
|
|
|
|
{
|
|
|
|
response: {
|
|
|
|
...metricsDashboardResponse,
|
|
|
|
dashboard: {
|
|
|
|
...metricsDashboardResponse.dashboard,
|
|
|
|
...mockTemplatingData.allVariableTypes.dashboard,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(commit).toHaveBeenCalledWith(
|
|
|
|
types.RECEIVE_METRICS_DASHBOARD_SUCCESS,
|
|
|
|
|
|
|
|
response,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-11-18 07:06:03 -05:00
|
|
|
it('sets the dashboards loaded from the repository', () => {
|
|
|
|
const params = {};
|
|
|
|
const response = metricsDashboardResponse;
|
|
|
|
response.all_dashboards = dashboardGitResponse;
|
|
|
|
receiveMetricsDashboardSuccess(
|
|
|
|
{
|
|
|
|
state,
|
|
|
|
commit,
|
|
|
|
dispatch,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
response,
|
|
|
|
params,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
expect(commit).toHaveBeenCalledWith(types.SET_ALL_DASHBOARDS, dashboardGitResponse);
|
|
|
|
});
|
|
|
|
});
|
2020-04-14 08:09:26 -04:00
|
|
|
describe('fetchDashboardData', () => {
|
2019-11-18 07:06:03 -05:00
|
|
|
let commit;
|
|
|
|
let dispatch;
|
2019-12-11 04:08:12 -05:00
|
|
|
|
2019-11-18 07:06:03 -05:00
|
|
|
beforeEach(() => {
|
2019-12-11 04:08:12 -05:00
|
|
|
jest.spyOn(Tracking, 'event');
|
2019-11-18 07:06:03 -05:00
|
|
|
commit = jest.fn();
|
|
|
|
dispatch = jest.fn();
|
2020-04-07 14:09:19 -04:00
|
|
|
|
|
|
|
state.timeRange = defaultTimeRange;
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
2019-12-11 04:08:12 -05:00
|
|
|
|
2019-11-18 07:06:03 -05:00
|
|
|
it('commits empty state when state.groups is empty', done => {
|
2019-12-11 04:08:12 -05:00
|
|
|
const getters = {
|
|
|
|
metricsWithData: () => [],
|
|
|
|
};
|
2020-04-14 08:09:26 -04:00
|
|
|
fetchDashboardData({ state, commit, dispatch, getters })
|
2019-11-18 07:06:03 -05:00
|
|
|
.then(() => {
|
2019-12-11 04:08:12 -05:00
|
|
|
expect(Tracking.event).toHaveBeenCalledWith(
|
|
|
|
document.body.dataset.page,
|
|
|
|
'dashboard_fetch',
|
|
|
|
{
|
|
|
|
label: 'custom_metrics_dashboard',
|
|
|
|
property: 'count',
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
);
|
2020-04-07 14:09:19 -04:00
|
|
|
expect(dispatch).toHaveBeenCalledTimes(1);
|
|
|
|
expect(dispatch).toHaveBeenCalledWith('fetchDeploymentsData');
|
|
|
|
|
2019-11-26 16:06:38 -05:00
|
|
|
expect(createFlash).not.toHaveBeenCalled();
|
2019-11-18 07:06:03 -05:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
it('dispatches fetchPrometheusMetric for each panel query', done => {
|
2020-02-26 19:09:19 -05:00
|
|
|
state.dashboard.panelGroups = convertObjectPropsToCamelCase(
|
|
|
|
metricsDashboardResponse.dashboard.panel_groups,
|
|
|
|
);
|
|
|
|
|
|
|
|
const [metric] = state.dashboard.panelGroups[0].panels[0].metrics;
|
2019-12-11 04:08:12 -05:00
|
|
|
const getters = {
|
|
|
|
metricsWithData: () => [metric.id],
|
|
|
|
};
|
|
|
|
|
2020-04-14 08:09:26 -04:00
|
|
|
fetchDashboardData({ state, commit, dispatch, getters })
|
2019-11-26 16:06:38 -05:00
|
|
|
.then(() => {
|
|
|
|
expect(dispatch).toHaveBeenCalledWith('fetchPrometheusMetric', {
|
|
|
|
metric,
|
2020-04-07 14:09:19 -04:00
|
|
|
defaultQueryParams: {
|
|
|
|
start_time: expect.any(String),
|
|
|
|
end_time: expect.any(String),
|
|
|
|
step: expect.any(Number),
|
|
|
|
},
|
2019-11-26 16:06:38 -05:00
|
|
|
});
|
|
|
|
|
2019-12-11 04:08:12 -05:00
|
|
|
expect(Tracking.event).toHaveBeenCalledWith(
|
|
|
|
document.body.dataset.page,
|
|
|
|
'dashboard_fetch',
|
|
|
|
{
|
|
|
|
label: 'custom_metrics_dashboard',
|
|
|
|
property: 'count',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
);
|
2019-11-26 16:06:38 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches fetchPrometheusMetric for each panel query, handles an error', done => {
|
2020-02-26 19:09:19 -05:00
|
|
|
state.dashboard.panelGroups = metricsDashboardViewModel.panelGroups;
|
|
|
|
const metric = state.dashboard.panelGroups[0].panels[0].metrics[0];
|
2019-11-26 16:06:38 -05:00
|
|
|
|
2020-04-07 14:09:19 -04:00
|
|
|
dispatch.mockResolvedValueOnce(); // fetchDeploymentsData
|
2020-02-26 19:09:19 -05:00
|
|
|
// Mock having one out of four metrics failing
|
2019-11-26 16:06:38 -05:00
|
|
|
dispatch.mockRejectedValueOnce(new Error('Error fetching this metric'));
|
|
|
|
dispatch.mockResolvedValue();
|
|
|
|
|
2020-04-14 08:09:26 -04:00
|
|
|
fetchDashboardData({ state, commit, dispatch })
|
2019-11-18 07:06:03 -05:00
|
|
|
.then(() => {
|
2020-04-16 02:09:39 -04:00
|
|
|
expect(dispatch).toHaveBeenCalledTimes(metricsDashboardPanelCount + 1); // plus 1 for deployments
|
2020-04-07 14:09:19 -04:00
|
|
|
expect(dispatch).toHaveBeenCalledWith('fetchDeploymentsData');
|
2019-11-18 07:06:03 -05:00
|
|
|
expect(dispatch).toHaveBeenCalledWith('fetchPrometheusMetric', {
|
|
|
|
metric,
|
2020-04-07 14:09:19 -04:00
|
|
|
defaultQueryParams: {
|
|
|
|
start_time: expect.any(String),
|
|
|
|
end_time: expect.any(String),
|
|
|
|
step: expect.any(Number),
|
|
|
|
},
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
2019-11-26 16:06:38 -05:00
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledTimes(1);
|
|
|
|
|
2019-11-18 07:06:03 -05:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('fetchPrometheusMetric', () => {
|
2020-04-07 14:09:19 -04:00
|
|
|
const defaultQueryParams = {
|
2020-03-23 20:09:24 -04:00
|
|
|
start_time: '2019-08-06T12:40:02.184Z',
|
|
|
|
end_time: '2019-08-06T20:40:02.184Z',
|
2020-04-07 14:09:19 -04:00
|
|
|
step: 60,
|
2019-11-26 16:06:38 -05:00
|
|
|
};
|
|
|
|
let metric;
|
|
|
|
let data;
|
2020-04-16 02:09:39 -04:00
|
|
|
let prometheusEndpointPath;
|
2019-11-26 16:06:38 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = storeState();
|
2020-04-16 02:09:39 -04:00
|
|
|
[metric] = metricsDashboardViewModel.panelGroups[0].panels[0].metrics;
|
|
|
|
|
|
|
|
prometheusEndpointPath = metric.prometheusEndpointPath;
|
2020-02-26 19:09:19 -05:00
|
|
|
|
|
|
|
data = {
|
|
|
|
metricId: metric.metricId,
|
|
|
|
result: [1582065167.353, 5, 1582065599.353],
|
|
|
|
};
|
2019-11-26 16:06:38 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('commits result', done => {
|
2020-04-16 02:09:39 -04:00
|
|
|
mock.onGet(prometheusEndpointPath).reply(200, { data }); // One attempt
|
2019-11-26 16:06:38 -05:00
|
|
|
|
2019-12-13 07:07:41 -05:00
|
|
|
testAction(
|
|
|
|
fetchPrometheusMetric,
|
2020-04-07 14:09:19 -04:00
|
|
|
{ metric, defaultQueryParams },
|
2019-12-13 07:07:41 -05:00
|
|
|
state,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.REQUEST_METRIC_RESULT,
|
|
|
|
payload: {
|
2020-02-26 19:09:19 -05:00
|
|
|
metricId: metric.metricId,
|
2019-12-13 07:07:41 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_METRIC_RESULT_SUCCESS,
|
|
|
|
payload: {
|
2020-02-26 19:09:19 -05:00
|
|
|
metricId: metric.metricId,
|
2019-12-13 07:07:41 -05:00
|
|
|
result: data.result,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
() => {
|
2019-11-26 16:06:38 -05:00
|
|
|
expect(mock.history.get).toHaveLength(1);
|
2019-11-18 07:06:03 -05:00
|
|
|
done();
|
2019-12-13 07:07:41 -05:00
|
|
|
},
|
|
|
|
).catch(done.fail);
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
2019-11-26 16:06:38 -05:00
|
|
|
|
2020-04-02 17:07:51 -04:00
|
|
|
describe('without metric defined step', () => {
|
|
|
|
const expectedParams = {
|
|
|
|
start_time: '2019-08-06T12:40:02.184Z',
|
|
|
|
end_time: '2019-08-06T20:40:02.184Z',
|
|
|
|
step: 60,
|
|
|
|
};
|
|
|
|
|
|
|
|
it('uses calculated step', done => {
|
2020-04-16 02:09:39 -04:00
|
|
|
mock.onGet(prometheusEndpointPath).reply(200, { data }); // One attempt
|
2020-04-02 17:07:51 -04:00
|
|
|
|
|
|
|
testAction(
|
|
|
|
fetchPrometheusMetric,
|
2020-04-07 14:09:19 -04:00
|
|
|
{ metric, defaultQueryParams },
|
2020-04-02 17:07:51 -04:00
|
|
|
state,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.REQUEST_METRIC_RESULT,
|
|
|
|
payload: {
|
|
|
|
metricId: metric.metricId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_METRIC_RESULT_SUCCESS,
|
|
|
|
payload: {
|
|
|
|
metricId: metric.metricId,
|
|
|
|
result: data.result,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
() => {
|
|
|
|
expect(mock.history.get[0].params).toEqual(expectedParams);
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
).catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with metric defined step', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
metric.step = 7;
|
|
|
|
});
|
|
|
|
|
|
|
|
const expectedParams = {
|
|
|
|
start_time: '2019-08-06T12:40:02.184Z',
|
|
|
|
end_time: '2019-08-06T20:40:02.184Z',
|
|
|
|
step: 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
it('uses metric step', done => {
|
2020-04-16 02:09:39 -04:00
|
|
|
mock.onGet(prometheusEndpointPath).reply(200, { data }); // One attempt
|
2020-04-02 17:07:51 -04:00
|
|
|
|
|
|
|
testAction(
|
|
|
|
fetchPrometheusMetric,
|
2020-04-07 14:09:19 -04:00
|
|
|
{ metric, defaultQueryParams },
|
2020-04-02 17:07:51 -04:00
|
|
|
state,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.REQUEST_METRIC_RESULT,
|
|
|
|
payload: {
|
|
|
|
metricId: metric.metricId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_METRIC_RESULT_SUCCESS,
|
|
|
|
payload: {
|
|
|
|
metricId: metric.metricId,
|
|
|
|
result: data.result,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
() => {
|
|
|
|
expect(mock.history.get[0].params).toEqual(expectedParams);
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
).catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-26 16:06:38 -05:00
|
|
|
it('commits result, when waiting for results', done => {
|
|
|
|
// Mock multiple attempts while the cache is filling up
|
2020-04-16 02:09:39 -04:00
|
|
|
mock.onGet(prometheusEndpointPath).replyOnce(statusCodes.NO_CONTENT);
|
|
|
|
mock.onGet(prometheusEndpointPath).replyOnce(statusCodes.NO_CONTENT);
|
|
|
|
mock.onGet(prometheusEndpointPath).replyOnce(statusCodes.NO_CONTENT);
|
|
|
|
mock.onGet(prometheusEndpointPath).reply(200, { data }); // 4th attempt
|
2019-11-26 16:06:38 -05:00
|
|
|
|
2019-12-13 07:07:41 -05:00
|
|
|
testAction(
|
|
|
|
fetchPrometheusMetric,
|
2020-04-07 14:09:19 -04:00
|
|
|
{ metric, defaultQueryParams },
|
2019-12-13 07:07:41 -05:00
|
|
|
state,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.REQUEST_METRIC_RESULT,
|
|
|
|
payload: {
|
2020-02-26 19:09:19 -05:00
|
|
|
metricId: metric.metricId,
|
2019-12-13 07:07:41 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_METRIC_RESULT_SUCCESS,
|
|
|
|
payload: {
|
2020-02-26 19:09:19 -05:00
|
|
|
metricId: metric.metricId,
|
2019-12-13 07:07:41 -05:00
|
|
|
result: data.result,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
() => {
|
2019-11-26 16:06:38 -05:00
|
|
|
expect(mock.history.get).toHaveLength(4);
|
|
|
|
done();
|
2019-12-13 07:07:41 -05:00
|
|
|
},
|
|
|
|
).catch(done.fail);
|
2019-11-26 16:06:38 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('commits failure, when waiting for results and getting a server error', done => {
|
|
|
|
// Mock multiple attempts while the cache is filling up and fails
|
2020-04-16 02:09:39 -04:00
|
|
|
mock.onGet(prometheusEndpointPath).replyOnce(statusCodes.NO_CONTENT);
|
|
|
|
mock.onGet(prometheusEndpointPath).replyOnce(statusCodes.NO_CONTENT);
|
|
|
|
mock.onGet(prometheusEndpointPath).replyOnce(statusCodes.NO_CONTENT);
|
|
|
|
mock.onGet(prometheusEndpointPath).reply(500); // 4th attempt
|
2019-11-26 16:06:38 -05:00
|
|
|
|
2019-12-13 07:07:41 -05:00
|
|
|
const error = new Error('Request failed with status code 500');
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
fetchPrometheusMetric,
|
2020-04-07 14:09:19 -04:00
|
|
|
{ metric, defaultQueryParams },
|
2019-12-13 07:07:41 -05:00
|
|
|
state,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.REQUEST_METRIC_RESULT,
|
|
|
|
payload: {
|
2020-02-26 19:09:19 -05:00
|
|
|
metricId: metric.metricId,
|
2019-12-13 07:07:41 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-12-17 10:08:15 -05:00
|
|
|
type: types.RECEIVE_METRIC_RESULT_FAILURE,
|
2019-12-13 07:07:41 -05:00
|
|
|
payload: {
|
2020-02-26 19:09:19 -05:00
|
|
|
metricId: metric.metricId,
|
2019-12-13 07:07:41 -05:00
|
|
|
error,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
).catch(e => {
|
|
|
|
expect(mock.history.get).toHaveLength(4);
|
|
|
|
expect(e).toEqual(error);
|
|
|
|
done();
|
|
|
|
});
|
2019-11-26 16:06:38 -05:00
|
|
|
});
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|
2020-01-16 13:08:46 -05:00
|
|
|
|
|
|
|
describe('duplicateSystemDashboard', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
state.dashboardsEndpoint = '/dashboards.json';
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Succesful POST request resolves', done => {
|
|
|
|
mock.onPost(state.dashboardsEndpoint).reply(statusCodes.CREATED, {
|
|
|
|
dashboard: dashboardGitResponse[1],
|
|
|
|
});
|
|
|
|
|
|
|
|
testAction(duplicateSystemDashboard, {}, state, [], [])
|
|
|
|
.then(() => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Succesful POST request resolves to a dashboard', done => {
|
|
|
|
const mockCreatedDashboard = dashboardGitResponse[1];
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
dashboard: 'my-dashboard',
|
|
|
|
fileName: 'file-name.yml',
|
|
|
|
branch: 'my-new-branch',
|
|
|
|
commitMessage: 'A new commit message',
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectedPayload = JSON.stringify({
|
|
|
|
dashboard: 'my-dashboard',
|
|
|
|
file_name: 'file-name.yml',
|
|
|
|
branch: 'my-new-branch',
|
|
|
|
commit_message: 'A new commit message',
|
|
|
|
});
|
|
|
|
|
|
|
|
mock.onPost(state.dashboardsEndpoint).reply(statusCodes.CREATED, {
|
|
|
|
dashboard: mockCreatedDashboard,
|
|
|
|
});
|
|
|
|
|
|
|
|
testAction(duplicateSystemDashboard, params, state, [], [])
|
|
|
|
.then(result => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
expect(mock.history.post[0].data).toEqual(expectedPayload);
|
|
|
|
expect(result).toEqual(mockCreatedDashboard);
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Failed POST request throws an error', done => {
|
|
|
|
mock.onPost(state.dashboardsEndpoint).reply(statusCodes.BAD_REQUEST);
|
|
|
|
|
|
|
|
testAction(duplicateSystemDashboard, {}, state, [], []).catch(err => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
expect(err).toEqual(expect.any(String));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Failed POST request throws an error with a description', done => {
|
|
|
|
const backendErrorMsg = 'This file already exists!';
|
|
|
|
|
|
|
|
mock.onPost(state.dashboardsEndpoint).reply(statusCodes.BAD_REQUEST, {
|
|
|
|
error: backendErrorMsg,
|
|
|
|
});
|
|
|
|
|
|
|
|
testAction(duplicateSystemDashboard, {}, state, [], []).catch(err => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
expect(err).toEqual(expect.any(String));
|
|
|
|
expect(err).toEqual(expect.stringContaining(backendErrorMsg));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-04-29 11:09:58 -04:00
|
|
|
|
|
|
|
describe('setExpandedPanel', () => {
|
|
|
|
it('Sets a panel as expanded', () => {
|
|
|
|
const group = 'group_1';
|
|
|
|
const panel = { title: 'A Panel' };
|
|
|
|
|
|
|
|
return testAction(
|
|
|
|
setExpandedPanel,
|
|
|
|
{ group, panel },
|
|
|
|
state,
|
|
|
|
[{ type: types.SET_EXPANDED_PANEL, payload: { group, panel } }],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('clearExpandedPanel', () => {
|
|
|
|
it('Clears a panel as expanded', () => {
|
|
|
|
return testAction(
|
|
|
|
clearExpandedPanel,
|
|
|
|
undefined,
|
|
|
|
state,
|
|
|
|
[{ type: types.SET_EXPANDED_PANEL, payload: { group: null, panel: null } }],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-11-18 07:06:03 -05:00
|
|
|
});
|