Commit 6cbbcbe2 authored by Simon Knox's avatar Simon Knox Committed by Nicolò Maria Mezzopera

Use vue-router for Iteration Cadences

parent a4e70544
<template>
<router-view />
</template>
...@@ -9,7 +9,6 @@ import { ...@@ -9,7 +9,6 @@ import {
GlFormInput, GlFormInput,
GlFormSelect, GlFormSelect,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { visitUrl } from '~/lib/utils/url_utility';
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
import createCadence from '../queries/create_cadence.mutation.graphql'; import createCadence from '../queries/create_cadence.mutation.graphql';
...@@ -65,14 +64,7 @@ export default { ...@@ -65,14 +64,7 @@ export default {
GlFormInput, GlFormInput,
GlFormSelect, GlFormSelect,
}, },
inject: ['groupPath'], inject: ['groupPath', 'cadencesListPath'],
props: {
cadencesListPath: {
type: String,
required: false,
default: '',
},
},
data() { data() {
return { return {
cadences: [], cadences: [],
...@@ -150,11 +142,7 @@ export default { ...@@ -150,11 +142,7 @@ export default {
return this.createCadence(); return this.createCadence();
}, },
cancel() { cancel() {
if (this.cadencesListPath) { this.$router.push({ name: 'index' });
visitUrl(this.cadencesListPath);
} else {
this.$emit('cancel');
}
}, },
createCadence() { createCadence() {
return this.$apollo return this.$apollo
...@@ -175,7 +163,7 @@ export default { ...@@ -175,7 +163,7 @@ export default {
return; return;
} }
visitUrl(this.cadencesListPath); this.$router.push({ name: 'index' });
}) })
.catch((e) => { .catch((e) => {
this.errorMessage = __('Unable to save cadence. Please try again'); this.errorMessage = __('Unable to save cadence. Please try again');
......
...@@ -2,10 +2,11 @@ import Vue from 'vue'; ...@@ -2,10 +2,11 @@ import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
import IterationCadenceForm from './components/iteration_cadence_form.vue'; import App from './components/app.vue';
import IterationForm from './components/iteration_form.vue'; import IterationForm from './components/iteration_form.vue';
import IterationReport from './components/iteration_report.vue'; import IterationReport from './components/iteration_report.vue';
import Iterations from './components/iterations.vue'; import Iterations from './components/iterations.vue';
import createRouter from './router';
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -91,28 +92,26 @@ export function initIterationReport({ namespaceType, initiallyEditing } = {}) { ...@@ -91,28 +92,26 @@ export function initIterationReport({ namespaceType, initiallyEditing } = {}) {
}); });
} }
export function initCadenceForm() { export function initCadenceApp() {
const el = document.querySelector('.js-iteration-cadence-form'); const el = document.querySelector('.js-iteration-cadence-app');
if (!el) { if (!el) {
return null; return null;
} }
const { groupFullPath: groupPath, cadenceId, cadencesListPath } = el.dataset; const { groupFullPath: groupPath, cadencesListPath } = el.dataset;
const router = createRouter(cadencesListPath);
return new Vue({ return new Vue({
el, el,
router,
apolloProvider, apolloProvider,
provide: { provide: {
groupPath, groupPath,
},
render(createElement) {
return createElement(IterationCadenceForm, {
props: {
cadenceId,
cadencesListPath, cadencesListPath,
}, },
}); render(createElement) {
return createElement(App);
}, },
}); });
} }
import Vue from 'vue';
import VueRouter from 'vue-router';
import IterationCadenceForm from './components/iteration_cadence_form.vue';
import IterationCadenceList from './components/iteration_cadences_list.vue';
Vue.use(VueRouter);
const routes = [
{
name: 'new',
path: '/new',
component: IterationCadenceForm,
},
{
name: 'index',
path: '/',
component: IterationCadenceList,
},
];
export default function createRouter(base) {
const router = new VueRouter({
base,
mode: 'history',
routes,
});
return router;
}
import { initCadenceForm } from 'ee/iterations'; import { initCadenceApp } from 'ee/iterations';
initCadenceForm(); initCadenceApp();
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
- breadcrumb_title params[:id] - breadcrumb_title params[:id]
- page_title _("Edit iteration cadence") - page_title _("Edit iteration cadence")
.js-iteration-cadence-form{ data: { group_full_path: @group.full_path, .js-iteration-cadence-app{ data: { group_full_path: @group.full_path,
cadence_id: params[:id], cadence_id: params[:id],
cadences_list_path: group_iteration_cadences_path(@group) } } cadences_list_path: group_iteration_cadences_path(@group) } }
- page_title _("Iteration cadences")
.js-iteration-cadence-app{ data: { group_full_path: @group.full_path, cadences_list_path: group_iteration_cadences_path(@group) } }
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
- breadcrumb_title _("New") - breadcrumb_title _("New")
- page_title _("New iteration cadence") - page_title _("New iteration cadence")
.js-iteration-cadence-form{ data: { group_full_path: @group.full_path, cadences_list_path: group_iteration_cadences_path(@group) } } .js-iteration-cadence-app{ data: { group_full_path: @group.full_path, cadences_list_path: group_iteration_cadences_path(@group) } }
import { GlFormCheckbox, GlFormGroup } from '@gitlab/ui'; import { GlFormCheckbox, GlFormGroup } from '@gitlab/ui';
import { createLocalVue, mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import IterationCadenceForm from 'ee/iterations/components/iteration_cadence_form.vue'; import IterationCadenceForm from 'ee/iterations/components/iteration_cadence_form.vue';
import createCadence from 'ee/iterations/queries/create_cadence.mutation.graphql'; import createCadence from 'ee/iterations/queries/create_cadence.mutation.graphql';
...@@ -7,14 +8,14 @@ import createMockApollo from 'helpers/mock_apollo_helper'; ...@@ -7,14 +8,14 @@ import createMockApollo from 'helpers/mock_apollo_helper';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { visitUrl } from '~/lib/utils/url_utility';
jest.mock('~/lib/utils/url_utility'); const push = jest.fn();
const $router = {
const localVue = createLocalVue(); push,
};
function createMockApolloProvider(requestHandlers) { function createMockApolloProvider(requestHandlers) {
localVue.use(VueApollo); Vue.use(VueApollo);
return createMockApollo(requestHandlers); return createMockApollo(requestHandlers);
} }
...@@ -39,17 +40,18 @@ describe('Iteration cadence form', () => { ...@@ -39,17 +40,18 @@ describe('Iteration cadence form', () => {
iterationCadenceCreate: { iterationCadence, errors: ['alas, your data is unchanged'] }, iterationCadenceCreate: { iterationCadence, errors: ['alas, your data is unchanged'] },
}, },
}; };
const defaultProps = { cadencesListPath: TEST_HOST };
function createComponent({ props = defaultProps, resolverMock } = {}) { function createComponent({ resolverMock } = {}) {
const apolloProvider = createMockApolloProvider([[createCadence, resolverMock]]); const apolloProvider = createMockApolloProvider([[createCadence, resolverMock]]);
wrapper = extendedWrapper( wrapper = extendedWrapper(
mount(IterationCadenceForm, { mount(IterationCadenceForm, {
apolloProvider, apolloProvider,
localVue, mocks: {
propsData: props, $router,
},
provide: { provide: {
groupPath, groupPath,
cadencesListPath: TEST_HOST,
}, },
}), }),
); );
...@@ -86,7 +88,7 @@ describe('Iteration cadence form', () => { ...@@ -86,7 +88,7 @@ describe('Iteration cadence form', () => {
it('cancel button links to list page', () => { it('cancel button links to list page', () => {
clickCancel(); clickCancel();
expect(visitUrl).toHaveBeenCalledWith(TEST_HOST); expect(push).toHaveBeenCalledWith({ name: 'index' });
}); });
describe('save', () => { describe('save', () => {
...@@ -131,7 +133,7 @@ describe('Iteration cadence form', () => { ...@@ -131,7 +133,7 @@ describe('Iteration cadence form', () => {
await waitForPromises(); await waitForPromises();
expect(visitUrl).toHaveBeenCalled(); expect(push).toHaveBeenCalledWith({ name: 'index' });
}); });
it('does not submit if required fields missing', () => { it('does not submit if required fields missing', () => {
......
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