Commit 534db60f authored by Miguel Rincon's avatar Miguel Rincon

Simplify reference to the store in specs

As wrapper.vm.$store also refers to the store, this change
simplifies referencing to the store.
parent bd732f92
...@@ -39,7 +39,7 @@ describe('Dashboard', () => { ...@@ -39,7 +39,7 @@ describe('Dashboard', () => {
const findEnvironmentsDropdown = () => wrapper.find({ ref: 'monitorEnvironmentsDropdown' }); const findEnvironmentsDropdown = () => wrapper.find({ ref: 'monitorEnvironmentsDropdown' });
const findAllEnvironmentsDropdownItems = () => findEnvironmentsDropdown().findAll(GlDropdownItem); const findAllEnvironmentsDropdownItems = () => findEnvironmentsDropdown().findAll(GlDropdownItem);
const setSearchTerm = searchTerm => { const setSearchTerm = searchTerm => {
wrapper.vm.$store.commit(`monitoringDashboard/${types.SET_ENVIRONMENTS_FILTER}`, searchTerm); store.commit(`monitoringDashboard/${types.SET_ENVIRONMENTS_FILTER}`, searchTerm);
}; };
const createShallowWrapper = (props = {}, options = {}) => { const createShallowWrapper = (props = {}, options = {}) => {
...@@ -135,7 +135,7 @@ describe('Dashboard', () => { ...@@ -135,7 +135,7 @@ describe('Dashboard', () => {
it('hides the group panels when showPanels is false', () => { it('hides the group panels when showPanels is false', () => {
createMountedWrapper({ hasMetrics: true, showPanels: false }); createMountedWrapper({ hasMetrics: true, showPanels: false });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.showEmptyState).toEqual(false); expect(wrapper.vm.showEmptyState).toEqual(false);
...@@ -148,7 +148,7 @@ describe('Dashboard', () => { ...@@ -148,7 +148,7 @@ describe('Dashboard', () => {
createMountedWrapper({ hasMetrics: true }); createMountedWrapper({ hasMetrics: true });
wrapper.vm.$store.commit( store.commit(
`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`, `monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`,
environmentData, environmentData,
); );
...@@ -188,7 +188,7 @@ describe('Dashboard', () => { ...@@ -188,7 +188,7 @@ describe('Dashboard', () => {
); );
createMountedWrapper({ hasMetrics: true }); createMountedWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(store.dispatch).toHaveBeenCalledWith('monitoringDashboard/setExpandedPanel', { expect(store.dispatch).toHaveBeenCalledWith('monitoringDashboard/setExpandedPanel', {
...@@ -205,7 +205,7 @@ describe('Dashboard', () => { ...@@ -205,7 +205,7 @@ describe('Dashboard', () => {
setSearch(''); setSearch('');
createMountedWrapper({ hasMetrics: true }); createMountedWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(store.dispatch).not.toHaveBeenCalledWith( expect(store.dispatch).not.toHaveBeenCalledWith(
...@@ -228,7 +228,7 @@ describe('Dashboard', () => { ...@@ -228,7 +228,7 @@ describe('Dashboard', () => {
); );
createMountedWrapper({ hasMetrics: true }); createMountedWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(createFlash).toHaveBeenCalled(); expect(createFlash).toHaveBeenCalled();
...@@ -328,7 +328,7 @@ describe('Dashboard', () => { ...@@ -328,7 +328,7 @@ describe('Dashboard', () => {
beforeEach(() => { beforeEach(() => {
createMountedWrapper({ hasMetrics: true }); createMountedWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -436,7 +436,7 @@ describe('Dashboard', () => { ...@@ -436,7 +436,7 @@ describe('Dashboard', () => {
it('hides the environments dropdown list when there is no environments', () => { it('hides the environments dropdown list when there is no environments', () => {
createMountedWrapper({ hasMetrics: true }); createMountedWrapper({ hasMetrics: true });
setupStoreWithDashboard(wrapper.vm.$store); setupStoreWithDashboard(store);
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(findAllEnvironmentsDropdownItems()).toHaveLength(0); expect(findAllEnvironmentsDropdownItems()).toHaveLength(0);
...@@ -446,7 +446,7 @@ describe('Dashboard', () => { ...@@ -446,7 +446,7 @@ describe('Dashboard', () => {
it('renders the datetimepicker dropdown', () => { it('renders the datetimepicker dropdown', () => {
createMountedWrapper({ hasMetrics: true }); createMountedWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find(DateTimePicker).exists()).toBe(true); expect(wrapper.find(DateTimePicker).exists()).toBe(true);
...@@ -456,7 +456,7 @@ describe('Dashboard', () => { ...@@ -456,7 +456,7 @@ describe('Dashboard', () => {
it('renders the refresh dashboard button', () => { it('renders the refresh dashboard button', () => {
createMountedWrapper({ hasMetrics: true }); createMountedWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
const refreshBtn = wrapper.findAll({ ref: 'refreshDashboardBtn' }); const refreshBtn = wrapper.findAll({ ref: 'refreshDashboardBtn' });
...@@ -469,8 +469,8 @@ describe('Dashboard', () => { ...@@ -469,8 +469,8 @@ describe('Dashboard', () => {
describe('variables section', () => { describe('variables section', () => {
beforeEach(() => { beforeEach(() => {
createShallowWrapper({ hasMetrics: true }); createShallowWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
setupStoreWithVariable(wrapper.vm.$store); setupStoreWithVariable(store);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -486,7 +486,7 @@ describe('Dashboard', () => { ...@@ -486,7 +486,7 @@ describe('Dashboard', () => {
describe('when the panel is not expanded', () => { describe('when the panel is not expanded', () => {
beforeEach(() => { beforeEach(() => {
createShallowWrapper({ hasMetrics: true }); createShallowWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -524,14 +524,14 @@ describe('Dashboard', () => { ...@@ -524,14 +524,14 @@ describe('Dashboard', () => {
beforeEach(() => { beforeEach(() => {
createShallowWrapper({ hasMetrics: true }, { stubs: { DashboardPanel: MockPanel } }); createShallowWrapper({ hasMetrics: true }, { stubs: { DashboardPanel: MockPanel } });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
const { panelGroups } = wrapper.vm.$store.state.monitoringDashboard.dashboard; const { panelGroups } = store.state.monitoringDashboard.dashboard;
group = panelGroups[0].group; group = panelGroups[0].group;
[panel] = panelGroups[0].panels; [panel] = panelGroups[0].panels;
wrapper.vm.$store.commit(`monitoringDashboard/${types.SET_EXPANDED_PANEL}`, { store.commit(`monitoringDashboard/${types.SET_EXPANDED_PANEL}`, {
group, group,
panel, panel,
}); });
...@@ -593,10 +593,8 @@ describe('Dashboard', () => { ...@@ -593,10 +593,8 @@ describe('Dashboard', () => {
beforeEach(() => { beforeEach(() => {
createShallowWrapper({ hasMetrics: true }); createShallowWrapper({ hasMetrics: true });
const { $store } = wrapper.vm; setupStoreWithDashboard(store);
setMetricResult({ store, result: [], panel: 2 });
setupStoreWithDashboard($store);
setMetricResult({ $store, result: [], panel: 2 });
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -622,7 +620,7 @@ describe('Dashboard', () => { ...@@ -622,7 +620,7 @@ describe('Dashboard', () => {
beforeEach(() => { beforeEach(() => {
createMountedWrapper({ hasMetrics: true }, { attachToDocument: true }); createMountedWrapper({ hasMetrics: true }, { attachToDocument: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -673,7 +671,7 @@ describe('Dashboard', () => { ...@@ -673,7 +671,7 @@ describe('Dashboard', () => {
}); });
it('shows loading element when environments fetch is still loading', () => { it('shows loading element when environments fetch is still loading', () => {
wrapper.vm.$store.commit(`monitoringDashboard/${types.REQUEST_ENVIRONMENTS_DATA}`); store.commit(`monitoringDashboard/${types.REQUEST_ENVIRONMENTS_DATA}`);
return wrapper.vm return wrapper.vm
.$nextTick() .$nextTick()
...@@ -681,7 +679,7 @@ describe('Dashboard', () => { ...@@ -681,7 +679,7 @@ describe('Dashboard', () => {
expect(wrapper.find({ ref: 'monitorEnvironmentsDropdownLoading' }).exists()).toBe(true); expect(wrapper.find({ ref: 'monitorEnvironmentsDropdownLoading' }).exists()).toBe(true);
}) })
.then(() => { .then(() => {
wrapper.vm.$store.commit( store.commit(
`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`, `monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`,
environmentData, environmentData,
); );
...@@ -703,7 +701,7 @@ describe('Dashboard', () => { ...@@ -703,7 +701,7 @@ describe('Dashboard', () => {
store.dispatch.mockRestore(); store.dispatch.mockRestore();
createShallowWrapper({ hasMetrics: true }); createShallowWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -791,7 +789,7 @@ describe('Dashboard', () => { ...@@ -791,7 +789,7 @@ describe('Dashboard', () => {
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
wrapper.vm.$store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, undefined); store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, undefined);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -917,7 +915,7 @@ describe('Dashboard', () => { ...@@ -917,7 +915,7 @@ describe('Dashboard', () => {
customMetricsPath: '/endpoint', customMetricsPath: '/endpoint',
customMetricsAvailable: true, customMetricsAvailable: true,
}); });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(store);
origPage = document.body.dataset.page; origPage = document.body.dataset.page;
document.body.dataset.page = 'projects:environments:metrics'; document.body.dataset.page = 'projects:environments:metrics';
......
...@@ -43,7 +43,7 @@ describe('Metrics dashboard/variables section component', () => { ...@@ -43,7 +43,7 @@ describe('Metrics dashboard/variables section component', () => {
it('shows the variables section', () => { it('shows the variables section', () => {
createShallowWrapper(); createShallowWrapper();
wrapper.vm.$store.commit(`monitoringDashboard/${types.SET_VARIABLES}`, sampleVariables); store.commit(`monitoringDashboard/${types.SET_VARIABLES}`, sampleVariables);
return wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
const allInputs = findAllFormInputs(); const allInputs = findAllFormInputs();
......
...@@ -2,48 +2,48 @@ import * as types from '~/monitoring/stores/mutation_types'; ...@@ -2,48 +2,48 @@ import * as types from '~/monitoring/stores/mutation_types';
import { metricsResult, environmentData, dashboardGitResponse } from './mock_data'; import { metricsResult, environmentData, dashboardGitResponse } from './mock_data';
import { metricsDashboardPayload } from './fixture_data'; import { metricsDashboardPayload } from './fixture_data';
export const setMetricResult = ({ $store, result, group = 0, panel = 0, metric = 0 }) => { export const setMetricResult = ({ store, result, group = 0, panel = 0, metric = 0 }) => {
const { dashboard } = $store.state.monitoringDashboard; const { dashboard } = store.state.monitoringDashboard;
const { metricId } = dashboard.panelGroups[group].panels[panel].metrics[metric]; const { metricId } = dashboard.panelGroups[group].panels[panel].metrics[metric];
$store.commit(`monitoringDashboard/${types.RECEIVE_METRIC_RESULT_SUCCESS}`, { store.commit(`monitoringDashboard/${types.RECEIVE_METRIC_RESULT_SUCCESS}`, {
metricId, metricId,
result, result,
}); });
}; };
const setEnvironmentData = $store => { const setEnvironmentData = store => {
$store.commit(`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`, environmentData); store.commit(`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`, environmentData);
}; };
export const setupAllDashboards = $store => { export const setupAllDashboards = store => {
$store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, dashboardGitResponse); store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, dashboardGitResponse);
}; };
export const setupStoreWithDashboard = $store => { export const setupStoreWithDashboard = store => {
$store.commit( store.commit(
`monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`, `monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`,
metricsDashboardPayload, metricsDashboardPayload,
); );
$store.commit( store.commit(
`monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`, `monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`,
metricsDashboardPayload, metricsDashboardPayload,
); );
}; };
export const setupStoreWithVariable = $store => { export const setupStoreWithVariable = store => {
$store.commit(`monitoringDashboard/${types.SET_VARIABLES}`, { store.commit(`monitoringDashboard/${types.SET_VARIABLES}`, {
label1: 'pod', label1: 'pod',
}); });
}; };
export const setupStoreWithData = $store => { export const setupStoreWithData = store => {
setupAllDashboards($store); setupAllDashboards(store);
setupStoreWithDashboard($store); setupStoreWithDashboard(store);
setMetricResult({ $store, result: [], panel: 0 }); setMetricResult({ store, result: [], panel: 0 });
setMetricResult({ $store, result: metricsResult, panel: 1 }); setMetricResult({ store, result: metricsResult, panel: 1 });
setMetricResult({ $store, result: metricsResult, panel: 2 }); setMetricResult({ store, result: metricsResult, panel: 2 });
setEnvironmentData($store); setEnvironmentData(store);
}; };
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