Commit 331c5d85 authored by Phil Hughes's avatar Phil Hughes

Merge branch '37999-spdx-dropdown' into 'master'

Pass SPDX licenses from backend to frontend

Closes #37999

See merge request gitlab-org/gitlab!36926
parents 71dd8e65 a5d2c222
...@@ -17,6 +17,7 @@ export default () => { ...@@ -17,6 +17,7 @@ export default () => {
settingsPath, settingsPath,
approvalsDocumentationPath, approvalsDocumentationPath,
lockedApprovalsRuleName, lockedApprovalsRuleName,
softwareLicenses,
} = el.dataset; } = el.dataset;
const storeSettings = { const storeSettings = {
...@@ -33,6 +34,8 @@ export default () => { ...@@ -33,6 +34,8 @@ export default () => {
store.dispatch('licenseManagement/setAPISettings', { store.dispatch('licenseManagement/setAPISettings', {
apiUrlManageLicenses: readLicensePoliciesEndpoint, apiUrlManageLicenses: readLicensePoliciesEndpoint,
}); });
store.dispatch('licenseManagement/setKnownLicenses', JSON.parse(softwareLicenses));
store.dispatch(`${LICENSE_LIST}/setLicensesEndpoint`, projectLicensesEndpoint); store.dispatch(`${LICENSE_LIST}/setLicensesEndpoint`, projectLicensesEndpoint);
return new Vue({ return new Vue({
......
...@@ -33,6 +33,10 @@ export default { ...@@ -33,6 +33,10 @@ export default {
required: false, required: false,
default: () => [], default: () => [],
}, },
knownLicenses: {
type: Array,
required: true,
},
loading: { loading: {
type: Boolean, type: Boolean,
required: false, required: false,
...@@ -78,6 +82,7 @@ export default { ...@@ -78,6 +82,7 @@ export default {
<add-license-form-dropdown <add-license-form-dropdown
id="js-license-dropdown" id="js-license-dropdown"
v-model="licenseName" v-model="licenseName"
:known-licenses="knownLicenses"
:placeholder="s__('LicenseCompliance|License name')" :placeholder="s__('LicenseCompliance|License name')"
/> />
<div class="invalid-feedback" :class="{ 'd-block': isInvalidLicense }"> <div class="invalid-feedback" :class="{ 'd-block': isInvalidLicense }">
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
import $ from 'jquery'; import $ from 'jquery';
import select2 from 'select2/select2'; import select2 from 'select2/select2';
import { KNOWN_LICENSES } from '../constants';
export default { export default {
name: 'AddLicenseFormDropdown', name: 'AddLicenseFormDropdown',
...@@ -17,6 +16,10 @@ export default { ...@@ -17,6 +16,10 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
knownLicenses: {
type: Array,
required: true,
},
}, },
mounted() { mounted() {
$(this.$refs.dropdownInput) $(this.$refs.dropdownInput)
...@@ -26,7 +29,10 @@ export default { ...@@ -26,7 +29,10 @@ export default {
placeholder: this.placeholder, placeholder: this.placeholder,
createSearchChoice: term => ({ id: term, text: term }), createSearchChoice: term => ({ id: term, text: term }),
createSearchChoicePosition: 'bottom', createSearchChoicePosition: 'bottom',
data: KNOWN_LICENSES.map(license => ({ id: license, text: license })), data: this.knownLicenses.map(license => ({
id: license,
text: license,
})),
}) })
.on('change', e => { .on('change', e => {
this.$emit('input', e.target.value); this.$emit('input', e.target.value);
......
...@@ -24,36 +24,6 @@ export const LICENSE_APPROVAL_ACTION = { ...@@ -24,36 +24,6 @@ export const LICENSE_APPROVAL_ACTION = {
DENY: 'deny', DENY: 'deny',
}; };
/* eslint-disable @gitlab/require-i18n-strings */
export const KNOWN_LICENSES = [
'AGPL-1.0',
'AGPL-3.0',
'Apache 2.0',
'Artistic-2.0',
'BSD',
'CC0 1.0 Universal',
'CDDL-1.0',
'CDDL-1.1',
'EPL-1.0',
'EPL-2.0',
'GPLv2',
'GPLv3',
'ISC',
'LGPL',
'LGPL-2.1',
'MIT',
'Mozilla Public License 2.0',
'MS-PL',
'MS-RL',
'New BSD',
'Python Software Foundation License',
'ruby',
'Simplified BSD',
'WTFPL',
'Zlib',
];
/* eslint-enable @gitlab/require-i18n-strings */
export const REPORT_GROUPS = [ export const REPORT_GROUPS = [
{ {
name: s__('LicenseManagement|Denied'), name: s__('LicenseManagement|Denied'),
......
...@@ -32,7 +32,12 @@ export default { ...@@ -32,7 +32,12 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(LICENSE_MANAGEMENT, ['managedLicenses', 'isLoadingManagedLicenses', 'isAdmin']), ...mapState(LICENSE_MANAGEMENT, [
'managedLicenses',
'isLoadingManagedLicenses',
'isAdmin',
'knownLicenses',
]),
...mapGetters(LICENSE_MANAGEMENT, [ ...mapGetters(LICENSE_MANAGEMENT, [
'isLicenseBeingUpdated', 'isLicenseBeingUpdated',
'hasPendingLicenses', 'hasPendingLicenses',
...@@ -143,6 +148,7 @@ export default { ...@@ -143,6 +148,7 @@ export default {
<div v-if="formIsOpen" class="gl-mt-3 gl-mb-3"> <div v-if="formIsOpen" class="gl-mt-3 gl-mb-3">
<add-license-form <add-license-form
:managed-licenses="managedLicenses" :managed-licenses="managedLicenses"
:known-licenses="knownLicenses"
:loading="isAddingNewLicense" :loading="isAddingNewLicense"
@addLicense="setLicenseApproval" @addLicense="setLicenseApproval"
@closeForm="closeAddLicenseForm" @closeForm="closeAddLicenseForm"
......
...@@ -12,6 +12,15 @@ export const setAPISettings = ({ commit }, data) => { ...@@ -12,6 +12,15 @@ export const setAPISettings = ({ commit }, data) => {
export const setLicenseInModal = ({ commit }, license) => { export const setLicenseInModal = ({ commit }, license) => {
commit(types.SET_LICENSE_IN_MODAL, license); commit(types.SET_LICENSE_IN_MODAL, license);
}; };
export const setIsAdmin = ({ commit }, payload) => {
commit(types.SET_IS_ADMIN, payload);
};
export const setKnownLicenses = ({ commit }, licenses) => {
commit(types.SET_KNOWN_LICENSES, licenses);
};
export const resetLicenseInModal = ({ commit }) => { export const resetLicenseInModal = ({ commit }) => {
commit(types.RESET_LICENSE_IN_MODAL); commit(types.RESET_LICENSE_IN_MODAL);
}; };
...@@ -153,10 +162,6 @@ export const receiveLicenseCheckApprovalRuleError = ({ commit }, error) => { ...@@ -153,10 +162,6 @@ export const receiveLicenseCheckApprovalRuleError = ({ commit }, error) => {
commit(types.RECEIVE_LICENSE_CHECK_APPROVAL_RULE_ERROR, error); commit(types.RECEIVE_LICENSE_CHECK_APPROVAL_RULE_ERROR, error);
}; };
export const setIsAdmin = ({ commit }, payload) => {
commit(types.SET_IS_ADMIN, payload);
};
export const addPendingLicense = ({ state, commit }, id = null) => { export const addPendingLicense = ({ state, commit }, id = null) => {
if (!state.pendingLicenses.includes(id)) { if (!state.pendingLicenses.includes(id)) {
commit(types.ADD_PENDING_LICENSE, id); commit(types.ADD_PENDING_LICENSE, id);
......
...@@ -13,6 +13,7 @@ export const REQUEST_SET_LICENSE_APPROVAL = 'REQUEST_SET_LICENSE_APPROVAL'; ...@@ -13,6 +13,7 @@ export const REQUEST_SET_LICENSE_APPROVAL = 'REQUEST_SET_LICENSE_APPROVAL';
export const RESET_LICENSE_IN_MODAL = 'RESET_LICENSE_IN_MODAL'; export const RESET_LICENSE_IN_MODAL = 'RESET_LICENSE_IN_MODAL';
export const SET_API_SETTINGS = 'SET_API_SETTINGS'; export const SET_API_SETTINGS = 'SET_API_SETTINGS';
export const SET_LICENSE_IN_MODAL = 'SET_LICENSE_IN_MODAL'; export const SET_LICENSE_IN_MODAL = 'SET_LICENSE_IN_MODAL';
export const SET_KNOWN_LICENSES = 'SET_KNOWN_LICENSES';
export const SET_IS_ADMIN = 'SET_IS_ADMIN'; export const SET_IS_ADMIN = 'SET_IS_ADMIN';
export const ADD_PENDING_LICENSE = 'ADD_PENDING_LICENSE'; export const ADD_PENDING_LICENSE = 'ADD_PENDING_LICENSE';
export const REMOVE_PENDING_LICENSE = 'REMOVE_PENDING_LICENSE'; export const REMOVE_PENDING_LICENSE = 'REMOVE_PENDING_LICENSE';
......
...@@ -20,6 +20,11 @@ export default { ...@@ -20,6 +20,11 @@ export default {
isAdmin: data, isAdmin: data,
}); });
}, },
[types.SET_KNOWN_LICENSES](state, data) {
Object.assign(state, {
knownLicenses: data,
});
},
[types.RECEIVE_MANAGED_LICENSES_SUCCESS](state, licenses = []) { [types.RECEIVE_MANAGED_LICENSES_SUCCESS](state, licenses = []) {
const managedLicenses = licenses.map(normalizeLicense).reverse(); const managedLicenses = licenses.map(normalizeLicense).reverse();
......
...@@ -17,4 +17,5 @@ export default () => ({ ...@@ -17,4 +17,5 @@ export default () => ({
existingLicenses: [], existingLicenses: [],
hasLicenseCheckApprovalRule: false, hasLicenseCheckApprovalRule: false,
isLoadingLicenseCheckApprovalRule: false, isLoadingLicenseCheckApprovalRule: false,
knownLicenses: [],
}); });
---
title: Show up to date SPDX licenses for license compliance
merge_request: 36926
author:
type: added
import Vue from 'vue';
import $ from 'jquery'; import $ from 'jquery';
import Dropdown from 'ee/vue_shared/license_compliance/components/add_license_form_dropdown.vue'; import Dropdown from 'ee/vue_shared/license_compliance/components/add_license_form_dropdown.vue';
import { KNOWN_LICENSES } from 'ee/vue_shared/license_compliance/constants'; import { shallowMount } from '@vue/test-utils';
import mountComponent from 'helpers/vue_mount_component_helper';
describe('AddLicenseFormDropdown', () => { let vm;
const Component = Vue.extend(Dropdown); let wrapper;
let vm;
const KNOWN_LICENSES = ['AGPL-1.0', 'AGPL-3.0', 'Apache 2.0', 'BSD'];
const createComponent = (props = {}) => {
wrapper = shallowMount(Dropdown, { propsData: { knownLicenses: KNOWN_LICENSES, ...props } });
vm = wrapper.vm;
};
describe('AddLicenseFormDropdown', () => {
afterEach(() => { afterEach(() => {
vm.$destroy(); vm = undefined;
wrapper.destroy();
}); });
it('emits `input` invent on change', () => { it('emits `input` invent on change', () => {
vm = mountComponent(Component); createComponent();
jest.spyOn(vm, '$emit').mockImplementation(() => {}); jest.spyOn(vm, '$emit').mockImplementation(() => {});
$(vm.$el) $(vm.$el)
...@@ -25,7 +32,7 @@ describe('AddLicenseFormDropdown', () => { ...@@ -25,7 +32,7 @@ describe('AddLicenseFormDropdown', () => {
it('sets the placeholder appropriately', () => { it('sets the placeholder appropriately', () => {
const placeholder = 'Select a license'; const placeholder = 'Select a license';
vm = mountComponent(Component, { placeholder }); createComponent({ placeholder });
const dropdownContainer = $(vm.$el).select2('container')[0]; const dropdownContainer = $(vm.$el).select2('container')[0];
...@@ -34,13 +41,13 @@ describe('AddLicenseFormDropdown', () => { ...@@ -34,13 +41,13 @@ describe('AddLicenseFormDropdown', () => {
it('sets the initial value correctly', () => { it('sets the initial value correctly', () => {
const value = 'AWESOME_LICENSE'; const value = 'AWESOME_LICENSE';
vm = mountComponent(Component, { value }); createComponent({ value });
expect(vm.$el.value).toContain(value); expect(vm.$el.value).toContain(value);
}); });
it('shows all pre-defined licenses', done => { it('shows all defined licenses', done => {
vm = mountComponent(Component); createComponent();
const element = $(vm.$el); const element = $(vm.$el);
......
import Vue from 'vue'; import Vue from 'vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
import LicenseIssueBody from 'ee/vue_shared/license_compliance/components/add_license_form.vue'; import LicenseIssueBody from 'ee/vue_shared/license_compliance/components/add_license_form.vue';
import mountComponent from 'helpers/vue_mount_component_helper';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_compliance/constants'; import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_compliance/constants';
describe('AddLicenseForm', () => { const KNOWN_LICENSES = [{ name: 'BSD' }, { name: 'Apache' }];
const Component = Vue.extend(LicenseIssueBody);
let vm; let wrapper;
let vm;
const findSubmitButton = () => vm.$el.querySelector('.js-submit'); const createComponent = (props = {}, mountFn = shallowMount) => {
const findCancelButton = () => vm.$el.querySelector('.js-cancel'); wrapper = mountFn(LicenseIssueBody, { propsData: { knownLicenses: KNOWN_LICENSES, ...props } });
vm = wrapper.vm;
};
describe('AddLicenseForm', () => {
const findSubmitButton = () => wrapper.find('.js-submit');
const findCancelButton = () => wrapper.find('.js-cancel');
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component); createComponent();
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); vm = undefined;
wrapper.destroy();
}); });
describe('interaction', () => { describe('interaction', () => {
it('clicking the Submit button submits the data and closes the form', done => { it('clicking the Submit button submits the data and closes the form', async () => {
const name = 'LICENSE_TEST'; const name = 'LICENSE_TEST';
createComponent({}, mount);
jest.spyOn(vm, '$emit').mockImplementation(() => {}); jest.spyOn(vm, '$emit').mockImplementation(() => {});
vm.approvalStatus = LICENSE_APPROVAL_STATUS.ALLOWED; wrapper.setData({ approvalStatus: LICENSE_APPROVAL_STATUS.ALLOWED, licenseName: name });
vm.licenseName = name;
Vue.nextTick(() => { await Vue.nextTick();
const linkEl = findSubmitButton();
linkEl.click();
expect(vm.$emit).toHaveBeenCalledWith('addLicense', { const linkEl = findSubmitButton();
newStatus: LICENSE_APPROVAL_STATUS.ALLOWED, linkEl.trigger('click');
license: { name },
});
done(); expect(vm.$emit).toHaveBeenCalledWith('addLicense', {
newStatus: LICENSE_APPROVAL_STATUS.ALLOWED,
license: { name },
}); });
}); });
it('clicking the Cancel button closes the form', () => { it('clicking the Cancel button closes the form', () => {
createComponent({}, mount);
const linkEl = findCancelButton(); const linkEl = findCancelButton();
jest.spyOn(vm, '$emit').mockImplementation(() => {}); jest.spyOn(vm, '$emit').mockImplementation(() => {});
linkEl.click(); linkEl.trigger('click');
expect(vm.$emit).toHaveBeenCalledWith('closeForm'); expect(vm.$emit).toHaveBeenCalledWith('closeForm');
}); });
...@@ -51,23 +58,20 @@ describe('AddLicenseForm', () => { ...@@ -51,23 +58,20 @@ describe('AddLicenseForm', () => {
describe('computed', () => { describe('computed', () => {
describe('submitDisabled', () => { describe('submitDisabled', () => {
it('is true if the approvalStatus is empty', () => { it('is true if the approvalStatus is empty', () => {
vm.licenseName = 'FOO'; wrapper.setData({ licenseName: 'FOO', approvalStatus: '' });
vm.approvalStatus = '';
expect(vm.submitDisabled).toBe(true); expect(vm.submitDisabled).toBe(true);
}); });
it('is true if the licenseName is empty', () => { it('is true if the licenseName is empty', () => {
vm.licenseName = ''; wrapper.setData({ licenseName: '', approvalStatus: LICENSE_APPROVAL_STATUS.ALLOWED });
vm.approvalStatus = LICENSE_APPROVAL_STATUS.ALLOWED;
expect(vm.submitDisabled).toBe(true); expect(vm.submitDisabled).toBe(true);
}); });
it('is true if the entered license is duplicated', () => { it('is true if the entered license is duplicated', () => {
vm = mountComponent(Component, { managedLicenses: [{ name: 'FOO' }] }); createComponent({ managedLicenses: [{ name: 'FOO' }] });
vm.licenseName = 'FOO'; wrapper.setData({ licenseName: 'FOO', approvalStatus: LICENSE_APPROVAL_STATUS.ALLOWED });
vm.approvalStatus = LICENSE_APPROVAL_STATUS.ALLOWED;
expect(vm.submitDisabled).toBe(true); expect(vm.submitDisabled).toBe(true);
}); });
...@@ -75,15 +79,15 @@ describe('AddLicenseForm', () => { ...@@ -75,15 +79,15 @@ describe('AddLicenseForm', () => {
describe('isInvalidLicense', () => { describe('isInvalidLicense', () => {
it('is true if the entered license is duplicated', () => { it('is true if the entered license is duplicated', () => {
vm = mountComponent(Component, { managedLicenses: [{ name: 'FOO' }] }); createComponent({ managedLicenses: [{ name: 'FOO' }] });
vm.licenseName = 'FOO'; wrapper.setData({ licenseName: 'FOO' });
expect(vm.isInvalidLicense).toBe(true); expect(vm.isInvalidLicense).toBe(true);
}); });
it('is false if the entered license is unique', () => { it('is false if the entered license is unique', () => {
vm = mountComponent(Component, { managedLicenses: [{ name: 'FOO' }] }); createComponent({ managedLicenses: [{ name: 'FOO' }] });
vm.licenseName = 'FOO2'; wrapper.setData({ licenseName: 'FOO2' });
expect(vm.isInvalidLicense).toBe(false); expect(vm.isInvalidLicense).toBe(false);
}); });
...@@ -92,98 +96,99 @@ describe('AddLicenseForm', () => { ...@@ -92,98 +96,99 @@ describe('AddLicenseForm', () => {
describe('template', () => { describe('template', () => {
it('renders the license select dropdown', () => { it('renders the license select dropdown', () => {
const dropdownElement = vm.$el.querySelector('#js-license-dropdown'); const dropdownElement = wrapper.find('#js-license-dropdown');
expect(dropdownElement).not.toBeNull(); expect(dropdownElement.exists()).toBe(true);
}); });
it('renders the license approval radio buttons dropdown', () => { it('renders the license approval radio buttons dropdown', () => {
const radioButtonParents = vm.$el.querySelectorAll('.form-check'); const radioButtonParents = wrapper.findAll('.form-check');
expect(radioButtonParents).toHaveLength(2); expect(radioButtonParents).toHaveLength(2);
expect(radioButtonParents[0].innerText.trim()).toBe('Allow'); expect(radioButtonParents.at(0).text()).toBe('Allow');
expect(radioButtonParents[0].querySelector('.form-check-input')).not.toBeNull(); expect(
expect(radioButtonParents[1].innerText.trim()).toBe('Deny'); radioButtonParents
expect(radioButtonParents[1].querySelector('.form-check-input')).not.toBeNull(); .at(0)
.find('.form-check-input')
.exists(),
).toBe(true);
expect(radioButtonParents.at(1).text()).toBe('Deny');
expect(
radioButtonParents
.at(1)
.find('.form-check-input')
.exists(),
).toBe(true);
}); });
it('renders error text, if there is a duplicate license', done => { it('renders error text, if there is a duplicate license', async () => {
vm = mountComponent(Component, { managedLicenses: [{ name: 'FOO' }] }); createComponent({ managedLicenses: [{ name: 'FOO' }] });
vm.licenseName = 'FOO'; wrapper.setData({ licenseName: 'FOO' });
Vue.nextTick(() => { await Vue.nextTick();
const feedbackElement = vm.$el.querySelector('.invalid-feedback');
const feedbackElement = wrapper.find('.invalid-feedback');
expect(feedbackElement).not.toBeNull();
expect(feedbackElement.classList).toContain('d-block'); expect(feedbackElement.exists()).toBe(true);
expect(feedbackElement.innerText.trim()).toBe( expect(feedbackElement.classes()).toContain('d-block');
'This license already exists in this project.', expect(feedbackElement.text()).toBe('This license already exists in this project.');
);
done();
});
}); });
it('shows radio button descriptions, if licenseComplianceDeniesMr feature flag is enabled', done => { it('shows radio button descriptions, if licenseComplianceDeniesMr feature flag is enabled', async () => {
const wrapper = shallowMount(LicenseIssueBody, { wrapper = shallowMount(LicenseIssueBody, {
propsData: { propsData: {
managedLicenses: [{ name: 'FOO' }], managedLicenses: [{ name: 'FOO' }],
knownLicenses: KNOWN_LICENSES,
}, },
provide: { provide: {
glFeatures: { licenseComplianceDeniesMr: true }, glFeatures: { licenseComplianceDeniesMr: true },
}, },
}); });
Vue.nextTick(() => { await Vue.nextTick();
const descriptionElement = wrapper.findAll('.text-secondary');
expect(descriptionElement.at(0).text()).toBe( const descriptionElement = wrapper.findAll('.text-secondary');
'Acceptable license to be used in the project',
);
expect(descriptionElement.at(1).text()).toBe( expect(descriptionElement.at(0).text()).toBe('Acceptable license to be used in the project');
'Disallow merge request if detected and will instruct developer to remove',
);
done(); expect(descriptionElement.at(1).text()).toBe(
}); 'Disallow merge request if detected and will instruct developer to remove',
);
}); });
it('does not show radio button descriptions, if licenseComplianceDeniesMr feature flag is disabled', done => { it('does not show radio button descriptions, if licenseComplianceDeniesMr feature flag is disabled', () => {
vm = mountComponent(Component, { managedLicenses: [{ name: 'FOO' }] }); createComponent({ managedLicenses: [{ name: 'FOO' }] });
vm.licenseName = 'FOO'; wrapper.setData({ licenseName: 'FOO' });
Vue.nextTick(() => { return Vue.nextTick().then(() => {
const formCheckElements = vm.$el.querySelectorAll('.form-check'); const formCheckElements = wrapper.findAll('.form-check');
expect(formCheckElements[0]).toMatchSnapshot(); expect(formCheckElements.at(0).element).toMatchSnapshot();
expect(formCheckElements[1]).toMatchSnapshot(); expect(formCheckElements.at(1).element).toMatchSnapshot();
done();
}); });
}); });
it('disables submit, if the form is invalid', done => { it('disables submit, if the form is invalid', async () => {
vm.licenseName = ''; wrapper.setData({ licenseName: '' });
Vue.nextTick(() => { await Vue.nextTick();
expect(vm.submitDisabled).toBe(true);
const submitButton = findSubmitButton(); expect(vm.submitDisabled).toBe(true);
expect(submitButton).not.toBeNull(); const submitButton = findSubmitButton();
expect(submitButton.disabled).toBe(true);
done(); expect(submitButton.exists()).toBe(true);
}); expect(submitButton.props().disabled).toBe(true);
}); });
it('disables submit and cancel while a new license is being added', done => { it('disables submit and cancel while a new license is being added', async () => {
vm.loading = true; wrapper.setProps({ loading: true });
Vue.nextTick(() => { await Vue.nextTick();
const submitButton = findSubmitButton();
const cancelButton = findCancelButton(); const submitButton = findSubmitButton();
const cancelButton = findCancelButton();
expect(submitButton).not.toBeNull();
expect(submitButton.disabled).toBe(true); expect(submitButton.exists()).toBe(true);
expect(cancelButton).not.toBeNull(); expect(submitButton.props().disabled).toBe(true);
expect(cancelButton.disabled).toBe(true); expect(cancelButton.exists()).toBe(true);
done(); expect(cancelButton.props().disabled).toBe(true);
});
}); });
}); });
}); });
...@@ -47,6 +47,7 @@ const createComponent = ({ state, getters, props, actionMocks, isAdmin, options, ...@@ -47,6 +47,7 @@ const createComponent = ({ state, getters, props, actionMocks, isAdmin, options,
managedLicenses, managedLicenses,
isLoadingManagedLicenses: true, isLoadingManagedLicenses: true,
isAdmin, isAdmin,
knownLicenses: [],
...state, ...state,
}, },
actions: { actions: {
......
...@@ -60,6 +60,21 @@ describe('License store actions', () => { ...@@ -60,6 +60,21 @@ describe('License store actions', () => {
}); });
}); });
describe('setKnownLicenses', () => {
it('commits SET_KNOWN_LICENSES', done => {
const payload = [{ name: 'BSD' }, { name: 'Apache' }];
testAction(
actions.setKnownLicenses,
payload,
state,
[{ type: mutationTypes.SET_KNOWN_LICENSES, payload }],
[],
)
.then(done)
.catch(done.fail);
});
});
describe('setLicenseInModal', () => { describe('setLicenseInModal', () => {
it('commits SET_LICENSE_IN_MODAL with license', done => { it('commits SET_LICENSE_IN_MODAL with license', done => {
testAction( testAction(
......
...@@ -20,6 +20,15 @@ describe('License store mutations', () => { ...@@ -20,6 +20,15 @@ describe('License store mutations', () => {
}); });
}); });
describe('SET_KNOWN_LICENSES', () => {
it('assigns knownLicenses to the store', () => {
const licenses = [{ name: 'BSD' }, { name: 'Apache' }];
store.commit(`licenseManagement/${types.SET_KNOWN_LICENSES}`, licenses);
expect(store.state.licenseManagement.knownLicenses).toBe(licenses);
});
});
describe('RESET_LICENSE_IN_MODAL', () => { describe('RESET_LICENSE_IN_MODAL', () => {
it('closes modal and deletes licenseInApproval', () => { it('closes modal and deletes licenseInApproval', () => {
store.replaceState({ store.replaceState({
......
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