Commit b7c28ee9 authored by Sam Beckham's avatar Sam Beckham Committed by Filipa Lacerda

Resolve "Show the full list of licenses in the MR widget if no report is...

Resolve "Show the full list of licenses in the MR widget if no report is available in the target branch"
parent 278d3943
......@@ -40,7 +40,7 @@ export default {
},
shouldRenderLicenseReport() {
const { licenseManagement } = this.mr;
return licenseManagement && licenseManagement.head_path && licenseManagement.base_path;
return licenseManagement && licenseManagement.head_path;
},
hasCodequalityIssues() {
return (
......
......@@ -7,6 +7,12 @@ export const licenseReport = state =>
parseLicenseReportMetrics(state.headReport, state.baseReport, state.managedLicenses);
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) {
return sprintf(s__('ciReport|Loading %{reportName} report'), {
reportName: s__('license management'),
......@@ -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__(
'ciReport|License management detected %d new license',
'ciReport|License management detected %d new licenses',
......@@ -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');
};
......
---
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', () => {
});
describe('licenseSummaryText', () => {
const state = {
loadLicenseReportError: null,
};
it('should be `Loading license management report` text if isLoading', () => {
const mockGetters = {};
mockGetters.isLoading = true;
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'Loading license management report',
);
});
describe('when licenses exist on both the HEAD and the BASE', () => {
const state = {
loadLicenseReportError: null,
headReport: licenseHeadIssues,
baseReport: licenseBaseIssues,
};
it('should be `Failed to load license management report` text if an error has happened', () => {
const mockGetters = {};
expect(
getters.licenseSummaryText({ loadLicenseReportError: new Error('Test') }, mockGetters),
).toBe('Failed to load license management report');
});
it('should be `Loading license management report` text if isLoading', () => {
const mockGetters = {};
mockGetters.isLoading = true;
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'Loading license management report',
);
});
it('should be `License management detected no new licenses`, if the report is empty', () => {
const mockGetters = { licenseReport: [] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License management detected no new licenses',
);
});
it('should be `Failed to load license management report` text if an error has happened', () => {
const mockGetters = {};
expect(
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', () => {
const mockGetters = { licenseReport: [licenseReportMock[0]] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License management detected 1 new license',
);
it('should be `License management detected no new licenses`, if the report is empty', () => {
const mockGetters = { licenseReport: [] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'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', () => {
const mockGetters = { licenseReport: [licenseReportMock[0], licenseReportMock[0]] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License management detected 2 new licenses',
);
describe('when there are no licences on the BASE', () => {
const state = { baseReport: {} };
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 ""
msgid "ciReport|Learn more about whitelisting"
msgstr ""
msgid "ciReport|License management detected no licenses for the source branch only"
msgstr ""
msgid "ciReport|License management detected no new licenses"
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