aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts
diff options
context:
space:
mode:
authorWouter Admiraal <wouter.admiraal@sonarsource.com>2019-12-17 16:55:03 +0100
committerSonarTech <sonartech@sonarsource.com>2020-02-10 20:46:14 +0100
commit26f66a70c8de871cc93f234398412966f160b1b8 (patch)
tree708aea302109ba6f9b296001f7b60e36fe80010a /server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts
parentea0e05cedbe604baa4b9ad50148353d7356237c2 (diff)
downloadsonarqube-26f66a70c8de871cc93f234398412966f160b1b8.tar.gz
sonarqube-26f66a70c8de871cc93f234398412966f160b1b8.zip
Extract metric keys to a global Enum, simplify mocking
Diffstat (limited to 'server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts')
-rw-r--r--server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts
new file mode 100644
index 00000000000..ea9bffaf05a
--- /dev/null
+++ b/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import { enhanceConditionWithMeasure } from '../measures';
+import { mockQualityGateStatusCondition } from '../mocks/quality-gates';
+import { mockMeasureEnhanced, mockMetric } from '../testMocks';
+
+describe('enhanceConditionWithMeasure', () => {
+ it('should correctly map enhance conditions with measure data', () => {
+ const measures = [
+ mockMeasureEnhanced({ metric: mockMetric({ key: 'bugs' }), periods: undefined }),
+ mockMeasureEnhanced({ metric: mockMetric({ key: 'new_bugs' }) })
+ ];
+
+ expect(
+ enhanceConditionWithMeasure(mockQualityGateStatusCondition({ metric: 'bugs' }), measures)
+ ).toMatchObject({
+ measure: expect.objectContaining({ metric: expect.objectContaining({ key: 'bugs' }) })
+ });
+
+ expect(
+ enhanceConditionWithMeasure(mockQualityGateStatusCondition({ metric: 'new_bugs' }), measures)
+ ).toMatchObject({
+ measure: expect.objectContaining({
+ metric: expect.objectContaining({ key: 'new_bugs' })
+ }),
+ period: 1
+ });
+ });
+
+ it('should return undefined if no match can be found', () => {
+ expect(enhanceConditionWithMeasure(mockQualityGateStatusCondition(), [])).toBeUndefined();
+ });
+});