Commit e54e741d authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'jnnkl-pipeline-license-no-url-fix' into 'master'

Bugfix for licenses without an url

See merge request gitlab-org/gitlab!56534
parents 4ca7538c 23ca5a0c
...@@ -25,7 +25,8 @@ export default { ...@@ -25,7 +25,8 @@ export default {
<template> <template>
<div class="report-block-info license-item"> <div class="report-block-info license-item">
<gl-link :href="issue.url" target="_blank">{{ issue.name }}</gl-link> <gl-link v-if="issue.url" :href="issue.url" target="_blank">{{ issue.name }}</gl-link>
<span v-else data-testid="license-copy">{{ issue.name }}</span>
<license-packages v-if="hasPackages" :packages="issue.packages" class="text-secondary" /> <license-packages v-if="hasPackages" :packages="issue.packages" class="text-secondary" />
</div> </div>
</template> </template>
---
title: Fix for licenses without an url in license issue body
merge_request: 56534
author:
type: changed
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
exports[`License Report MR Widget report section report body should render correctly 1`] = ` exports[`License Report MR Widget report section report body should render correctly 1`] = `
<smart-virtual-list-stub <smart-virtual-list-stub
class="report-block-container" class="report-block-container"
length="1" length="2"
remain="20" remain="20"
rtag="div" rtag="div"
size="26" size="26"
......
import Vue from 'vue'; import { GlLink } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import LicenseIssueBody from 'ee/vue_shared/license_compliance/components/license_issue_body.vue'; import LicenseIssueBody from 'ee/vue_shared/license_compliance/components/license_issue_body.vue';
import createStore from 'ee/vue_shared/license_compliance/store'; import LicensePackages from 'ee/vue_shared/license_compliance/components/license_packages.vue';
import { trimText } from 'helpers/text_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import { licenseReport } from '../mock_data'; import { licenseReport } from '../mock_data';
describe('LicenseIssueBody', () => { describe('LicenseIssueBody', () => {
const issue = licenseReport[0]; let wrapper;
const Component = Vue.extend(LicenseIssueBody);
let vm; const findLicenseIssueBody = () => wrapper.findComponent(LicenseIssueBody);
let store; const findLicensePackages = () => wrapper.findComponent(LicensePackages);
const findGlLink = () => wrapper.find(GlLink);
const findText = () => wrapper.find('[data-testid="license-copy"]');
const createComponent = (props = {}) => {
wrapper = extendedWrapper(
shallowMount(LicenseIssueBody, {
propsData: {
...props,
},
}),
);
};
beforeEach(() => { beforeEach(() => {
store = createStore(); createComponent({ issue: licenseReport[0] });
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
}); });
describe('template', () => { describe('on load', () => {
beforeEach(() => { it('renders license issue body', () => {
vm = mountComponentWithStore(Component, { props: { issue }, store }); expect(findLicenseIssueBody().exists()).toBe(true);
}); });
it('renders component container element with class `license-item`', () => { it('renders packages list', () => {
expect(vm.$el.classList.contains('license-item')).toBe(true); expect(findLicensePackages().exists()).toBe(true);
}); });
});
describe('when issue url is defined', () => {
it('renders link to view license', () => { it('renders link to view license', () => {
const linkEl = vm.$el.querySelector('.license-item > a'); const link = findGlLink();
const text = findText();
expect(linkEl).not.toBeNull(); expect(link.text()).toBe(licenseReport[0].name);
expect(linkEl.innerText.trim()).toBe(issue.name); expect(link.attributes('href')).toBe(licenseReport[0].url);
expect(text.exists()).toBe(false);
}); });
});
it('renders packages list', () => { describe('when issue url is undefined', () => {
const packagesEl = vm.$el.querySelector('.license-packages'); beforeEach(() => {
createComponent({ issue: licenseReport[1] });
});
it('renders text to view license', () => {
const link = findGlLink();
const text = findText();
expect(packagesEl).not.toBeNull(); expect(text.text()).toBe(licenseReport[1].name);
expect(trimText(packagesEl.innerText)).toBe('Used by pg, puma, foo, and 2 more'); expect(link.exists()).toBe(false);
}); });
}); });
...@@ -49,14 +71,12 @@ describe('LicenseIssueBody', () => { ...@@ -49,14 +71,12 @@ describe('LicenseIssueBody', () => {
const issueWithoutPackages = licenseReport[0]; const issueWithoutPackages = licenseReport[0];
issueWithoutPackages.packages = []; issueWithoutPackages.packages = [];
vm = mountComponentWithStore(Component, { props: { issue: issueWithoutPackages }, store }); createComponent({ issue: issueWithoutPackages });
}); });
it('does not render packages list', () => { it('does not render packages list', () => {
const packagesEl = vm.$el.querySelector('.license-packages'); const packages = findLicensePackages();
expect(packages.exists()).toBe(false);
expect(packagesEl).toBeNull();
vm.$destroy();
}); });
}); });
}); });
...@@ -56,6 +56,47 @@ export const licenseReport = [ ...@@ -56,6 +56,47 @@ export const licenseReport = [
}, },
], ],
}, },
{
name: 'another New BSD',
count: 5,
packages: [
{
name: 'pg',
url: 'https://bitbucket.org/ged/ruby-pg',
description:
'Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/]',
paths: ['.'],
},
{
name: 'puma',
url: 'http://puma.io',
description:
'Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications',
paths: ['.'],
},
{
name: 'foo',
url: 'https://bitbucket.org/ged/ruby-pg',
description:
'Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/]',
paths: ['.'],
},
{
name: 'bar',
url: 'http://puma.io',
description:
'Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications',
paths: ['.'],
},
{
name: 'baz',
url: 'https://bitbucket.org/ged/ruby-pg',
description:
'Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/]',
paths: ['.'],
},
],
},
]; ];
export const generateReportGroup = ({ status = 'some-status', numberOfLicenses = 0 } = {}) => ({ export const generateReportGroup = ({ status = 'some-status', numberOfLicenses = 0 } = {}) => ({
......
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