]> source.dussan.org Git - sonarqube.git/commitdiff
fix rendering of secondary measures on the Measures page
authorStas Vilchik <stas.vilchik@sonarsource.com>
Thu, 1 Feb 2018 10:42:47 +0000 (11:42 +0100)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Thu, 1 Feb 2018 13:12:18 +0000 (14:12 +0100)
server/sonar-web/src/main/js/apps/component-measures/drilldown/MeasureCell.js
server/sonar-web/src/main/js/apps/component-measures/drilldown/__tests__/MeasureCell-test.js [new file with mode: 0644]

index 0934587ccf22151c4e34b44242decba2ffd6768d..8e7d69452a70fa151b88b2fb0a70961ecb2e4289 100644 (file)
 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 (file)
index 0000000..6897ed8
--- /dev/null
@@ -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');
+  });
+});