diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-20 21:06:18 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-20 21:06:18 +0000 |
commit | 12577c6e3988054d510529d8de4ec99d1cdbfc85 (patch) | |
tree | bcc2f3881365f43116a79dc22ddff66134b43518 /spec/javascripts/monitoring | |
parent | 4c6c0280a6111a2d9d5364a9d5a513e7fc538dd7 (diff) | |
download | gitlab-ce-12577c6e3988054d510529d8de4ec99d1cdbfc85.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts/monitoring')
-rw-r--r-- | spec/javascripts/monitoring/store/mutations_spec.js | 7 | ||||
-rw-r--r-- | spec/javascripts/monitoring/store/utils_spec.js | 41 |
2 files changed, 44 insertions, 4 deletions
diff --git a/spec/javascripts/monitoring/store/mutations_spec.js b/spec/javascripts/monitoring/store/mutations_spec.js index bdb68a80a8a..bdddd83358c 100644 --- a/spec/javascripts/monitoring/store/mutations_spec.js +++ b/spec/javascripts/monitoring/store/mutations_spec.js @@ -7,6 +7,7 @@ import { metricsDashboardResponse, dashboardGitResponse, } from '../mock_data'; +import { uniqMetricsId } from '~/monitoring/stores/utils'; describe('Monitoring mutations', () => { let stateCopy; @@ -128,6 +129,7 @@ describe('Monitoring mutations', () => { describe('SET_QUERY_RESULT', () => { const metricId = 12; + const id = 'system_metrics_kubernetes_container_memory_total'; const result = [{ values: [[0, 1], [1, 1], [1, 3]] }]; beforeEach(() => { @@ -146,12 +148,13 @@ describe('Monitoring mutations', () => { }); it('sets metricsWithData value', () => { + const uniqId = uniqMetricsId({ metric_id: metricId, id }); mutations[types.SET_QUERY_RESULT](stateCopy, { - metricId, + metricId: uniqId, result, }); - expect(stateCopy.metricsWithData).toEqual([12]); + expect(stateCopy.metricsWithData).toEqual([uniqId]); }); it('does not store empty results', () => { diff --git a/spec/javascripts/monitoring/store/utils_spec.js b/spec/javascripts/monitoring/store/utils_spec.js index 73dd370ffb3..98388ac19f8 100644 --- a/spec/javascripts/monitoring/store/utils_spec.js +++ b/spec/javascripts/monitoring/store/utils_spec.js @@ -1,4 +1,4 @@ -import { groupQueriesByChartInfo } from '~/monitoring/stores/utils'; +import { groupQueriesByChartInfo, normalizeMetric, uniqMetricsId } from '~/monitoring/stores/utils'; describe('groupQueriesByChartInfo', () => { let input; @@ -12,7 +12,11 @@ describe('groupQueriesByChartInfo', () => { ]; output = [ - { title: 'title', y_label: 'MB', queries: [{ metricId: null }, { metricId: null }] }, + { + title: 'title', + y_label: 'MB', + queries: [{ metricId: null }, { metricId: null }], + }, { title: 'new title', y_label: 'MB', queries: [{ metricId: null }] }, ]; @@ -35,3 +39,36 @@ describe('groupQueriesByChartInfo', () => { expect(groupQueriesByChartInfo(input)).toEqual(output); }); }); + +describe('normalizeMetric', () => { + [ + { args: [], expected: 'undefined_undefined' }, + { args: [undefined], expected: 'undefined_undefined' }, + { args: [{ id: 'something' }], expected: 'undefined_something' }, + { args: [{ id: 45 }], expected: 'undefined_45' }, + { args: [{ metric_id: 5 }], expected: '5_undefined' }, + { args: [{ metric_id: 'something' }], expected: 'something_undefined' }, + { + args: [{ metric_id: 5, id: 'system_metrics_kubernetes_container_memory_total' }], + expected: '5_system_metrics_kubernetes_container_memory_total', + }, + ].forEach(({ args, expected }) => { + it(`normalizes metric to "${expected}" with args=${JSON.stringify(args)}`, () => { + expect(normalizeMetric(...args)).toEqual({ metric_id: expected }); + }); + }); +}); + +describe('uniqMetricsId', () => { + [ + { input: { id: 1 }, expected: 'undefined_1' }, + { input: { metric_id: 2 }, expected: '2_undefined' }, + { input: { metric_id: 2, id: 21 }, expected: '2_21' }, + { input: { metric_id: 22, id: 1 }, expected: '22_1' }, + { input: { metric_id: 'aaa', id: '_a' }, expected: 'aaa__a' }, + ].forEach(({ input, expected }) => { + it(`creates unique metric ID with ${JSON.stringify(input)}`, () => { + expect(uniqMetricsId(input)).toEqual(expected); + }); + }); +}); |