Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-23 22:44:23 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-23 22:44:23 +0300
commit6b96d119aec0ba674cca2c380cf60f1500306612 (patch)
treef7742d802f557d04e2144b06a2b47719fbd58b82 /spec/frontend
parent8b7c4494871c7d69ac7bc59839bdce6ff2937f95 (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/monitoring/store/utils_spec.js113
-rw-r--r--spec/frontend/monitoring/store/variable_mapping_spec.js73
-rw-r--r--spec/frontend/monitoring/utils_spec.js78
3 files changed, 189 insertions, 75 deletions
diff --git a/spec/frontend/monitoring/store/utils_spec.js b/spec/frontend/monitoring/store/utils_spec.js
index 3a70bda51da..2dea40585f1 100644
--- a/spec/frontend/monitoring/store/utils_spec.js
+++ b/spec/frontend/monitoring/store/utils_spec.js
@@ -9,6 +9,7 @@ import {
convertToGrafanaTimeRange,
addDashboardMetaDataToLink,
} from '~/monitoring/stores/utils';
+import * as urlUtils from '~/lib/utils/url_utility';
import { annotationsData } from '../mock_data';
import { NOT_IN_DB_PREFIX } from '~/monitoring/constants';
@@ -398,6 +399,118 @@ describe('mapToDashboardViewModel', () => {
});
});
});
+
+ describe('templating variables mapping', () => {
+ beforeEach(() => {
+ jest.spyOn(urlUtils, 'queryToObject');
+ });
+
+ afterEach(() => {
+ urlUtils.queryToObject.mockRestore();
+ });
+
+ it('sets variables as-is from yml file if URL has no variables', () => {
+ const response = {
+ dashboard: 'Dashboard Name',
+ links: [],
+ templating: {
+ variables: {
+ pod: 'kubernetes',
+ pod_2: 'kubernetes-2',
+ },
+ },
+ };
+
+ urlUtils.queryToObject.mockReturnValueOnce();
+
+ expect(mapToDashboardViewModel(response)).toMatchObject({
+ dashboard: 'Dashboard Name',
+ links: [],
+ variables: {
+ pod: {
+ label: 'pod',
+ type: 'text',
+ value: 'kubernetes',
+ },
+ pod_2: {
+ label: 'pod_2',
+ type: 'text',
+ value: 'kubernetes-2',
+ },
+ },
+ });
+ });
+
+ it('sets variables as-is from yml file if URL has no matching variables', () => {
+ const response = {
+ dashboard: 'Dashboard Name',
+ links: [],
+ templating: {
+ variables: {
+ pod: 'kubernetes',
+ pod_2: 'kubernetes-2',
+ },
+ },
+ };
+
+ urlUtils.queryToObject.mockReturnValueOnce({
+ 'var-environment': 'POD',
+ });
+
+ expect(mapToDashboardViewModel(response)).toMatchObject({
+ dashboard: 'Dashboard Name',
+ links: [],
+ variables: {
+ pod: {
+ label: 'pod',
+ type: 'text',
+ value: 'kubernetes',
+ },
+ pod_2: {
+ label: 'pod_2',
+ type: 'text',
+ value: 'kubernetes-2',
+ },
+ },
+ });
+ });
+
+ it('merges variables from URL with the ones from yml file', () => {
+ const response = {
+ dashboard: 'Dashboard Name',
+ links: [],
+ templating: {
+ variables: {
+ pod: 'kubernetes',
+ pod_2: 'kubernetes-2',
+ },
+ },
+ };
+
+ urlUtils.queryToObject.mockReturnValueOnce({
+ 'var-environment': 'POD',
+ 'var-pod': 'POD1',
+ 'var-pod_2': 'POD2',
+ });
+
+ expect(mapToDashboardViewModel(response)).toMatchObject({
+ dashboard: 'Dashboard Name',
+ links: [],
+ variables: {
+ pod: {
+ label: 'pod',
+ type: 'text',
+ value: 'POD1',
+ },
+ pod_2: {
+ label: 'pod_2',
+ type: 'text',
+ value: 'POD2',
+ },
+ },
+ });
+ });
+ });
});
describe('normalizeQueryResult', () => {
diff --git a/spec/frontend/monitoring/store/variable_mapping_spec.js b/spec/frontend/monitoring/store/variable_mapping_spec.js
index c44bb957166..5164ed1b54b 100644
--- a/spec/frontend/monitoring/store/variable_mapping_spec.js
+++ b/spec/frontend/monitoring/store/variable_mapping_spec.js
@@ -1,4 +1,5 @@
-import { parseTemplatingVariables } from '~/monitoring/stores/variable_mapping';
+import { parseTemplatingVariables, mergeURLVariables } from '~/monitoring/stores/variable_mapping';
+import * as urlUtils from '~/lib/utils/url_utility';
import { mockTemplatingData, mockTemplatingDataResponses } from '../mock_data';
describe('parseTemplatingVariables', () => {
@@ -21,3 +22,73 @@ describe('parseTemplatingVariables', () => {
expect(parseTemplatingVariables(input?.dashboard?.templating)).toEqual(expected);
});
});
+
+describe('mergeURLVariables', () => {
+ beforeEach(() => {
+ jest.spyOn(urlUtils, 'queryToObject');
+ });
+
+ afterEach(() => {
+ urlUtils.queryToObject.mockRestore();
+ });
+
+ it('returns empty object if variables are not defined in yml or URL', () => {
+ urlUtils.queryToObject.mockReturnValueOnce({});
+
+ expect(mergeURLVariables({})).toEqual({});
+ });
+
+ it('returns empty object if variables are defined in URL but not in yml', () => {
+ urlUtils.queryToObject.mockReturnValueOnce({
+ 'var-env': 'one',
+ 'var-instance': 'localhost',
+ });
+
+ expect(mergeURLVariables({})).toEqual({});
+ });
+
+ it('returns yml variables if variables defined in yml but not in the URL', () => {
+ urlUtils.queryToObject.mockReturnValueOnce({});
+
+ const params = {
+ env: 'one',
+ instance: 'localhost',
+ };
+
+ expect(mergeURLVariables(params)).toEqual(params);
+ });
+
+ it('returns yml variables if variables defined in URL do not match with yml variables', () => {
+ const urlParams = {
+ 'var-env': 'one',
+ 'var-instance': 'localhost',
+ };
+ const ymlParams = {
+ pod: { value: 'one' },
+ service: { value: 'database' },
+ };
+ urlUtils.queryToObject.mockReturnValueOnce(urlParams);
+
+ expect(mergeURLVariables(ymlParams)).toEqual(ymlParams);
+ });
+
+ it('returns merged yml and URL variables if there is some match', () => {
+ const urlParams = {
+ 'var-env': 'one',
+ 'var-instance': 'localhost:8080',
+ };
+ const ymlParams = {
+ instance: { value: 'localhost' },
+ service: { value: 'database' },
+ };
+
+ const merged = {
+ instance: { value: 'localhost:8080' },
+ service: { value: 'database' },
+ };
+
+ urlUtils.queryToObject.mockReturnValueOnce(urlParams);
+
+ expect(mergeURLVariables(ymlParams)).toEqual(merged);
+ });
+});
diff --git a/spec/frontend/monitoring/utils_spec.js b/spec/frontend/monitoring/utils_spec.js
index aa5a4459a72..039cf275eea 100644
--- a/spec/frontend/monitoring/utils_spec.js
+++ b/spec/frontend/monitoring/utils_spec.js
@@ -169,8 +169,8 @@ describe('monitoring/utils', () => {
});
});
- describe('getPromCustomVariablesFromUrl', () => {
- const { getPromCustomVariablesFromUrl } = monitoringUtils;
+ describe('templatingVariablesFromUrl', () => {
+ const { templatingVariablesFromUrl } = monitoringUtils;
beforeEach(() => {
jest.spyOn(urlUtils, 'queryToObject');
@@ -195,7 +195,7 @@ describe('monitoring/utils', () => {
'var-pod': 'POD',
});
- expect(getPromCustomVariablesFromUrl()).toEqual(expect.objectContaining({ pod: 'POD' }));
+ expect(templatingVariablesFromUrl()).toEqual(expect.objectContaining({ pod: 'POD' }));
});
it('returns an empty object when no custom variables are present', () => {
@@ -203,7 +203,7 @@ describe('monitoring/utils', () => {
dashboard: '.gitlab/dashboards/custom_dashboard.yml',
});
- expect(getPromCustomVariablesFromUrl()).toStrictEqual({});
+ expect(templatingVariablesFromUrl()).toStrictEqual({});
});
});
@@ -427,76 +427,6 @@ describe('monitoring/utils', () => {
});
});
- describe('mergeURLVariables', () => {
- beforeEach(() => {
- jest.spyOn(urlUtils, 'queryToObject');
- });
-
- afterEach(() => {
- urlUtils.queryToObject.mockRestore();
- });
-
- it('returns empty object if variables are not defined in yml or URL', () => {
- urlUtils.queryToObject.mockReturnValueOnce({});
-
- expect(monitoringUtils.mergeURLVariables({})).toEqual({});
- });
-
- it('returns empty object if variables are defined in URL but not in yml', () => {
- urlUtils.queryToObject.mockReturnValueOnce({
- 'var-env': 'one',
- 'var-instance': 'localhost',
- });
-
- expect(monitoringUtils.mergeURLVariables({})).toEqual({});
- });
-
- it('returns yml variables if variables defined in yml but not in the URL', () => {
- urlUtils.queryToObject.mockReturnValueOnce({});
-
- const params = {
- env: 'one',
- instance: 'localhost',
- };
-
- expect(monitoringUtils.mergeURLVariables(params)).toEqual(params);
- });
-
- it('returns yml variables if variables defined in URL do not match with yml variables', () => {
- const urlParams = {
- 'var-env': 'one',
- 'var-instance': 'localhost',
- };
- const ymlParams = {
- pod: { value: 'one' },
- service: { value: 'database' },
- };
- urlUtils.queryToObject.mockReturnValueOnce(urlParams);
-
- expect(monitoringUtils.mergeURLVariables(ymlParams)).toEqual(ymlParams);
- });
-
- it('returns merged yml and URL variables if there is some match', () => {
- const urlParams = {
- 'var-env': 'one',
- 'var-instance': 'localhost:8080',
- };
- const ymlParams = {
- instance: { value: 'localhost' },
- service: { value: 'database' },
- };
-
- const merged = {
- instance: { value: 'localhost:8080' },
- service: { value: 'database' },
- };
-
- urlUtils.queryToObject.mockReturnValueOnce(urlParams);
-
- expect(monitoringUtils.mergeURLVariables(ymlParams)).toEqual(merged);
- });
- });
-
describe('convertVariablesForURL', () => {
it.each`
input | expected