diff options
author | Wouter Admiraal <wouter.admiraal@sonarsource.com> | 2019-04-04 15:16:46 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-05-29 20:21:13 +0200 |
commit | 46d075adfb3c4a666010a14d925203690bad0f10 (patch) | |
tree | e8ea0e2c628e2ddab3b02dd703a0f6dd31aa8ade /server/sonar-web/src/main/js/helpers | |
parent | 7853e9f613ae662e17a568bd70b3d65e5898ba80 (diff) | |
download | sonarqube-46d075adfb3c4a666010a14d925203690bad0f10.tar.gz sonarqube-46d075adfb3c4a666010a14d925203690bad0f10.zip |
Improve test coverage
Diffstat (limited to 'server/sonar-web/src/main/js/helpers')
-rw-r--r-- | server/sonar-web/src/main/js/helpers/__tests__/qualityGates-test.ts | 71 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/helpers/qualityGates.ts | 8 |
2 files changed, 74 insertions, 5 deletions
diff --git a/server/sonar-web/src/main/js/helpers/__tests__/qualityGates-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/qualityGates-test.ts new file mode 100644 index 00000000000..1b440f03edf --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/__tests__/qualityGates-test.ts @@ -0,0 +1,71 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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 { + isSameStatusConditionList, + extractStatusConditionsFromProjectStatus +} from '../qualityGates'; +import { mockQualityGateStatusCondition, mockQualityGateProjectStatus } from '../testMocks'; + +describe('extractStatusConditionsFromProjectStatus', () => { + it('should correclty extract the conditions for the project status', () => { + expect(extractStatusConditionsFromProjectStatus(mockQualityGateProjectStatus())).toEqual([ + { + actual: '0', + error: '1.0', + level: 'OK', + metric: 'new_bugs', + op: 'GT', + period: 1 + } + ]); + }); +}); + +describe('isSameStatusConditionList', () => { + it('should correctly return true if the conditions are the same', () => { + expect(isSameStatusConditionList()).toBe(true); + expect(isSameStatusConditionList([], [])).toBe(true); + expect( + isSameStatusConditionList( + [mockQualityGateStatusCondition()], + [mockQualityGateStatusCondition()] + ) + ).toBe(true); + }); + + it('should correctly return false if any condition is different', () => { + expect(isSameStatusConditionList([mockQualityGateStatusCondition()])).toBe(false); + expect(isSameStatusConditionList(undefined, [mockQualityGateStatusCondition()])).toBe(false); + expect(isSameStatusConditionList([], [mockQualityGateStatusCondition()])).toBe(false); + expect(isSameStatusConditionList([mockQualityGateStatusCondition()], [])).toBe(false); + expect( + isSameStatusConditionList( + [mockQualityGateStatusCondition({ metric: 'foo' })], + [mockQualityGateStatusCondition({ metric: 'bar' })] + ) + ).toBe(false); + expect( + isSameStatusConditionList( + [mockQualityGateStatusCondition({ metric: 'foo', level: '2.0' })], + [mockQualityGateStatusCondition({ metric: 'foo', level: '1.0' })] + ) + ).toBe(false); + }); +}); diff --git a/server/sonar-web/src/main/js/helpers/qualityGates.ts b/server/sonar-web/src/main/js/helpers/qualityGates.ts index 5dbb8a257b1..090647a8781 100644 --- a/server/sonar-web/src/main/js/helpers/qualityGates.ts +++ b/server/sonar-web/src/main/js/helpers/qualityGates.ts @@ -34,12 +34,10 @@ export function extractStatusConditionsFromProjectStatus( } export function isSameStatusConditionList( - conditions?: T.QualityGateStatusCondition[], - prevConditions?: T.QualityGateStatusCondition[] + conditions: T.QualityGateStatusCondition[] = [], + prevConditions: T.QualityGateStatusCondition[] = [] ): boolean { - if (conditions === undefined || prevConditions === undefined) { - return !(prevConditions || conditions); - } else if (conditions.length !== prevConditions.length) { + if (conditions.length !== prevConditions.length) { return false; } else { const filtered = conditions.filter(c1 => { |