Commit ecef867f authored by Jacques's avatar Jacques

Replace form form props with provide/inject

Replaced the fork form paths with provide/inject
parent 61c0cd31
...@@ -10,38 +10,6 @@ export default { ...@@ -10,38 +10,6 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
endpoint: {
type: String,
required: true,
},
projectFullPath: {
type: String,
required: true,
},
projectId: {
type: String,
required: true,
},
projectName: {
type: String,
required: true,
},
projectPath: {
type: String,
required: true,
},
projectDescription: {
type: String,
required: true,
},
projectVisibility: {
type: String,
required: true,
},
restrictedVisibilityLevels: {
type: Array,
required: true,
},
}, },
}; };
</script> </script>
...@@ -62,16 +30,7 @@ export default { ...@@ -62,16 +30,7 @@ export default {
</p> </p>
</div> </div>
<div class="col-lg-9"> <div class="col-lg-9">
<fork-form <fork-form />
:endpoint="endpoint"
:project-full-path="projectFullPath"
:project-id="projectId"
:project-name="projectName"
:project-path="projectPath"
:project-description="projectDescription"
:project-visibility="projectVisibility"
:restricted-visibility-levels="restrictedVisibilityLevels"
/>
</div> </div>
</div> </div>
</template> </template>
...@@ -72,40 +72,29 @@ export default { ...@@ -72,40 +72,29 @@ export default {
visibilityHelpPath: { visibilityHelpPath: {
default: '', default: '',
}, },
},
props: {
endpoint: { endpoint: {
type: String, default: '',
required: true,
}, },
projectFullPath: { projectFullPath: {
type: String, default: '',
required: true,
}, },
projectId: { projectId: {
type: String, default: '',
required: true,
}, },
projectName: { projectName: {
type: String, default: '',
required: true,
}, },
projectPath: { projectPath: {
type: String, default: '',
required: true,
}, },
projectDescription: { projectDescription: {
type: String,
required: false,
default: '', default: '',
}, },
projectVisibility: { projectVisibility: {
type: String, default: '',
required: true,
}, },
restrictedVisibilityLevels: { restrictedVisibilityLevels: {
type: Array, default: [],
required: true,
}, },
}, },
data() { data() {
......
...@@ -23,21 +23,19 @@ new Vue({ ...@@ -23,21 +23,19 @@ new Vue({
provide: { provide: {
newGroupPath, newGroupPath,
visibilityHelpPath, visibilityHelpPath,
endpoint,
projectFullPath,
projectId,
projectName,
projectPath,
projectDescription,
projectVisibility,
restrictedVisibilityLevels: JSON.parse(restrictedVisibilityLevels),
}, },
render(h) { render(h) {
return h(App, { return h(App, {
props: { props: {
forkIllustration, forkIllustration,
endpoint,
newGroupPath,
projectFullPath,
visibilityHelpPath,
projectId,
projectName,
projectPath,
projectDescription,
projectVisibility,
restrictedVisibilityLevels: JSON.parse(restrictedVisibilityLevels),
}, },
}); });
}, },
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import App from '~/pages/projects/forks/new/components/app.vue'; import App from '~/pages/projects/forks/new/components/app.vue';
import ForkForm from '~/pages/projects/forks/new/components/fork_form.vue';
describe('App component', () => { describe('App component', () => {
let wrapper; let wrapper;
const DEFAULT_PROPS = { const DEFAULT_PROPS = {
forkIllustration: 'illustrations/project-create-new-sm.svg', forkIllustration: 'illustrations/project-create-new-sm.svg',
endpoint: '/some/project-full-path/-/forks/new.json',
projectFullPath: '/some/project-full-path',
projectId: '10',
projectName: 'Project Name',
projectPath: 'project-name',
projectDescription: 'some project description',
projectVisibility: 'private',
restrictedVisibilityLevels: [],
}; };
const createComponent = (props = {}) => { const createComponent = (props = {}) => {
...@@ -37,7 +30,7 @@ describe('App component', () => { ...@@ -37,7 +30,7 @@ describe('App component', () => {
expect(wrapper.find('img').attributes('src')).toBe('illustrations/project-create-new-sm.svg'); expect(wrapper.find('img').attributes('src')).toBe('illustrations/project-create-new-sm.svg');
}); });
it('renders ForkForm component with prop', () => { it('renders ForkForm component', () => {
expect(wrapper.props()).toEqual(expect.objectContaining(DEFAULT_PROPS)); expect(wrapper.findComponent(ForkForm).exists()).toBe(true);
}); });
}); });
...@@ -40,7 +40,9 @@ describe('ForkForm component', () => { ...@@ -40,7 +40,9 @@ describe('ForkForm component', () => {
}, },
]; ];
const DEFAULT_PROPS = { const DEFAULT_PROVIDE = {
newGroupPath: 'some/groups/path',
visibilityHelpPath: 'some/visibility/help/path',
endpoint: '/some/project-full-path/-/forks/new.json', endpoint: '/some/project-full-path/-/forks/new.json',
projectFullPath: '/some/project-full-path', projectFullPath: '/some/project-full-path',
projectId: '10', projectId: '10',
...@@ -52,18 +54,14 @@ describe('ForkForm component', () => { ...@@ -52,18 +54,14 @@ describe('ForkForm component', () => {
}; };
const mockGetRequest = (data = {}, statusCode = httpStatus.OK) => { const mockGetRequest = (data = {}, statusCode = httpStatus.OK) => {
axiosMock.onGet(DEFAULT_PROPS.endpoint).replyOnce(statusCode, data); axiosMock.onGet(DEFAULT_PROVIDE.endpoint).replyOnce(statusCode, data);
}; };
const createComponentFactory = (mountFn) => (props = {}, data = {}) => { const createComponentFactory = (mountFn) => (provide = {}, data = {}) => {
wrapper = mountFn(ForkForm, { wrapper = mountFn(ForkForm, {
provide: { provide: {
newGroupPath: 'some/groups/path', ...DEFAULT_PROVIDE,
visibilityHelpPath: 'some/visibility/help/path', ...provide,
},
propsData: {
...DEFAULT_PROPS,
...props,
}, },
data() { data() {
return { return {
...@@ -111,7 +109,7 @@ describe('ForkForm component', () => { ...@@ -111,7 +109,7 @@ describe('ForkForm component', () => {
mockGetRequest(); mockGetRequest();
createComponent(); createComponent();
const { projectFullPath } = DEFAULT_PROPS; const { projectFullPath } = DEFAULT_PROVIDE;
const cancelButton = wrapper.find('[data-testid="cancel-button"]'); const cancelButton = wrapper.find('[data-testid="cancel-button"]');
expect(cancelButton.attributes('href')).toBe(projectFullPath); expect(cancelButton.attributes('href')).toBe(projectFullPath);
...@@ -130,10 +128,10 @@ describe('ForkForm component', () => { ...@@ -130,10 +128,10 @@ describe('ForkForm component', () => {
mockGetRequest(); mockGetRequest();
createComponent(); createComponent();
expect(findForkNameInput().attributes('value')).toBe(DEFAULT_PROPS.projectName); expect(findForkNameInput().attributes('value')).toBe(DEFAULT_PROVIDE.projectName);
expect(findForkSlugInput().attributes('value')).toBe(DEFAULT_PROPS.projectPath); expect(findForkSlugInput().attributes('value')).toBe(DEFAULT_PROVIDE.projectPath);
expect(findForkDescriptionTextarea().attributes('value')).toBe( expect(findForkDescriptionTextarea().attributes('value')).toBe(
DEFAULT_PROPS.projectDescription, DEFAULT_PROVIDE.projectDescription,
); );
}); });
...@@ -164,7 +162,7 @@ describe('ForkForm component', () => { ...@@ -164,7 +162,7 @@ describe('ForkForm component', () => {
it('make GET request from endpoint', async () => { it('make GET request from endpoint', async () => {
await axios.waitForAll(); await axios.waitForAll();
expect(axiosMock.history.get[0].url).toBe(DEFAULT_PROPS.endpoint); expect(axiosMock.history.get[0].url).toBe(DEFAULT_PROVIDE.endpoint);
}); });
it('generate default option', async () => { it('generate default option', async () => {
...@@ -469,7 +467,7 @@ describe('ForkForm component', () => { ...@@ -469,7 +467,7 @@ describe('ForkForm component', () => {
projectName, projectName,
projectPath, projectPath,
projectVisibility, projectVisibility,
} = DEFAULT_PROPS; } = DEFAULT_PROVIDE;
const url = `/api/${GON_API_VERSION}/projects/${projectId}/fork`; const url = `/api/${GON_API_VERSION}/projects/${projectId}/fork`;
const project = { const project = {
......
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