diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-02-01 11:42:47 +0100 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-02-01 14:12:18 +0100 |
commit | 6c63fd513de47d944d76fdfd1979a5e90ebb8a2c (patch) | |
tree | 6c9c21ca67dc02dced53210b34a242986e434cbd /server | |
parent | e737a37b28a2504aa1a6387606841afd776f2fef (diff) | |
download | sonarqube-6c63fd513de47d944d76fdfd1979a5e90ebb8a2c.tar.gz sonarqube-6c63fd513de47d944d76fdfd1979a5e90ebb8a2c.zip |
fix rendering of secondary measures on the Measures page
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-web/src/main/js/apps/component-measures/drilldown/MeasureCell.js | 19 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/component-measures/drilldown/__tests__/MeasureCell-test.js | 47 |
2 files changed, 58 insertions, 8 deletions
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 ( <td className="thin nowrap text-right"> <span id={`component-measures-component-measure-${component.key}-${metric.key}`}> - <Measure - value={isDiffMetric(metric.key) ? component.leak : component.value} - metricKey={metric.key} - metricType={metric.type} - /> + <Measure value={value} metricKey={metric.key} metricType={metric.type} /> </span> </td> ); 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(<MeasureCell {...props} />) + .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'); + }); +}); |