Commit 13c21890 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'jnnkl-provide-inject-refactor' into 'master'

Refactor dependency list to use provide/inject for static values

See merge request gitlab-org/gitlab!76955
parents 3b90b273 05180ea0
...@@ -24,28 +24,13 @@ export default { ...@@ -24,28 +24,13 @@ export default {
DependencyListJobFailedAlert, DependencyListJobFailedAlert,
PaginatedDependenciesTable, PaginatedDependenciesTable,
}, },
props: { inject: [
endpoint: { 'sbomSurveySvgPath',
type: String, 'emptyStateSvgPath',
required: true, 'documentationPath',
}, 'endpoint',
sbomSurveySvgPath: { 'supportDocumentationPath',
type: String, ],
required: true,
},
emptyStateSvgPath: {
type: String,
required: true,
},
documentationPath: {
type: String,
required: true,
},
supportDocumentationPath: {
type: String,
required: true,
},
},
data() { data() {
return { return {
isIncompleteAlertDismissed: false, isIncompleteAlertDismissed: false,
......
...@@ -5,13 +5,13 @@ import createStore from './store'; ...@@ -5,13 +5,13 @@ import createStore from './store';
export default () => { export default () => {
const el = document.querySelector('#js-dependencies-app'); const el = document.querySelector('#js-dependencies-app');
const { const provide = {
endpoint, sbomSurveySvgPath: el.dataset.sbomSurveySvgPath,
emptyStateSvgPath, emptyStateSvgPath: el.dataset.emptyStateSvgPath,
documentationPath, documentationPath: el.dataset.documentationPath,
supportDocumentationPath, endpoint: el.dataset.endpoint,
sbomSurveySvgPath, supportDocumentationPath: el.dataset.supportDocumentationPath,
} = el.dataset; };
const store = createStore(); const store = createStore();
...@@ -21,16 +21,9 @@ export default () => { ...@@ -21,16 +21,9 @@ export default () => {
DependenciesApp, DependenciesApp,
}, },
store, store,
provide,
render(createElement) { render(createElement) {
return createElement(DependenciesApp, { return createElement(DependenciesApp);
props: {
endpoint,
emptyStateSvgPath,
documentationPath,
supportDocumentationPath,
sbomSurveySvgPath,
},
});
}, },
}); });
}; };
...@@ -36,20 +36,7 @@ export default { ...@@ -36,20 +36,7 @@ export default {
LicenseManagement, LicenseManagement,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
props: { inject: ['sbomSurveySvgPath', 'emptyStateSvgPath', 'documentationPath'],
emptyStateSvgPath: {
type: String,
required: true,
},
sbomSurveySvgPath: {
type: String,
required: true,
},
documentationPath: {
type: String,
required: true,
},
},
data() { data() {
return { return {
tabIndex: this.activeTabIndex(), tabIndex: this.activeTabIndex(),
......
...@@ -7,8 +7,6 @@ export default () => { ...@@ -7,8 +7,6 @@ export default () => {
const el = document.querySelector('#js-licenses-app'); const el = document.querySelector('#js-licenses-app');
const { const {
projectLicensesEndpoint, projectLicensesEndpoint,
emptyStateSvgPath,
documentationPath,
readLicensePoliciesEndpoint, readLicensePoliciesEndpoint,
writeLicensePoliciesEndpoint, writeLicensePoliciesEndpoint,
projectId, projectId,
...@@ -18,7 +16,6 @@ export default () => { ...@@ -18,7 +16,6 @@ export default () => {
approvalsDocumentationPath, approvalsDocumentationPath,
lockedApprovalsRuleName, lockedApprovalsRuleName,
softwareLicenses, softwareLicenses,
sbomSurveySvgPath,
} = el.dataset; } = el.dataset;
const storeSettings = { const storeSettings = {
...@@ -31,6 +28,12 @@ export default () => { ...@@ -31,6 +28,12 @@ export default () => {
}; };
const store = createStore(storeSettings); const store = createStore(storeSettings);
const provide = {
sbomSurveySvgPath: el.dataset.sbomSurveySvgPath,
emptyStateSvgPath: el.dataset.emptyStateSvgPath,
documentationPath: el.dataset.documentationPath,
};
store.dispatch('licenseManagement/setIsAdmin', Boolean(writeLicensePoliciesEndpoint)); store.dispatch('licenseManagement/setIsAdmin', Boolean(writeLicensePoliciesEndpoint));
store.dispatch('licenseManagement/setAPISettings', { store.dispatch('licenseManagement/setAPISettings', {
apiUrlManageLicenses: readLicensePoliciesEndpoint, apiUrlManageLicenses: readLicensePoliciesEndpoint,
...@@ -45,14 +48,9 @@ export default () => { ...@@ -45,14 +48,9 @@ export default () => {
components: { components: {
LicenseComplianceApp, LicenseComplianceApp,
}, },
provide: () => provide,
render(createElement) { render(createElement) {
return createElement(LicenseComplianceApp, { return createElement(LicenseComplianceApp);
props: {
sbomSurveySvgPath,
emptyStateSvgPath,
documentationPath,
},
});
}, },
}); });
}; };
...@@ -26,7 +26,7 @@ describe('DependenciesApp component', () => { ...@@ -26,7 +26,7 @@ describe('DependenciesApp component', () => {
supportDocumentationPath: `${TEST_HOST}/dependency_scanning#supported-languages`, supportDocumentationPath: `${TEST_HOST}/dependency_scanning#supported-languages`,
}; };
const factory = ({ props = basicAppProps, ...options } = {}) => { const factory = ({ ...options } = {}) => {
store = createStore(); store = createStore();
jest.spyOn(store, 'dispatch').mockImplementation(); jest.spyOn(store, 'dispatch').mockImplementation();
...@@ -41,9 +41,15 @@ describe('DependenciesApp component', () => { ...@@ -41,9 +41,15 @@ describe('DependenciesApp component', () => {
wrapper = extendedWrapper( wrapper = extendedWrapper(
mount(DependenciesApp, { mount(DependenciesApp, {
store, store,
propsData: { ...props },
stubs, stubs,
...options, ...options,
provide: {
endpoint: '/foo',
emptyStateSvgPath: '/bar.svg',
sbomSurveySvgPath: '/foo.svg',
documentationPath: TEST_HOST,
supportDocumentationPath: `${TEST_HOST}/dependency_scanning#supported-languages`,
},
}), }),
); );
}; };
...@@ -221,7 +227,7 @@ describe('DependenciesApp component', () => { ...@@ -221,7 +227,7 @@ describe('DependenciesApp component', () => {
it('renders the SbomBannercomponent with the right props', () => { it('renders the SbomBannercomponent with the right props', () => {
const sbomBanner = findSbomBanner(); const sbomBanner = findSbomBanner();
expect(sbomBanner.exists()).toBe(true); expect(sbomBanner.exists()).toBe(true);
expect(sbomBanner.props().sbomSurveySvgPath).toEqual(wrapper.props().sbomSurveySvgPath); expect(sbomBanner.props().sbomSurveySvgPath).toEqual(basicAppProps.sbomSurveySvgPath);
}); });
describe('given the user has public permissions', () => { describe('given the user has public permissions', () => {
......
...@@ -74,15 +74,17 @@ const createComponent = ({ state, props, options }) => { ...@@ -74,15 +74,17 @@ const createComponent = ({ state, props, options }) => {
wrapper = mountFunc(LicenseComplianceApp, { wrapper = mountFunc(LicenseComplianceApp, {
propsData: { propsData: {
emptyStateSvgPath,
documentationPath,
sbomSurveySvgPath,
readLicensePoliciesEndpoint, readLicensePoliciesEndpoint,
...props, ...props,
}, },
...options, ...options,
store: fakeStore, store: fakeStore,
stubs: { transition: stubTransition() }, stubs: { transition: stubTransition() },
provide: {
sbomSurveySvgPath,
emptyStateSvgPath,
documentationPath,
},
}); });
}; };
...@@ -190,7 +192,7 @@ describe('Project Licenses', () => { ...@@ -190,7 +192,7 @@ describe('Project Licenses', () => {
it('renders the SbomBannercomponent with the right props', () => { it('renders the SbomBannercomponent with the right props', () => {
const sbomBanner = findSbomBanner(); const sbomBanner = findSbomBanner();
expect(sbomBanner.exists()).toBe(true); expect(sbomBanner.exists()).toBe(true);
expect(sbomBanner.props().sbomSurveySvgPath).toEqual(wrapper.props().sbomSurveySvgPath); expect(sbomBanner.props().sbomSurveySvgPath).toEqual(sbomSurveySvgPath);
}); });
it('renders a "Detected in project" tab and a "Policies" tab', () => { it('renders a "Detected in project" tab and a "Policies" tab', () => {
......
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