Commit c8ad69ee authored by Dave Pisek's avatar Dave Pisek

Change summary text copy for license-compliance MR widget

This commit adds additional information to the summary text if the
report contains blacklisted licenses.

It also contains a small refactor to related specs.
parent 8d02faa1
......@@ -120,6 +120,7 @@ export default {
data-qa-selector="license_report_widget"
>
<template #success>
<div class="pr-3">
{{ licenseSummaryText }}
<gl-link
v-if="reportContainsBlacklistedLicense && securityApprovalsHelpPagePath"
......@@ -129,6 +130,7 @@ export default {
>
<icon :size="12" name="question" />
</gl-link>
</div>
</template>
<div v-if="showActionButtons" slot="actionButtons" class="append-right-default">
<a
......
......@@ -33,8 +33,8 @@ export const licenseSummaryText = (state, getters) => {
if (!baseReportHasLicenses) {
return getters.reportContainsBlacklistedLicense
? n__(
'LicenseCompliance|License Compliance detected %d license for the source branch only; approval required',
'LicenseCompliance|License Compliance detected %d licenses for the source branch only; approval required',
'LicenseCompliance|License Compliance detected %d license and policy violation for the source branch only; approval required',
'LicenseCompliance|License Compliance detected %d licenses and policy violations for the source branch only; approval required',
licenseReportLength,
)
: n__(
......@@ -46,8 +46,8 @@ export const licenseSummaryText = (state, getters) => {
return getters.reportContainsBlacklistedLicense
? n__(
'LicenseCompliance|License Compliance detected %d new license; approval required',
'LicenseCompliance|License Compliance detected %d new licenses; approval required',
'LicenseCompliance|License Compliance detected %d new license and policy violation; approval required',
'LicenseCompliance|License Compliance detected %d new licenses and policy violations; approval required',
licenseReportLength,
)
: n__(
......
---
title: Change summary text copy for license-compliance MR widget
merge_request: 28732
author:
type: changed
......@@ -120,83 +120,51 @@ describe('getters', () => {
);
});
it('should be `License Compliance detected no new licenses`, if the report is empty', () => {
const mockGetters = { licenseReport: [] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License Compliance detected no new licenses',
);
});
it('should be `License Compliance detected 1 new license`, if the report has one element', () => {
const mockGetters = { licenseReport: [licenseReportMock[0]] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License Compliance detected 1 new license',
);
});
it('should be `License Compliance detected 2 new licenses`, if the report has two elements', () => {
const mockGetters = { licenseReport: [licenseReportMock[0], licenseReportMock[0]] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License Compliance detected 2 new licenses',
);
});
it('should be `License Compliance detected 2 new licenses; approval required`, if the report has two elements and including some blacklisted', () => {
it.each`
givenLicenseReport | givenReportContainsBlacklistedLicense | expectedSummaryText
${[]} | ${false} | ${'License Compliance detected no new licenses'}
${[licenseReportMock[0]]} | ${false} | ${'License Compliance detected 1 new license'}
${[licenseReportMock[0], licenseReportMock[0]]} | ${false} | ${'License Compliance detected 2 new licenses'}
${[licenseReportMock[0]]} | ${true} | ${'License Compliance detected 1 new license and policy violation; approval required'}
${[licenseReportMock[0], licenseReportMock[0]]} | ${true} | ${'License Compliance detected 2 new licenses and policy violations; approval required'}
`(
`should show "$expectedSummaryText" if the report contains $givenLicenseReport.length license(s) and contains blacklisted licenses is: $givenReportContainsBlacklistedLicense`,
({ givenLicenseReport, givenReportContainsBlacklistedLicense, expectedSummaryText }) => {
const mockGetters = {
licenseReport: [licenseReportMock[0], licenseReportMock[0]],
reportContainsBlacklistedLicense: true,
licenseReport: givenLicenseReport,
reportContainsBlacklistedLicense: givenReportContainsBlacklistedLicense,
};
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License Compliance detected 2 new licenses; approval required',
expect(getters.licenseSummaryText(state, mockGetters)).toBe(expectedSummaryText);
},
);
});
});
describe('when there are no licences on the BASE', () => {
describe('when there are no licenses on the BASE', () => {
beforeEach(() => {
state = createState();
});
it('should be `License Compliance detected no licenses for the source branch only` with no new licences', () => {
const mockGetters = { licenseReport: [] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License Compliance detected no licenses for the source branch only',
);
});
it('should be `License Compliance detected 1 license for the source branch only` with one new licence', () => {
const mockGetters = { licenseReport: [licenseReportMock[0]] };
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License Compliance detected 1 license for the source branch only',
);
});
it('should be `License Compliance 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 Compliance detected 2 licenses for the source branch only',
);
});
it('should be `License Compliance detected 2 licenses for the source branch only; approval required` with two new licences including some blacklisted', () => {
it.each`
givenLicenseReport | givenReportContainsBlacklistedLicense | expectedSummaryText
${[]} | ${false} | ${'License Compliance detected no licenses for the source branch only'}
${[licenseReportMock[0]]} | ${false} | ${'License Compliance detected 1 license for the source branch only'}
${[licenseReportMock[0], licenseReportMock[0]]} | ${false} | ${'License Compliance detected 2 licenses for the source branch only'}
${[licenseReportMock[0]]} | ${true} | ${'License Compliance detected 1 license and policy violation for the source branch only; approval required'}
${[licenseReportMock[0], licenseReportMock[0]]} | ${true} | ${'License Compliance detected 2 licenses and policy violations for the source branch only; approval required'}
`(
`should show "$expectedSummaryText" if the report contains $givenLicenseReport.length license(s) and contains blacklisted licenses is: $givenReportContainsBlacklistedLicense`,
({ givenLicenseReport, givenReportContainsBlacklistedLicense, expectedSummaryText }) => {
const mockGetters = {
licenseReport: [licenseReportMock[0], licenseReportMock[0]],
reportContainsBlacklistedLicense: true,
licenseReport: givenLicenseReport,
reportContainsBlacklistedLicense: givenReportContainsBlacklistedLicense,
};
expect(getters.licenseSummaryText(state, mockGetters)).toBe(
'License Compliance detected 2 licenses for the source branch only; approval required',
expect(getters.licenseSummaryText(state, mockGetters)).toBe(expectedSummaryText);
},
);
});
});
});
describe('reportContainsBlacklistedLicense', () => {
it('should be false if the report does not contain blacklisted licenses', () => {
......
......@@ -11878,13 +11878,13 @@ msgstr ""
msgid "LicenseCompliance|License Compliance"
msgstr ""
msgid "LicenseCompliance|License Compliance detected %d license for the source branch only"
msgid_plural "LicenseCompliance|License Compliance detected %d licenses for the source branch only"
msgid "LicenseCompliance|License Compliance detected %d license and policy violation for the source branch only; approval required"
msgid_plural "LicenseCompliance|License Compliance detected %d licenses and policy violations for the source branch only; approval required"
msgstr[0] ""
msgstr[1] ""
msgid "LicenseCompliance|License Compliance detected %d license for the source branch only; approval required"
msgid_plural "LicenseCompliance|License Compliance detected %d licenses for the source branch only; approval required"
msgid "LicenseCompliance|License Compliance detected %d license for the source branch only"
msgid_plural "LicenseCompliance|License Compliance detected %d licenses for the source branch only"
msgstr[0] ""
msgstr[1] ""
......@@ -11893,8 +11893,8 @@ msgid_plural "LicenseCompliance|License Compliance detected %d new licenses"
msgstr[0] ""
msgstr[1] ""
msgid "LicenseCompliance|License Compliance detected %d new license; approval required"
msgid_plural "LicenseCompliance|License Compliance detected %d new licenses; approval required"
msgid "LicenseCompliance|License Compliance detected %d new license and policy violation; approval required"
msgid_plural "LicenseCompliance|License Compliance detected %d new licenses and policy violations; approval required"
msgstr[0] ""
msgstr[1] ""
......
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