From: Wouter Admiraal Date: Mon, 17 Jun 2019 15:20:40 +0000 (+0200) Subject: SONAR-11937 Update empty main branch message X-Git-Tag: 8.0~532 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4734af329d86349f42343786dac28874d41168c1;p=sonarqube.git SONAR-11937 Update empty main branch message --- diff --git a/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.tsx b/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.tsx index be4107412cc..b5bc358dbdf 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/OverviewApp.tsx @@ -43,11 +43,13 @@ import { import { isSameBranchLike, getBranchLikeQuery, - isLongLivingBranch + isLongLivingBranch, + isMainBranch, + getBranchLikeDisplayName } from '../../../helpers/branches'; import { fetchMetrics } from '../../../store/rootActions'; import { getMetrics, Store } from '../../../store/rootReducer'; -import { translate } from '../../../helpers/l10n'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; import '../styles.css'; interface Props { @@ -160,18 +162,61 @@ export class OverviewApp extends React.PureComponent { }; renderEmpty = () => { - const { component } = this.props; + const { branchLike, component } = this.props; const isApp = component.qualifier === 'APP'; + + /* eslint-disable no-lonely-if */ + // - Is App + // - No measures, OR measures, but no projects => empty + // - Else => no lines of code + // - Else + // - No measures => empty + // - Main branch? + // - LLB? + // - No branch info? + // - Measures, but no ncloc (checked in isEmpty()) => no lines of code + // - Main branch? + // - LLB? + // - No branch info? + let title; + if (isApp) { + if ( + this.state.measures === undefined || + this.state.measures.find(measure => measure.metric.key === 'projects') === undefined + ) { + title = translate('portfolio.app.empty'); + } else { + title = translate('portfolio.app.no_lines_of_code'); + } + } else { + if (this.state.measures === undefined || this.state.measures.length === 0) { + if (isMainBranch(branchLike)) { + title = translate('overview.project.main_branch_empty'); + } else if (branchLike !== undefined) { + title = translateWithParameters( + 'overview.project.branch_X_empty', + getBranchLikeDisplayName(branchLike) + ); + } else { + title = translate('overview.project.empty'); + } + } else { + if (isMainBranch(branchLike)) { + title = translate('overview.project.main_branch_no_lines_of_code'); + } else if (branchLike !== undefined) { + title = translateWithParameters( + 'overview.project.branch_X_no_lines_of_code', + getBranchLikeDisplayName(branchLike) + ); + } else { + title = translate('overview.project.no_lines_of_code'); + } + } + } + /* eslint-enable no-lonely-if */ return (
-

- {!this.state.measures || - !this.state.measures.find(measure => measure.metric.key === 'projects') - ? translate(isApp ? 'portfolio.app.empty' : 'overview.project.empty') - : translate( - isApp ? 'portfolio.app.no_lines_of_code' : 'overview.project.no_lines_of_code' - )} -

+

{title}

); }; diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/OverviewApp-test.tsx b/server/sonar-web/src/main/js/apps/overview/components/__tests__/OverviewApp-test.tsx index c107902beb2..796edf8c9ce 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/OverviewApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/OverviewApp-test.tsx @@ -26,7 +26,8 @@ import { mockMainBranch, mockComponent, mockMetric, - mockMeasure + mockMeasure, + mockLongLivingBranch } from '../../../../helpers/testMocks'; import { waitAndUpdate } from '../../../../helpers/testUtils'; @@ -70,18 +71,75 @@ it('should render correctly', async () => { expect(getAllTimeMachineData).toBeCalled(); }); -it('should render correctly if no measures are found', async () => { +it('should show the correct message if the application is empty or has no lines of code', async () => { (getMeasuresAndMeta as jest.Mock).mockResolvedValue({ component: { - measures: [mockMeasure({ metric: 'coverage' })], + measures: [mockMeasure({ metric: 'projects' })], name: 'foo' }, - metrics: [mockMetric()] + metrics: [mockMetric({ key: 'projects' })] }); - const wrapper = shallowRender(); + const wrapper = shallowRender({ + component: mockComponent({ key: 'foo', name: 'foo', qualifier: 'APP' }) + }); await waitAndUpdate(wrapper); - expect(wrapper).toMatchSnapshot(); + expect(wrapper.find('h3').text()).toBe('portfolio.app.no_lines_of_code'); + + (getMeasuresAndMeta as jest.Mock).mockResolvedValue({ + component: { + measures: [], + name: 'bar' + }, + metrics: [] + }); + wrapper.setProps({ component: mockComponent({ key: 'bar', name: 'bar', qualifier: 'APP' }) }); + await waitAndUpdate(wrapper); + expect(wrapper.find('h3').text()).toBe('portfolio.app.empty'); +}); + +it('should show the correct message if the project is empty', async () => { + (getMeasuresAndMeta as jest.Mock).mockResolvedValue({ + component: { + measures: [], + name: 'foo' + }, + metrics: [] + }); + const wrapper = shallowRender({ branchLike: mockMainBranch() }); + + await waitAndUpdate(wrapper); + expect(wrapper.find('h3').text()).toBe('overview.project.main_branch_empty'); + + wrapper.setProps({ branchLike: mockLongLivingBranch({ name: 'branch-foo' }) }); + await waitAndUpdate(wrapper); + expect(wrapper.find('h3').text()).toBe('overview.project.branch_X_empty.branch-foo'); + + wrapper.setProps({ branchLike: undefined }); + await waitAndUpdate(wrapper); + expect(wrapper.find('h3').text()).toBe('overview.project.empty'); +}); + +it('should show the correct message if the project has no lines of code', async () => { + (getMeasuresAndMeta as jest.Mock).mockResolvedValue({ + component: { + measures: [mockMeasure({ metric: 'bugs' })], + name: 'foo' + }, + metrics: [mockMetric({ key: 'bugs' })] + }); + const wrapper = shallowRender({ branchLike: mockMainBranch() }); + + await waitAndUpdate(wrapper); + expect(wrapper.find('h3').text()).toBe('overview.project.main_branch_no_lines_of_code'); + + wrapper.setProps({ branchLike: mockLongLivingBranch({ name: 'branch-foo' }) }); + await waitAndUpdate(wrapper); + expect(wrapper.find('h3').text()).toBe('overview.project.branch_X_no_lines_of_code.branch-foo'); + + wrapper.setProps({ branchLike: undefined }); + await waitAndUpdate(wrapper); + expect(wrapper.find('h3').text()).toBe('overview.project.no_lines_of_code'); }); function getMockHelpers() { diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/OverviewApp-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/OverviewApp-test.tsx.snap index b92c643ffa7..2ca949f0f7f 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/OverviewApp-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/OverviewApp-test.tsx.snap @@ -781,132 +781,3 @@ exports[`should render correctly 2`] = ` `; - -exports[`should render correctly if no measures are found 1`] = ` -
-
- -
-

- overview.project.empty -

-
-
- -
-
-
-`; diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverallMeasures.tsx b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverallMeasures.tsx index 4ca5a6793a4..5720f71393c 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverallMeasures.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardOverallMeasures.tsx @@ -40,7 +40,7 @@ export default function ProjectCardOverallMeasures({ measures }: Props) { const { ncloc } = measures; if (!ncloc) { - return
{translate('overview.project.empty')}
; + return
{translate('overview.project.main_branch_empty')}
; } return ( diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverallMeasures-test.tsx.snap b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverallMeasures-test.tsx.snap index 43bad2938ca..763be5cd1ca 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverallMeasures-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/__snapshots__/ProjectCardOverallMeasures-test.tsx.snap @@ -243,7 +243,7 @@ exports[`should render empty 1`] = `
- overview.project.empty + overview.project.main_branch_empty
`; diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 4bbe463e6f2..0264f73fad3 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2449,8 +2449,12 @@ overview.external_links=External Links overview.project_key.APP=Application Key overview.project_key.TRK=Project Key -overview.project.no_lines_of_code=This project as no lines of code. +overview.project.no_lines_of_code=This project has no lines of code. overview.project.empty=This project is empty. +overview.project.branch_X_no_lines_of_code=The "{0}" branch has no lines of code. +overview.project.branch_X_empty=The "{0}" branch of this project is empty. +overview.project.main_branch_no_lines_of_code=The main branch has no lines of code. +overview.project.main_branch_empty=The main branch of this project is empty. overview.metric.code_smells=Code Smells overview.metric.new_code_smells=New Code Smells