diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2019-04-16 14:08:02 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-04-16 20:20:58 +0200 |
commit | d9275526f557ad3822ba9706d8aa959b69c251f4 (patch) | |
tree | 02242c041e04e0924b470ca15153fcfb90391d60 | |
parent | 84b860c58a4bbddd8bbdb8af0839c2c53e568644 (diff) | |
download | sonarqube-d9275526f557ad3822ba9706d8aa959b69c251f4.tar.gz sonarqube-d9275526f557ad3822ba9706d8aa959b69c251f4.zip |
SONARCLOUD-593 Display correctly when coverage is missing in homepage data
4 files changed, 46 insertions, 19 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 c5c617ade03..da10093def3 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 @@ -215,24 +215,28 @@ export function ProjectCard({ project, order, viewable }: ProjectCardProps) { /> <li> <span>{getMetricName('coverage')}</span> - <div> - {viewable && ( - <CountUp - decimal="." - decimals={1} - delay={0} - duration={4} - end={project.coverage} - suffix="%"> - {(data: { countUpRef?: React.RefObject<HTMLHeadingElement> }) => ( - <h6 className="display-inline-block big-spacer-right" ref={data.countUpRef}> - 0 - </h6> - )} - </CountUp> - )} - <CoverageRating value={project.coverage} /> - </div> + {project.coverage !== undefined ? ( + <div> + {viewable && ( + <CountUp + decimal="." + decimals={1} + delay={0} + duration={4} + end={project.coverage} + suffix="%"> + {(data: { countUpRef?: React.RefObject<HTMLHeadingElement> }) => ( + <h6 className="display-inline-block big-spacer-right" ref={data.countUpRef}> + 0 + </h6> + )} + </CountUp> + )} + <CoverageRating value={project.coverage} /> + </div> + ) : ( + <span className="huge little-spacer-right">—</span> + )} </li> <li> <span>{getMetricName('duplications')}</span> 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 5a643e07eb4..03d67846cf1 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 @@ -130,6 +130,16 @@ it('should render ProjectCard correctly', () => { ).toMatchSnapshot(); }); +it('should render ProjectCard correctly when there is no coverage', () => { + expect( + shallow( + <ProjectCard order={1} project={{ ...PROJECTS[0], coverage: undefined }} viewable={true} /> + ) + .find('li') + .first() + ).toMatchSnapshot(); +}); + it('should render correctly', () => { const wrapper = shallow(<FeaturedProjects projects={PROJECTS} />); expect(wrapper).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 a3ebf4ed16c..ec7a093fda3 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 @@ -115,6 +115,19 @@ exports[`should render ProjectCard correctly 1`] = ` </div> `; +exports[`should render ProjectCard correctly when there is no coverage 1`] = ` +<li> + <span> + overview.metric.coverage + </span> + <span + className="huge little-spacer-right" + > + — + </span> +</li> +`; + exports[`should render ProjectIssues correctly 1`] = ` <li> <span> diff --git a/server/sonar-web/src/main/js/apps/about/sonarcloud/utils.ts b/server/sonar-web/src/main/js/apps/about/sonarcloud/utils.ts index 7f4301429d9..8dbec41e9b3 100644 --- a/server/sonar-web/src/main/js/apps/about/sonarcloud/utils.ts +++ b/server/sonar-web/src/main/js/apps/about/sonarcloud/utils.ts @@ -27,7 +27,7 @@ export interface FeaturedProject { name: string; bugs: number; codeSmells: number; - coverage: number; + coverage?: number; duplications: number; gateStatus: string; languages: string[]; |