Commit 86ea3d3e authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'refactor-license-management-mount-hook' into 'master'

Refactor mount hooks for license compliance

See merge request gitlab-org/gitlab!27274
parents f6eb0d85 f4e8e16f
...@@ -13,6 +13,7 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -13,6 +13,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (el && el.dataset && el.dataset.apiUrl) { if (el && el.dataset && el.dataset.apiUrl) {
const store = createStore(); const store = createStore();
store.dispatch('licenseManagement/setIsAdmin', Boolean(el.dataset.apiUrl)); store.dispatch('licenseManagement/setIsAdmin', Boolean(el.dataset.apiUrl));
store.dispatch('licenseManagement/setAPISettings', { apiUrlManageLicenses: el.dataset.apiUrl });
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
el, el,
......
...@@ -32,10 +32,6 @@ export default { ...@@ -32,10 +32,6 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
readLicensePoliciesEndpoint: {
type: String,
required: true,
},
}, },
data() { data() {
return { return {
...@@ -120,7 +116,7 @@ export default { ...@@ -120,7 +116,7 @@ export default {
<gl-badge pill>{{ policyCount }}</gl-badge> <gl-badge pill>{{ policyCount }}</gl-badge>
</template> </template>
<license-management :api-url="readLicensePoliciesEndpoint" /> <license-management />
</gl-tab> </gl-tab>
</gl-tabs> </gl-tabs>
</template> </template>
......
...@@ -14,6 +14,9 @@ export default () => { ...@@ -14,6 +14,9 @@ export default () => {
} = el.dataset; } = el.dataset;
const store = createStore(); const store = createStore();
store.dispatch('licenseManagement/setIsAdmin', Boolean(writeLicensePoliciesEndpoint)); store.dispatch('licenseManagement/setIsAdmin', Boolean(writeLicensePoliciesEndpoint));
store.dispatch('licenseManagement/setAPISettings', {
apiUrlManageLicenses: readLicensePoliciesEndpoint,
});
store.dispatch(`${LICENSE_LIST}/setLicensesEndpoint`, projectLicensesEndpoint); store.dispatch(`${LICENSE_LIST}/setLicensesEndpoint`, projectLicensesEndpoint);
return new Vue({ return new Vue({
...@@ -27,7 +30,6 @@ export default () => { ...@@ -27,7 +30,6 @@ export default () => {
props: { props: {
emptyStateSvgPath, emptyStateSvgPath,
documentationPath, documentationPath,
readLicensePoliciesEndpoint,
}, },
}); });
}, },
......
...@@ -21,12 +21,6 @@ export default { ...@@ -21,12 +21,6 @@ export default {
GlLoadingIcon, GlLoadingIcon,
PaginatedList, PaginatedList,
}, },
props: {
apiUrl: {
type: String,
required: true,
},
},
data() { data() {
return { return {
formIsOpen: false, formIsOpen: false,
...@@ -55,17 +49,10 @@ export default { ...@@ -55,17 +49,10 @@ export default {
}, },
}, },
mounted() { mounted() {
this.setAPISettings({
apiUrlManageLicenses: this.apiUrl,
});
this.fetchManagedLicenses(); this.fetchManagedLicenses();
}, },
methods: { methods: {
...mapActions(LICENSE_MANAGEMENT, [ ...mapActions(LICENSE_MANAGEMENT, ['fetchManagedLicenses', 'setLicenseApproval']),
'fetchManagedLicenses',
'setAPISettings',
'setLicenseApproval',
]),
openAddLicenseForm() { openAddLicenseForm() {
this.formIsOpen = true; this.formIsOpen = true;
}, },
......
...@@ -7,14 +7,12 @@ import AdminLicenseManagementRow from 'ee/vue_shared/license_management/componen ...@@ -7,14 +7,12 @@ import AdminLicenseManagementRow from 'ee/vue_shared/license_management/componen
import LicenseManagementRow from 'ee/vue_shared/license_management/components/license_management_row.vue'; import LicenseManagementRow from 'ee/vue_shared/license_management/components/license_management_row.vue';
import AddLicenseForm from 'ee/vue_shared/license_management/components/add_license_form.vue'; import AddLicenseForm from 'ee/vue_shared/license_management/components/add_license_form.vue';
import DeleteConfirmationModal from 'ee/vue_shared/license_management/components/delete_confirmation_modal.vue'; import DeleteConfirmationModal from 'ee/vue_shared/license_management/components/delete_confirmation_modal.vue';
import { TEST_HOST } from 'helpers/test_constants';
import { approvedLicense, blacklistedLicense } from './mock_data'; import { approvedLicense, blacklistedLicense } from './mock_data';
Vue.use(Vuex); Vue.use(Vuex);
let wrapper; let wrapper;
const apiUrl = `${TEST_HOST}/license_management`;
const managedLicenses = [approvedLicense, blacklistedLicense]; const managedLicenses = [approvedLicense, blacklistedLicense];
const PaginatedListMock = { const PaginatedListMock = {
...@@ -50,7 +48,6 @@ const createComponent = ({ state, getters, props, actionMocks, isAdmin }) => { ...@@ -50,7 +48,6 @@ const createComponent = ({ state, getters, props, actionMocks, isAdmin }) => {
}, },
actions: { actions: {
fetchManagedLicenses: noop, fetchManagedLicenses: noop,
setAPISettings: noop,
setLicenseApproval: noop, setLicenseApproval: noop,
...actionMocks, ...actionMocks,
}, },
...@@ -60,7 +57,6 @@ const createComponent = ({ state, getters, props, actionMocks, isAdmin }) => { ...@@ -60,7 +57,6 @@ const createComponent = ({ state, getters, props, actionMocks, isAdmin }) => {
wrapper = shallowMount(LicenseManagement, { wrapper = shallowMount(LicenseManagement, {
propsData: { propsData: {
apiUrl,
...props, ...props,
}, },
stubs: { stubs: {
...@@ -106,27 +102,17 @@ describe('License Management', () => { ...@@ -106,27 +102,17 @@ describe('License Management', () => {
}); });
}); });
it('should set api settings after mount and init API calls', () => { it('should mount and fetch licenses', () => {
const setAPISettingsMock = jest.fn();
const fetchManagedLicensesMock = jest.fn(); const fetchManagedLicensesMock = jest.fn();
createComponent({ createComponent({
state: { isLoadingManagedLicenses: false }, state: { isLoadingManagedLicenses: false },
actionMocks: { actionMocks: {
setAPISettings: setAPISettingsMock,
fetchManagedLicenses: fetchManagedLicensesMock, fetchManagedLicenses: fetchManagedLicensesMock,
}, },
isAdmin, isAdmin,
}); });
expect(setAPISettingsMock).toHaveBeenCalledWith(
expect.any(Object),
{
apiUrlManageLicenses: apiUrl,
},
undefined,
);
expect(fetchManagedLicensesMock).toHaveBeenCalledWith( expect(fetchManagedLicensesMock).toHaveBeenCalledWith(
expect.any(Object), expect.any(Object),
undefined, undefined,
......
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