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