Commit fd430007 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch '6589-full-list-of-licences' into 'master'

Resolve "Show the full list of licenses in the MR widget if no report is available in the target branch"

Closes #6589

See merge request gitlab-org/gitlab-ee!6720
parents 278d3943 b7c28ee9
...@@ -40,7 +40,7 @@ export default { ...@@ -40,7 +40,7 @@ export default {
}, },
shouldRenderLicenseReport() { shouldRenderLicenseReport() {
const { licenseManagement } = this.mr; const { licenseManagement } = this.mr;
return licenseManagement && licenseManagement.head_path && licenseManagement.base_path; return licenseManagement && licenseManagement.head_path;
}, },
hasCodequalityIssues() { hasCodequalityIssues() {
return ( return (
......
...@@ -7,6 +7,12 @@ export const licenseReport = state => ...@@ -7,6 +7,12 @@ export const licenseReport = state =>
parseLicenseReportMetrics(state.headReport, state.baseReport, state.managedLicenses); parseLicenseReportMetrics(state.headReport, state.baseReport, state.managedLicenses);
export const licenseSummaryText = (state, getters) => { export const licenseSummaryText = (state, getters) => {
const hasReportItems = getters.licenseReport && getters.licenseReport.length;
const baseReportHasLicenses =
state.baseReport
&& state.baseReport.licenses
&& state.baseReport.licenses.length;
if (getters.isLoading) { if (getters.isLoading) {
return sprintf(s__('ciReport|Loading %{reportName} report'), { return sprintf(s__('ciReport|Loading %{reportName} report'), {
reportName: s__('license management'), reportName: s__('license management'),
...@@ -19,7 +25,15 @@ export const licenseSummaryText = (state, getters) => { ...@@ -19,7 +25,15 @@ export const licenseSummaryText = (state, getters) => {
}); });
} }
if (getters.licenseReport && getters.licenseReport.length > 0) { if (hasReportItems) {
if (!baseReportHasLicenses) {
return n__(
'ciReport|License management detected %d license for the source branch only',
'ciReport|License management detected %d licenses for the source branch only',
getters.licenseReport.length,
);
}
return n__( return n__(
'ciReport|License management detected %d new license', 'ciReport|License management detected %d new license',
'ciReport|License management detected %d new licenses', 'ciReport|License management detected %d new licenses',
...@@ -27,6 +41,10 @@ export const licenseSummaryText = (state, getters) => { ...@@ -27,6 +41,10 @@ export const licenseSummaryText = (state, getters) => {
); );
} }
if (!baseReportHasLicenses) {
return s__('ciReport|License management detected no licenses for the source branch only');
}
return s__('ciReport|License management detected no new licenses'); return s__('ciReport|License management detected no new licenses');
}; };
......
---
title: Shows license reports when there are no reports in the source branch
merge_request: 6720
author:
type: changed
...@@ -47,44 +47,76 @@ describe('getters', () => { ...@@ -47,44 +47,76 @@ describe('getters', () => {
}); });
describe('licenseSummaryText', () => { describe('licenseSummaryText', () => {
const state = { describe('when licenses exist on both the HEAD and the BASE', () => {
loadLicenseReportError: null, const state = {
}; loadLicenseReportError: null,
headReport: licenseHeadIssues,
it('should be `Loading license management report` text if isLoading', () => { baseReport: licenseBaseIssues,
const mockGetters = {}; };
mockGetters.isLoading = true;
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'Loading license management report',
);
});
it('should be `Failed to load license management report` text if an error has happened', () => { it('should be `Loading license management report` text if isLoading', () => {
const mockGetters = {}; const mockGetters = {};
expect( mockGetters.isLoading = true;
getters.licenseSummaryText({ loadLicenseReportError: new Error('Test') }, mockGetters), expect(getters.licenseSummaryText(state, mockGetters)).toBe(
).toBe('Failed to load license management report'); 'Loading license management report',
}); );
});
it('should be `License management detected no new licenses`, if the report is empty', () => { it('should be `Failed to load license management report` text if an error has happened', () => {
const mockGetters = { licenseReport: [] }; const mockGetters = {};
expect(getters.licenseSummaryText(state, mockGetters)).toBe( expect(
'License management detected no new licenses', getters.licenseSummaryText({ loadLicenseReportError: new Error('Test') }, mockGetters),
); ).toBe('Failed to load license management report');
}); });
it('should be `License management detected 1 new license`, if the report has one element', () => { it('should be `License management detected no new licenses`, if the report is empty', () => {
const mockGetters = { licenseReport: [licenseReportMock[0]] }; const mockGetters = { licenseReport: [] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe( expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License management detected 1 new license', 'License management detected no new licenses',
); );
});
it('should be `License management detected 1 new license`, if the report has one element', () => {
const mockGetters = { licenseReport: [licenseReportMock[0]] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License management detected 1 new license',
);
});
it('should be `License management detected 2 new licenses`, if the report has two elements', () => {
const mockGetters = { licenseReport: [licenseReportMock[0], licenseReportMock[0]] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License management detected 2 new licenses',
);
});
}); });
it('should be `License management detected 2 new licenses`, if the report has two elements', () => { describe('when there are no licences on the BASE', () => {
const mockGetters = { licenseReport: [licenseReportMock[0], licenseReportMock[0]] }; const state = { baseReport: {} };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License management detected 2 new licenses', it('should be `License management detected no licenses for the source branch only` with no new licences', () => {
); const mockGetters = { licenseReport: [] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License management detected no licenses for the source branch only',
);
});
it('should be `License management detected 1 license for the source branch only` with one new licence', () => {
const mockGetters = { licenseReport: [licenseReportMock[0]] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License management detected 1 license for the source branch only',
);
});
it('should be `License management detected 2 licenses for the source branch only` with two new licences', () => {
const mockGetters = { licenseReport: [licenseReportMock[0], licenseReportMock[0]] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License management detected 2 licenses for the source branch only',
);
});
}); });
}); });
}); });
...@@ -7433,6 +7433,9 @@ msgstr "" ...@@ -7433,6 +7433,9 @@ msgstr ""
msgid "ciReport|Learn more about whitelisting" msgid "ciReport|Learn more about whitelisting"
msgstr "" msgstr ""
msgid "ciReport|License management detected no licenses for the source branch only"
msgstr ""
msgid "ciReport|License management detected no new licenses" msgid "ciReport|License management detected no new licenses"
msgstr "" msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment