From: Stas Vilchik Date: Thu, 1 Feb 2018 10:42:47 +0000 (+0100) Subject: fix rendering of secondary measures on the Measures page X-Git-Tag: 7.5~1748 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6c63fd513de47d944d76fdfd1979a5e90ebb8a2c;p=sonarqube.git fix rendering of secondary measures on the Measures page --- diff --git a/server/sonar-web/src/main/js/apps/component-measures/drilldown/MeasureCell.js b/server/sonar-web/src/main/js/apps/component-measures/drilldown/MeasureCell.js index 0934587ccf2..8e7d69452a7 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/drilldown/MeasureCell.js +++ b/server/sonar-web/src/main/js/apps/component-measures/drilldown/MeasureCell.js @@ -21,23 +21,26 @@ import React from 'react'; import Measure from '../../../components/measure/Measure'; import { isDiffMetric } from '../../../helpers/measures'; -/*:: import type { Component } from '../types'; */ +/*:: import type { ComponentEnhanced } from '../types'; */ +/*:: import type { MeasureEnhanced } from '../../../components/measure/types'; */ /*:: import type { Metric } from '../../../store/metrics/actions'; */ /*:: type Props = { - component: Component, + component: ComponentEnhanced, + measure?: MeasureEnhanced, metric: Metric }; */ -export default function MeasureCell({ component, metric } /*: Props */) { +export default function MeasureCell({ component, measure, metric } /*: Props */) { + const getValue = (item /*: { leak?: ?string; value?: string } */) => + isDiffMetric(metric.key) ? item.leak : item.value; + + const value = getValue(measure || component); + return ( - + ); diff --git a/server/sonar-web/src/main/js/apps/component-measures/drilldown/__tests__/MeasureCell-test.js b/server/sonar-web/src/main/js/apps/component-measures/drilldown/__tests__/MeasureCell-test.js new file mode 100644 index 00000000000..6897ed8a623 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/component-measures/drilldown/__tests__/MeasureCell-test.js @@ -0,0 +1,47 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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 React from 'react'; +import { shallow } from 'enzyme'; +import MeasureCell from '../MeasureCell'; + +describe('should correctly take the value', () => { + const renderAndTakeValue = props => + shallow() + .find('Measure') + .prop('value'); + + it('absolute value', () => { + const component = { value: '123' }; + const metric = { key: 'coverage' }; + const measure = { value: '567' }; + + expect(renderAndTakeValue({ component, metric })).toEqual('123'); + expect(renderAndTakeValue({ component, metric, measure })).toEqual('567'); + }); + + it('leak value', () => { + const component = { leak: '234' }; + const metric = { key: 'new_coverage' }; + const measure = { leak: '678' }; + + expect(renderAndTakeValue({ component, metric })).toEqual('234'); + expect(renderAndTakeValue({ component, metric, measure })).toEqual('678'); + }); +});