aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2018-11-08 17:01:46 +0100
committersonartech <sonartech@sonarsource.com>2018-11-12 10:47:56 +0100
commit4a7f571a8550ad250b4631a033682fed422831d7 (patch)
tree67faec68cf2c2283e5cfc239ebfd07e982484667
parent62b681e9f6039e656d88b190c0488911bf328d6d (diff)
downloadsonarqube-4a7f571a8550ad250b4631a033682fed422831d7.tar.gz
sonarqube-4a7f571a8550ad250b4631a033682fed422831d7.zip
SONARCLOUD-45 Fix measures of featured projects
-rw-r--r--server/sonar-web/src/main/js/apps/about/sonarcloud/components/FeaturedProjects.tsx6
-rw-r--r--server/sonar-web/src/main/js/apps/about/sonarcloud/components/__mocks__/react-countup.tsx26
-rw-r--r--server/sonar-web/src/main/js/apps/about/sonarcloud/components/__tests__/FeaturedProjects-test.tsx7
-rw-r--r--server/sonar-web/src/main/js/apps/about/sonarcloud/components/__tests__/__snapshots__/FeaturedProjects-test.tsx.snap55
4 files changed, 86 insertions, 8 deletions
diff --git a/server/sonar-web/src/main/js/apps/about/sonarcloud/components/FeaturedProjects.tsx b/server/sonar-web/src/main/js/apps/about/sonarcloud/components/FeaturedProjects.tsx
index 7dbcd7ec7aa..e64f1d130bf 100644
--- a/server/sonar-web/src/main/js/apps/about/sonarcloud/components/FeaturedProjects.tsx
+++ b/server/sonar-web/src/main/js/apps/about/sonarcloud/components/FeaturedProjects.tsx
@@ -280,9 +280,9 @@ interface ProjectIssues {
}
export function ProjectIssues({ metric, metricKey, ratingMetric, viewable }: ProjectIssues) {
- const formattedString = formatMeasure(metric, 'SHORT_INT');
- const value = parseFloat(formattedString.slice(0, -1));
- const suffix = formattedString.substr(-1);
+ const formattedValue = formatMeasure(metric, 'SHORT_INT');
+ const value = parseFloat(formattedValue);
+ const suffix = formattedValue.replace(value.toString(), '');
return (
<li>
<span>{getMetricName(metricKey)}</span>
diff --git a/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__mocks__/react-countup.tsx b/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__mocks__/react-countup.tsx
new file mode 100644
index 00000000000..bc397d458b5
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__mocks__/react-countup.tsx
@@ -0,0 +1,26 @@
+/*
+ * 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 * as React from 'react';
+
+export default class CountUp extends React.Component<any> {
+ render() {
+ return <div />;
+ }
+}
diff --git a/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__tests__/FeaturedProjects-test.tsx b/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__tests__/FeaturedProjects-test.tsx
index 6cb8946abeb..456fd9bec61 100644
--- a/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__tests__/FeaturedProjects-test.tsx
+++ b/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__tests__/FeaturedProjects-test.tsx
@@ -117,13 +117,16 @@ const PROJECTS = [
it('should render ProjectIssues correctly', () => {
expect(
- shallow(<ProjectIssues metric={15} metricKey="foo" ratingMetric={20} viewable={false} />)
+ shallow(<ProjectIssues metric={5} metricKey="foo" ratingMetric={20} viewable={true} />)
+ ).toMatchSnapshot();
+ expect(
+ shallow(<ProjectIssues metric={15000} metricKey="foo" ratingMetric={20} viewable={true} />)
).toMatchSnapshot();
});
it('should render ProjectCard correctly', () => {
expect(
- shallow(<ProjectCard order={1} project={PROJECTS[0]} viewable={false} />)
+ shallow(<ProjectCard order={1} project={PROJECTS[0]} viewable={true} />)
).toMatchSnapshot();
});
diff --git a/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__tests__/__snapshots__/FeaturedProjects-test.tsx.snap b/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__tests__/__snapshots__/FeaturedProjects-test.tsx.snap
index 36862944aad..3569ab43a29 100644
--- a/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__tests__/__snapshots__/FeaturedProjects-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/about/sonarcloud/components/__tests__/__snapshots__/FeaturedProjects-test.tsx.snap
@@ -48,25 +48,35 @@ exports[`should render ProjectCard correctly 1`] = `
metric={0}
metricKey="bugs"
ratingMetric={1}
- viewable={false}
+ viewable={true}
/>
<ProjectIssues
metric={0}
metricKey="vulnerabilities"
ratingMetric={1}
- viewable={false}
+ viewable={true}
/>
<ProjectIssues
metric={7}
metricKey="code_smells"
ratingMetric={1}
- viewable={false}
+ viewable={true}
/>
<li>
<span>
overview.metric.coverage
</span>
<div>
+ <CountUp
+ decimal="."
+ decimals={1}
+ delay={0}
+ duration={4}
+ end={9.7}
+ suffix="%"
+ >
+ <Component />
+ </CountUp>
<CoverageRating
value={9.7}
/>
@@ -77,6 +87,16 @@ exports[`should render ProjectCard correctly 1`] = `
overview.metric.duplications
</span>
<div>
+ <CountUp
+ decimal="."
+ decimals={1}
+ delay={0}
+ duration={4}
+ end={56.2}
+ suffix="%"
+ >
+ <Component />
+ </CountUp>
<DuplicationsRating
value={56.2}
/>
@@ -104,6 +124,35 @@ exports[`should render ProjectIssues correctly 1`] = `
overview.metric.foo
</span>
<div>
+ <CountUp
+ delay={0}
+ duration={4}
+ end={5}
+ suffix=""
+ >
+ <Component />
+ </CountUp>
+ <Rating
+ value={20}
+ />
+ </div>
+</li>
+`;
+
+exports[`should render ProjectIssues correctly 2`] = `
+<li>
+ <span>
+ overview.metric.foo
+ </span>
+ <div>
+ <CountUp
+ delay={0}
+ duration={4}
+ end={15}
+ suffix="short_number_suffix.k"
+ >
+ <Component />
+ </CountUp>
<Rating
value={20}
/>