diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-04 12:06:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-04 12:06:21 +0300 |
commit | 2b7a5214342baa2575b35868316ea9413d2afe1f (patch) | |
tree | f80a862f7fa382620b8f8a695d07b6d1734fc5f5 /spec/javascripts/monitoring | |
parent | 15a2d004be2f79160752d77f701c0f08e7f96973 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts/monitoring')
4 files changed, 50 insertions, 18 deletions
diff --git a/spec/javascripts/monitoring/charts/time_series_spec.js b/spec/javascripts/monitoring/charts/time_series_spec.js index 31ea9ede9de..42feaca616b 100644 --- a/spec/javascripts/monitoring/charts/time_series_spec.js +++ b/spec/javascripts/monitoring/charts/time_series_spec.js @@ -23,7 +23,7 @@ describe('Time series component', () => { store = createStore(); store.commit(`monitoringDashboard/${types.RECEIVE_METRICS_DATA_SUCCESS}`, MonitoringMock.data); store.commit(`monitoringDashboard/${types.RECEIVE_DEPLOYMENTS_DATA_SUCCESS}`, deploymentData); - [mockGraphData] = store.state.monitoringDashboard.groups[0].metrics; + [, mockGraphData] = store.state.monitoringDashboard.dashboard.panel_groups[0].metrics; makeTimeSeriesChart = (graphData, type) => shallowMount(TimeSeries, { diff --git a/spec/javascripts/monitoring/components/dashboard_spec.js b/spec/javascripts/monitoring/components/dashboard_spec.js index be7ab24185d..4070de4cc35 100644 --- a/spec/javascripts/monitoring/components/dashboard_spec.js +++ b/spec/javascripts/monitoring/components/dashboard_spec.js @@ -442,6 +442,28 @@ describe('Dashboard', () => { expect(findEnabledDraggables()).toEqual(findDraggables()); }); + it('metrics can be swapped', done => { + const firstDraggable = findDraggables().at(0); + const mockMetrics = [...metricsGroupsAPIResponse.data[0].metrics]; + const value = () => firstDraggable.props('value'); + + expect(value().length).toBe(mockMetrics.length); + value().forEach((metric, i) => { + expect(metric.title).toBe(mockMetrics[i].title); + }); + + // swap two elements and `input` them + [mockMetrics[0], mockMetrics[1]] = [mockMetrics[1], mockMetrics[0]]; + firstDraggable.vm.$emit('input', mockMetrics); + + firstDraggable.vm.$nextTick(() => { + value().forEach((metric, i) => { + expect(metric.title).toBe(mockMetrics[i].title); + }); + done(); + }); + }); + it('shows a remove button, which removes a panel', done => { expect(findFirstDraggableRemoveButton().isEmpty()).toBe(false); @@ -449,8 +471,6 @@ describe('Dashboard', () => { findFirstDraggableRemoveButton().trigger('click'); wrapper.vm.$nextTick(() => { - // At present graphs will not be removed in backend - // See https://gitlab.com/gitlab-org/gitlab/issues/27835 expect(findDraggablePanels().length).toEqual(expectedPanelCount - 1); done(); }); @@ -686,7 +706,9 @@ describe('Dashboard', () => { `monitoringDashboard/${types.RECEIVE_METRICS_DATA_SUCCESS}`, MonitoringMock.data, ); - [mockGraphData] = component.$store.state.monitoringDashboard.groups[0].metrics; + [ + mockGraphData, + ] = component.$store.state.monitoringDashboard.dashboard.panel_groups[0].metrics; }); describe('csvText', () => { diff --git a/spec/javascripts/monitoring/store/actions_spec.js b/spec/javascripts/monitoring/store/actions_spec.js index 1bd74f59282..4d602e3b0a2 100644 --- a/spec/javascripts/monitoring/store/actions_spec.js +++ b/spec/javascripts/monitoring/store/actions_spec.js @@ -291,9 +291,9 @@ describe('Monitoring store actions', () => { it('dispatches fetchPrometheusMetric for each panel query', done => { const params = {}; const state = storeState(); - state.groups = metricsDashboardResponse.dashboard.panel_groups; + state.dashboard.panel_groups = metricsDashboardResponse.dashboard.panel_groups; - const metric = state.groups[0].panels[0].metrics[0]; + const metric = state.dashboard.panel_groups[0].panels[0].metrics[0]; fetchPrometheusMetrics({ state, commit, dispatch }, params) .then(() => { diff --git a/spec/javascripts/monitoring/store/mutations_spec.js b/spec/javascripts/monitoring/store/mutations_spec.js index bdddd83358c..49aed1b85e6 100644 --- a/spec/javascripts/monitoring/store/mutations_spec.js +++ b/spec/javascripts/monitoring/store/mutations_spec.js @@ -20,16 +20,26 @@ describe('Monitoring mutations', () => { let groups; beforeEach(() => { - stateCopy.groups = []; + stateCopy.dashboard.panel_groups = []; groups = metricsGroupsAPIResponse.data; }); + it('adds a key to the group', () => { + mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups); + + expect(stateCopy.dashboard.panel_groups[0].key).toBe('kubernetes-0'); + expect(stateCopy.dashboard.panel_groups[1].key).toBe('nginx-1'); + }); + it('normalizes values', () => { mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups); const expectedTimestamp = '2017-05-25T08:22:34.925Z'; - const expectedValue = 0.0010794445585559514; - const [timestamp, value] = stateCopy.groups[0].metrics[0].queries[0].result[0].values[0]; + const expectedValue = 8.0390625; + const [ + timestamp, + value, + ] = stateCopy.dashboard.panel_groups[0].metrics[0].queries[0].result[0].values[0]; expect(timestamp).toEqual(expectedTimestamp); expect(value).toEqual(expectedValue); @@ -38,25 +48,25 @@ describe('Monitoring mutations', () => { it('contains two groups that contains, one of which has two queries sorted by priority', () => { mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups); - expect(stateCopy.groups).toBeDefined(); - expect(stateCopy.groups.length).toEqual(2); - expect(stateCopy.groups[0].metrics.length).toEqual(2); + expect(stateCopy.dashboard.panel_groups).toBeDefined(); + expect(stateCopy.dashboard.panel_groups.length).toEqual(2); + expect(stateCopy.dashboard.panel_groups[0].metrics.length).toEqual(2); }); it('assigns queries a metric id', () => { mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups); - expect(stateCopy.groups[1].metrics[0].queries[0].metricId).toEqual('100'); + expect(stateCopy.dashboard.panel_groups[1].metrics[0].queries[0].metricId).toEqual('100'); }); it('removes the data if all the values from a query are not defined', () => { mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, groups); - expect(stateCopy.groups[1].metrics[0].queries[0].result.length).toEqual(0); + expect(stateCopy.dashboard.panel_groups[1].metrics[0].queries[0].result.length).toEqual(0); }); it('assigns metric id of null if metric has no id', () => { - stateCopy.groups = []; + stateCopy.dashboard.panel_groups = []; const noId = groups.map(group => ({ ...group, ...{ @@ -70,7 +80,7 @@ describe('Monitoring mutations', () => { mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, noId); - stateCopy.groups.forEach(group => { + stateCopy.dashboard.panel_groups.forEach(group => { group.metrics.forEach(metric => { expect(metric.queries.every(query => query.metricId === null)).toBe(true); }); @@ -87,13 +97,13 @@ describe('Monitoring mutations', () => { it('aliases group panels to metrics for backwards compatibility', () => { mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboardGroups); - expect(stateCopy.groups[0].metrics[0]).toBeDefined(); + expect(stateCopy.dashboard.panel_groups[0].metrics[0]).toBeDefined(); }); it('aliases panel metrics to queries for backwards compatibility', () => { mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboardGroups); - expect(stateCopy.groups[0].metrics[0].queries).toBeDefined(); + expect(stateCopy.dashboard.panel_groups[0].metrics[0].queries).toBeDefined(); }); }); }); |