Commit 85735517 authored by Miguel Rincon's avatar Miguel Rincon

Refactor state initialization for monitoring dashboard

In order to make the dashboard easier to test, we can remove props
from it and instead initialize it previously.
parent f93290b5
...@@ -111,28 +111,10 @@ export default { ...@@ -111,28 +111,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
projectPath: {
type: String,
required: true,
},
logsPath: {
type: String,
required: false,
default: invalidUrl,
},
defaultBranch: { defaultBranch: {
type: String, type: String,
required: true, required: true,
}, },
metricsEndpoint: {
type: String,
required: true,
},
deploymentsEndpoint: {
type: String,
required: false,
default: null,
},
emptyGettingStartedSvgPath: { emptyGettingStartedSvgPath: {
type: String, type: String,
required: true, required: true,
...@@ -153,10 +135,6 @@ export default { ...@@ -153,10 +135,6 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
currentEnvironmentName: {
type: String,
required: true,
},
customMetricsAvailable: { customMetricsAvailable: {
type: Boolean, type: Boolean,
required: false, required: false,
...@@ -172,21 +150,6 @@ export default { ...@@ -172,21 +150,6 @@ export default {
required: false, required: false,
default: invalidUrl, default: invalidUrl,
}, },
dashboardEndpoint: {
type: String,
required: false,
default: invalidUrl,
},
dashboardsEndpoint: {
type: String,
required: false,
default: invalidUrl,
},
currentDashboard: {
type: String,
required: false,
default: '',
},
smallEmptyState: { smallEmptyState: {
type: Boolean, type: Boolean,
required: false, required: false,
...@@ -228,6 +191,8 @@ export default { ...@@ -228,6 +191,8 @@ export default {
'expandedPanel', 'expandedPanel',
'variables', 'variables',
'isUpdatingStarredValue', 'isUpdatingStarredValue',
'currentDashboard',
'currentEnvironmentName',
]), ]),
...mapGetters('monitoringDashboard', [ ...mapGetters('monitoringDashboard', [
'selectedDashboard', 'selectedDashboard',
...@@ -281,16 +246,6 @@ export default { ...@@ -281,16 +246,6 @@ export default {
}, },
}, },
created() { created() {
this.setInitialState({
metricsEndpoint: this.metricsEndpoint,
deploymentsEndpoint: this.deploymentsEndpoint,
dashboardEndpoint: this.dashboardEndpoint,
dashboardsEndpoint: this.dashboardsEndpoint,
currentDashboard: this.currentDashboard,
projectPath: this.projectPath,
logsPath: this.logsPath,
currentEnvironmentName: this.currentEnvironmentName,
});
window.addEventListener('keyup', this.onKeyup); window.addEventListener('keyup', this.onKeyup);
}, },
destroyed() { destroyed() {
...@@ -310,7 +265,6 @@ export default { ...@@ -310,7 +265,6 @@ export default {
'fetchData', 'fetchData',
'fetchDashboardData', 'fetchDashboardData',
'setGettingStartedEmptyState', 'setGettingStartedEmptyState',
'setInitialState',
'setPanelGroupMetrics', 'setPanelGroupMetrics',
'filterEnvironments', 'filterEnvironments',
'setExpandedPanel', 'setExpandedPanel',
......
...@@ -140,7 +140,6 @@ export const dateFormats = { ...@@ -140,7 +140,6 @@ export const dateFormats = {
* Currently used in `receiveMetricsDashboardSuccess` action. * Currently used in `receiveMetricsDashboardSuccess` action.
*/ */
export const endpointKeys = [ export const endpointKeys = [
'metricsEndpoint',
'deploymentsEndpoint', 'deploymentsEndpoint',
'dashboardEndpoint', 'dashboardEndpoint',
'dashboardsEndpoint', 'dashboardsEndpoint',
......
...@@ -3,7 +3,7 @@ import { GlToast } from '@gitlab/ui'; ...@@ -3,7 +3,7 @@ import { GlToast } from '@gitlab/ui';
import Dashboard from '~/monitoring/components/dashboard.vue'; import Dashboard from '~/monitoring/components/dashboard.vue';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
import { getParameterValues } from '~/lib/utils/url_utility'; import { getParameterValues } from '~/lib/utils/url_utility';
import store from './stores'; import { createStore } from './stores';
Vue.use(GlToast); Vue.use(GlToast);
...@@ -13,6 +13,31 @@ export default (props = {}) => { ...@@ -13,6 +13,31 @@ export default (props = {}) => {
if (el && el.dataset) { if (el && el.dataset) {
const [currentDashboard] = getParameterValues('dashboard'); const [currentDashboard] = getParameterValues('dashboard');
const {
deploymentsEndpoint,
dashboardEndpoint,
dashboardsEndpoint,
projectPath,
logsPath,
currentEnvironmentName,
...dataProps
} = el.dataset;
const store = createStore({
currentDashboard,
deploymentsEndpoint,
dashboardEndpoint,
dashboardsEndpoint,
projectPath,
logsPath,
currentEnvironmentName,
});
// HTML attributes are always strings, parse other types.
dataProps.hasMetrics = parseBoolean(dataProps.hasMetrics);
dataProps.customMetricsAvailable = parseBoolean(dataProps.customMetricsAvailable);
dataProps.prometheusAlertsAvailable = parseBoolean(dataProps.prometheusAlertsAvailable);
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
el, el,
...@@ -20,11 +45,7 @@ export default (props = {}) => { ...@@ -20,11 +45,7 @@ export default (props = {}) => {
render(createElement) { render(createElement) {
return createElement(Dashboard, { return createElement(Dashboard, {
props: { props: {
...el.dataset, ...dataProps,
currentDashboard,
customMetricsAvailable: parseBoolean(el.dataset.customMetricsAvailable),
prometheusAlertsAvailable: parseBoolean(el.dataset.prometheusAlertsAvailable),
hasMetrics: parseBoolean(el.dataset.hasMetrics),
...props, ...props,
}, },
}); });
......
...@@ -314,8 +314,7 @@ export const receiveEnvironmentsDataFailure = ({ commit }) => { ...@@ -314,8 +314,7 @@ export const receiveEnvironmentsDataFailure = ({ commit }) => {
export const fetchAnnotations = ({ state, dispatch }) => { export const fetchAnnotations = ({ state, dispatch }) => {
const { start } = convertToFixedRange(state.timeRange); const { start } = convertToFixedRange(state.timeRange);
const dashboardPath = const dashboardPath = state.currentDashboard || DEFAULT_DASHBOARD_PATH;
state.currentDashboard === '' ? DEFAULT_DASHBOARD_PATH : state.currentDashboard;
return gqClient return gqClient
.mutate({ .mutate({
mutation: getAnnotations, mutation: getAnnotations,
......
...@@ -15,11 +15,15 @@ export const monitoringDashboard = { ...@@ -15,11 +15,15 @@ export const monitoringDashboard = {
state, state,
}; };
export const createStore = () => export const createStore = (initState = {}) =>
new Vuex.Store({ new Vuex.Store({
modules: { modules: {
monitoringDashboard, monitoringDashboard: {
...monitoringDashboard,
state: {
...state(),
...initState,
},
},
}, },
}); });
export default createStore();
...@@ -2,9 +2,9 @@ import invalidUrl from '~/lib/utils/invalid_url'; ...@@ -2,9 +2,9 @@ import invalidUrl from '~/lib/utils/invalid_url';
export default () => ({ export default () => ({
// API endpoints // API endpoints
metricsEndpoint: null,
deploymentsEndpoint: null, deploymentsEndpoint: null,
dashboardEndpoint: invalidUrl, dashboardEndpoint: invalidUrl,
dashboardsEndpoint: invalidUrl,
// Dashboard request parameters // Dashboard request parameters
timeRange: null, timeRange: null,
...@@ -46,6 +46,7 @@ export default () => ({ ...@@ -46,6 +46,7 @@ export default () => ({
environments: [], environments: [],
environmentsSearchTerm: '', environmentsSearchTerm: '',
environmentsLoading: false, environmentsLoading: false,
currentEnvironmentName: null,
// GitLab paths to other pages // GitLab paths to other pages
projectPath: null, projectPath: null,
......
...@@ -6,7 +6,6 @@ import { objectToQuery } from '~/lib/utils/url_utility'; ...@@ -6,7 +6,6 @@ import { objectToQuery } from '~/lib/utils/url_utility';
import VueDraggable from 'vuedraggable'; import VueDraggable from 'vuedraggable';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import statusCodes from '~/lib/utils/http_status';
import { metricStates } from '~/monitoring/constants'; import { metricStates } from '~/monitoring/constants';
import Dashboard from '~/monitoring/components/dashboard.vue'; import Dashboard from '~/monitoring/components/dashboard.vue';
...@@ -80,19 +79,6 @@ describe('Dashboard', () => { ...@@ -80,19 +79,6 @@ describe('Dashboard', () => {
it('shows the environment selector', () => { it('shows the environment selector', () => {
expect(findEnvironmentsDropdown().exists()).toBe(true); expect(findEnvironmentsDropdown().exists()).toBe(true);
}); });
it('sets initial state', () => {
expect(store.dispatch).toHaveBeenCalledWith('monitoringDashboard/setInitialState', {
currentDashboard: '',
currentEnvironmentName: 'production',
dashboardEndpoint: 'https://invalid',
dashboardsEndpoint: 'https://invalid',
deploymentsEndpoint: null,
logsPath: '/path/to/logs',
metricsEndpoint: 'http://test.host/monitoring/mock',
projectPath: '/path/to/project',
});
});
}); });
describe('no data found', () => { describe('no data found', () => {
...@@ -288,7 +274,10 @@ describe('Dashboard', () => { ...@@ -288,7 +274,10 @@ describe('Dashboard', () => {
it('URL is updated with panel parameters and custom dashboard', () => { it('URL is updated with panel parameters and custom dashboard', () => {
const dashboard = 'dashboard.yml'; const dashboard = 'dashboard.yml';
createMountedWrapper({ hasMetrics: true, currentDashboard: dashboard }); store.commit(`monitoringDashboard/${types.SET_INITIAL_STATE}`, {
currentDashboard: dashboard,
});
createMountedWrapper({ hasMetrics: true });
expandPanel(group, panel); expandPanel(group, panel);
const expectedSearch = objectToQuery({ const expectedSearch = objectToQuery({
...@@ -326,8 +315,10 @@ describe('Dashboard', () => { ...@@ -326,8 +315,10 @@ describe('Dashboard', () => {
describe('when all requests have been commited by the store', () => { describe('when all requests have been commited by the store', () => {
beforeEach(() => { beforeEach(() => {
store.commit(`monitoringDashboard/${types.SET_INITIAL_STATE}`, {
currentEnvironmentName: 'production',
});
createMountedWrapper({ hasMetrics: true }); createMountedWrapper({ hasMetrics: true });
setupStoreWithData(store); setupStoreWithData(store);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
...@@ -785,7 +776,6 @@ describe('Dashboard', () => { ...@@ -785,7 +776,6 @@ describe('Dashboard', () => {
describe('cluster health', () => { describe('cluster health', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet(propsData.metricsEndpoint).reply(statusCodes.OK, JSON.stringify({}));
createShallowWrapper({ hasMetrics: true, showHeader: false }); createShallowWrapper({ hasMetrics: true, showHeader: false });
// all_dashboards is not defined in health dashboards // all_dashboards is not defined in health dashboards
...@@ -877,7 +867,10 @@ describe('Dashboard', () => { ...@@ -877,7 +867,10 @@ describe('Dashboard', () => {
beforeEach(() => { beforeEach(() => {
setupStoreWithData(store); setupStoreWithData(store);
createShallowWrapper({ hasMetrics: true, currentDashboard }); store.commit(`monitoringDashboard/${types.SET_INITIAL_STATE}`, {
currentDashboard,
});
createShallowWrapper({ hasMetrics: true });
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
......
...@@ -14,7 +14,9 @@ describe('Dashboard template', () => { ...@@ -14,7 +14,9 @@ describe('Dashboard template', () => {
let mock; let mock;
beforeEach(() => { beforeEach(() => {
store = createStore(); store = createStore({
currentEnvironmentName: 'production',
});
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
setupAllDashboards(store); setupAllDashboards(store);
......
...@@ -11,17 +11,12 @@ export const propsData = { ...@@ -11,17 +11,12 @@ export const propsData = {
settingsPath: '/path/to/settings', settingsPath: '/path/to/settings',
clustersPath: '/path/to/clusters', clustersPath: '/path/to/clusters',
tagsPath: '/path/to/tags', tagsPath: '/path/to/tags',
projectPath: '/path/to/project',
logsPath: '/path/to/logs',
defaultBranch: 'master', defaultBranch: 'master',
metricsEndpoint: mockApiEndpoint,
deploymentsEndpoint: null,
emptyGettingStartedSvgPath: '/path/to/getting-started.svg', emptyGettingStartedSvgPath: '/path/to/getting-started.svg',
emptyLoadingSvgPath: '/path/to/loading.svg', emptyLoadingSvgPath: '/path/to/loading.svg',
emptyNoDataSvgPath: '/path/to/no-data.svg', emptyNoDataSvgPath: '/path/to/no-data.svg',
emptyNoDataSmallSvgPath: '/path/to/no-data-small.svg', emptyNoDataSmallSvgPath: '/path/to/no-data-small.svg',
emptyUnableToConnectSvgPath: '/path/to/unable-to-connect.svg', emptyUnableToConnectSvgPath: '/path/to/unable-to-connect.svg',
currentEnvironmentName: 'production',
customMetricsAvailable: false, customMetricsAvailable: false,
customMetricsPath: '', customMetricsPath: '',
validateQueryPath: '', validateQueryPath: '',
......
...@@ -8,7 +8,7 @@ import createFlash from '~/flash'; ...@@ -8,7 +8,7 @@ import createFlash from '~/flash';
import { defaultTimeRange } from '~/vue_shared/constants'; import { defaultTimeRange } from '~/vue_shared/constants';
import { ENVIRONMENT_AVAILABLE_STATE } from '~/monitoring/constants'; import { ENVIRONMENT_AVAILABLE_STATE } from '~/monitoring/constants';
import store from '~/monitoring/stores'; import { createStore } from '~/monitoring/stores';
import * as types from '~/monitoring/stores/mutation_types'; import * as types from '~/monitoring/stores/mutation_types';
import { import {
fetchData, fetchData,
...@@ -52,20 +52,16 @@ import { ...@@ -52,20 +52,16 @@ import {
jest.mock('~/flash'); jest.mock('~/flash');
const resetStore = str => {
str.replaceState({
showEmptyState: true,
emptyState: 'loading',
groups: [],
});
};
describe('Monitoring store actions', () => { describe('Monitoring store actions', () => {
const { convertObjectPropsToCamelCase } = commonUtils; const { convertObjectPropsToCamelCase } = commonUtils;
let mock; let mock;
let store;
let state;
beforeEach(() => { beforeEach(() => {
store = createStore();
state = store.state.monitoringDashboard;
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
jest.spyOn(commonUtils, 'backOff').mockImplementation(callback => { jest.spyOn(commonUtils, 'backOff').mockImplementation(callback => {
...@@ -83,7 +79,6 @@ describe('Monitoring store actions', () => { ...@@ -83,7 +79,6 @@ describe('Monitoring store actions', () => {
}); });
}); });
afterEach(() => { afterEach(() => {
resetStore(store);
mock.reset(); mock.reset();
commonUtils.backOff.mockReset(); commonUtils.backOff.mockReset();
...@@ -92,8 +87,6 @@ describe('Monitoring store actions', () => { ...@@ -92,8 +87,6 @@ describe('Monitoring store actions', () => {
describe('fetchData', () => { describe('fetchData', () => {
it('dispatches fetchEnvironmentsData and fetchEnvironmentsData', () => { it('dispatches fetchEnvironmentsData and fetchEnvironmentsData', () => {
const { state } = store;
return testAction( return testAction(
fetchData, fetchData,
null, null,
...@@ -111,8 +104,6 @@ describe('Monitoring store actions', () => { ...@@ -111,8 +104,6 @@ describe('Monitoring store actions', () => {
const origGon = window.gon; const origGon = window.gon;
window.gon = { features: { metricsDashboardAnnotations: true } }; window.gon = { features: { metricsDashboardAnnotations: true } };
const { state } = store;
return testAction( return testAction(
fetchData, fetchData,
null, null,
...@@ -131,7 +122,6 @@ describe('Monitoring store actions', () => { ...@@ -131,7 +122,6 @@ describe('Monitoring store actions', () => {
describe('fetchDeploymentsData', () => { describe('fetchDeploymentsData', () => {
it('dispatches receiveDeploymentsDataSuccess on success', () => { it('dispatches receiveDeploymentsDataSuccess on success', () => {
const { state } = store;
state.deploymentsEndpoint = '/success'; state.deploymentsEndpoint = '/success';
mock.onGet(state.deploymentsEndpoint).reply(200, { mock.onGet(state.deploymentsEndpoint).reply(200, {
deployments: deploymentData, deployments: deploymentData,
...@@ -146,7 +136,6 @@ describe('Monitoring store actions', () => { ...@@ -146,7 +136,6 @@ describe('Monitoring store actions', () => {
); );
}); });
it('dispatches receiveDeploymentsDataFailure on error', () => { it('dispatches receiveDeploymentsDataFailure on error', () => {
const { state } = store;
state.deploymentsEndpoint = '/error'; state.deploymentsEndpoint = '/error';
mock.onGet(state.deploymentsEndpoint).reply(500); mock.onGet(state.deploymentsEndpoint).reply(500);
...@@ -164,11 +153,8 @@ describe('Monitoring store actions', () => { ...@@ -164,11 +153,8 @@ describe('Monitoring store actions', () => {
}); });
describe('fetchEnvironmentsData', () => { describe('fetchEnvironmentsData', () => {
const { state } = store; beforeEach(() => {
state.projectPath = 'gitlab-org/gitlab-test'; state.projectPath = 'gitlab-org/gitlab-test';
afterEach(() => {
resetStore(store);
}); });
it('setting SET_ENVIRONMENTS_FILTER should dispatch fetchEnvironmentsData', () => { it('setting SET_ENVIRONMENTS_FILTER should dispatch fetchEnvironmentsData', () => {
...@@ -269,7 +255,7 @@ describe('Monitoring store actions', () => { ...@@ -269,7 +255,7 @@ describe('Monitoring store actions', () => {
}); });
describe('fetchAnnotations', () => { describe('fetchAnnotations', () => {
const { state } = store; beforeEach(() => {
state.timeRange = { state.timeRange = {
start: '2020-04-15T12:54:32.137Z', start: '2020-04-15T12:54:32.137Z',
end: '2020-08-15T12:54:32.137Z', end: '2020-08-15T12:54:32.137Z',
...@@ -277,9 +263,6 @@ describe('Monitoring store actions', () => { ...@@ -277,9 +263,6 @@ describe('Monitoring store actions', () => {
state.projectPath = 'gitlab-org/gitlab-test'; state.projectPath = 'gitlab-org/gitlab-test';
state.currentEnvironmentName = 'production'; state.currentEnvironmentName = 'production';
state.currentDashboard = '.gitlab/dashboards/custom_dashboard.yml'; state.currentDashboard = '.gitlab/dashboards/custom_dashboard.yml';
afterEach(() => {
resetStore(store);
}); });
it('fetches annotations data and dispatches receiveAnnotationsSuccess', () => { it('fetches annotations data and dispatches receiveAnnotationsSuccess', () => {
...@@ -353,7 +336,6 @@ describe('Monitoring store actions', () => { ...@@ -353,7 +336,6 @@ describe('Monitoring store actions', () => {
}); });
describe('Toggles starred value of current dashboard', () => { describe('Toggles starred value of current dashboard', () => {
const { state } = store;
let unstarredDashboard; let unstarredDashboard;
let starredDashboard; let starredDashboard;
...@@ -396,23 +378,19 @@ describe('Monitoring store actions', () => { ...@@ -396,23 +378,19 @@ describe('Monitoring store actions', () => {
}); });
describe('Set initial state', () => { describe('Set initial state', () => {
let mockedState;
beforeEach(() => {
mockedState = storeState();
});
it('should commit SET_INITIAL_STATE mutation', done => { it('should commit SET_INITIAL_STATE mutation', done => {
testAction( testAction(
setInitialState, setInitialState,
{ {
metricsEndpoint: 'additional_metrics.json', currentDashboard: '.gitlab/dashboards/dashboard.yml',
deploymentsEndpoint: 'deployments.json', deploymentsEndpoint: 'deployments.json',
}, },
mockedState, state,
[ [
{ {
type: types.SET_INITIAL_STATE, type: types.SET_INITIAL_STATE,
payload: { payload: {
metricsEndpoint: 'additional_metrics.json', currentDashboard: '.gitlab/dashboards/dashboard.yml',
deploymentsEndpoint: 'deployments.json', deploymentsEndpoint: 'deployments.json',
}, },
}, },
...@@ -423,15 +401,11 @@ describe('Monitoring store actions', () => { ...@@ -423,15 +401,11 @@ describe('Monitoring store actions', () => {
}); });
}); });
describe('Set empty states', () => { describe('Set empty states', () => {
let mockedState;
beforeEach(() => {
mockedState = storeState();
});
it('should commit SET_METRICS_ENDPOINT mutation', done => { it('should commit SET_METRICS_ENDPOINT mutation', done => {
testAction( testAction(
setGettingStartedEmptyState, setGettingStartedEmptyState,
null, null,
mockedState, state,
[ [
{ {
type: types.SET_GETTING_STARTED_EMPTY_STATE, type: types.SET_GETTING_STARTED_EMPTY_STATE,
...@@ -444,15 +418,11 @@ describe('Monitoring store actions', () => { ...@@ -444,15 +418,11 @@ describe('Monitoring store actions', () => {
}); });
describe('updateVariableValues', () => { describe('updateVariableValues', () => {
let mockedState;
beforeEach(() => {
mockedState = storeState();
});
it('should commit UPDATE_VARIABLE_VALUES mutation', done => { it('should commit UPDATE_VARIABLE_VALUES mutation', done => {
testAction( testAction(
updateVariableValues, updateVariableValues,
{ pod: 'POD' }, { pod: 'POD' },
mockedState, state,
[ [
{ {
type: types.UPDATE_VARIABLE_VALUES, type: types.UPDATE_VARIABLE_VALUES,
...@@ -467,13 +437,11 @@ describe('Monitoring store actions', () => { ...@@ -467,13 +437,11 @@ describe('Monitoring store actions', () => {
describe('fetchDashboard', () => { describe('fetchDashboard', () => {
let dispatch; let dispatch;
let state;
let commit; let commit;
const response = metricsDashboardResponse; const response = metricsDashboardResponse;
beforeEach(() => { beforeEach(() => {
dispatch = jest.fn(); dispatch = jest.fn();
commit = jest.fn(); commit = jest.fn();
state = storeState();
state.dashboardEndpoint = '/dashboard'; state.dashboardEndpoint = '/dashboard';
}); });
...@@ -557,12 +525,10 @@ describe('Monitoring store actions', () => { ...@@ -557,12 +525,10 @@ describe('Monitoring store actions', () => {
describe('receiveMetricsDashboardSuccess', () => { describe('receiveMetricsDashboardSuccess', () => {
let commit; let commit;
let dispatch; let dispatch;
let state;
beforeEach(() => { beforeEach(() => {
commit = jest.fn(); commit = jest.fn();
dispatch = jest.fn(); dispatch = jest.fn();
state = storeState();
}); });
it('stores groups', () => { it('stores groups', () => {
...@@ -623,13 +589,11 @@ describe('Monitoring store actions', () => { ...@@ -623,13 +589,11 @@ describe('Monitoring store actions', () => {
describe('fetchDashboardData', () => { describe('fetchDashboardData', () => {
let commit; let commit;
let dispatch; let dispatch;
let state;
beforeEach(() => { beforeEach(() => {
jest.spyOn(Tracking, 'event'); jest.spyOn(Tracking, 'event');
commit = jest.fn(); commit = jest.fn();
dispatch = jest.fn(); dispatch = jest.fn();
state = storeState();
state.timeRange = defaultTimeRange; state.timeRange = defaultTimeRange;
}); });
...@@ -731,7 +695,6 @@ describe('Monitoring store actions', () => { ...@@ -731,7 +695,6 @@ describe('Monitoring store actions', () => {
step: 60, step: 60,
}; };
let metric; let metric;
let state;
let data; let data;
let prometheusEndpointPath; let prometheusEndpointPath;
...@@ -929,10 +892,7 @@ describe('Monitoring store actions', () => { ...@@ -929,10 +892,7 @@ describe('Monitoring store actions', () => {
}); });
describe('duplicateSystemDashboard', () => { describe('duplicateSystemDashboard', () => {
let state;
beforeEach(() => { beforeEach(() => {
state = storeState();
state.dashboardsEndpoint = '/dashboards.json'; state.dashboardsEndpoint = '/dashboards.json';
}); });
...@@ -1010,12 +970,6 @@ describe('Monitoring store actions', () => { ...@@ -1010,12 +970,6 @@ describe('Monitoring store actions', () => {
}); });
describe('setExpandedPanel', () => { describe('setExpandedPanel', () => {
let state;
beforeEach(() => {
state = storeState();
});
it('Sets a panel as expanded', () => { it('Sets a panel as expanded', () => {
const group = 'group_1'; const group = 'group_1';
const panel = { title: 'A Panel' }; const panel = { title: 'A Panel' };
...@@ -1031,12 +985,6 @@ describe('Monitoring store actions', () => { ...@@ -1031,12 +985,6 @@ describe('Monitoring store actions', () => {
}); });
describe('clearExpandedPanel', () => { describe('clearExpandedPanel', () => {
let state;
beforeEach(() => {
state = storeState();
});
it('Clears a panel as expanded', () => { it('Clears a panel as expanded', () => {
return testAction( return testAction(
clearExpandedPanel, clearExpandedPanel,
......
import { createStore } from '~/monitoring/stores';
describe('Monitoring Store Index', () => {
it('creates store with a `monitoringDashboard` namespace', () => {
expect(createStore().state).toEqual({
monitoringDashboard: expect.any(Object),
});
});
it('creates store with initial values', () => {
const defaults = {
deploymentsEndpoint: '/mock/deployments',
dashboardEndpoint: '/mock/dashboard',
dashboardsEndpoint: '/mock/dashboards',
};
const { state } = createStore(defaults);
expect(state).toEqual({
monitoringDashboard: expect.objectContaining(defaults),
});
});
});
...@@ -128,13 +128,11 @@ describe('Monitoring mutations', () => { ...@@ -128,13 +128,11 @@ describe('Monitoring mutations', () => {
describe('SET_INITIAL_STATE', () => { describe('SET_INITIAL_STATE', () => {
it('should set all the endpoints', () => { it('should set all the endpoints', () => {
mutations[types.SET_INITIAL_STATE](stateCopy, { mutations[types.SET_INITIAL_STATE](stateCopy, {
metricsEndpoint: 'additional_metrics.json',
deploymentsEndpoint: 'deployments.json', deploymentsEndpoint: 'deployments.json',
dashboardEndpoint: 'dashboard.json', dashboardEndpoint: 'dashboard.json',
projectPath: '/gitlab-org/gitlab-foss', projectPath: '/gitlab-org/gitlab-foss',
currentEnvironmentName: 'production', currentEnvironmentName: 'production',
}); });
expect(stateCopy.metricsEndpoint).toEqual('additional_metrics.json');
expect(stateCopy.deploymentsEndpoint).toEqual('deployments.json'); expect(stateCopy.deploymentsEndpoint).toEqual('deployments.json');
expect(stateCopy.dashboardEndpoint).toEqual('dashboard.json'); expect(stateCopy.dashboardEndpoint).toEqual('dashboard.json');
expect(stateCopy.projectPath).toEqual('/gitlab-org/gitlab-foss'); expect(stateCopy.projectPath).toEqual('/gitlab-org/gitlab-foss');
...@@ -179,12 +177,10 @@ describe('Monitoring mutations', () => { ...@@ -179,12 +177,10 @@ describe('Monitoring mutations', () => {
describe('SET_ENDPOINTS', () => { describe('SET_ENDPOINTS', () => {
it('should set all the endpoints', () => { it('should set all the endpoints', () => {
mutations[types.SET_ENDPOINTS](stateCopy, { mutations[types.SET_ENDPOINTS](stateCopy, {
metricsEndpoint: 'additional_metrics.json',
deploymentsEndpoint: 'deployments.json', deploymentsEndpoint: 'deployments.json',
dashboardEndpoint: 'dashboard.json', dashboardEndpoint: 'dashboard.json',
projectPath: '/gitlab-org/gitlab-foss', projectPath: '/gitlab-org/gitlab-foss',
}); });
expect(stateCopy.metricsEndpoint).toEqual('additional_metrics.json');
expect(stateCopy.deploymentsEndpoint).toEqual('deployments.json'); expect(stateCopy.deploymentsEndpoint).toEqual('deployments.json');
expect(stateCopy.dashboardEndpoint).toEqual('dashboard.json'); expect(stateCopy.dashboardEndpoint).toEqual('dashboard.json');
expect(stateCopy.projectPath).toEqual('/gitlab-org/gitlab-foss'); expect(stateCopy.projectPath).toEqual('/gitlab-org/gitlab-foss');
......
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