Commit 6dd4a4fd authored by Enrique Alcántara's avatar Enrique Alcántara Committed by Paul Slaughter

Move success view to a different page

Create a different page to display the submit
changes success message.

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/30533
parent 4bc39902
<script> <script>
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import SkeletonLoader from '../components/skeleton_loader.vue'; import SkeletonLoader from '../components/skeleton_loader.vue';
import EditArea from '../components/edit_area.vue'; import EditArea from '../components/edit_area.vue';
import SavedChangesMessage from '../components/saved_changes_message.vue';
import InvalidContentMessage from '../components/invalid_content_message.vue'; import InvalidContentMessage from '../components/invalid_content_message.vue';
import SubmitChangesError from '../components/submit_changes_error.vue'; import SubmitChangesError from '../components/submit_changes_error.vue';
import { SUCCESS_ROUTE } from '../router/constants';
import appDataQuery from '../graphql/queries/app_data.query.graphql'; import appDataQuery from '../graphql/queries/app_data.query.graphql';
import sourceContentQuery from '../graphql/queries/source_content.query.graphql'; import sourceContentQuery from '../graphql/queries/source_content.query.graphql';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { LOAD_CONTENT_ERROR } from '../constants'; import { LOAD_CONTENT_ERROR } from '../constants';
export default { export default {
...@@ -19,7 +15,6 @@ export default { ...@@ -19,7 +15,6 @@ export default {
SkeletonLoader, SkeletonLoader,
EditArea, EditArea,
InvalidContentMessage, InvalidContentMessage,
SavedChangesMessage,
SubmitChangesError, SubmitChangesError,
}, },
apollo: { apollo: {
...@@ -50,7 +45,7 @@ export default { ...@@ -50,7 +45,7 @@ export default {
}, },
}, },
computed: { computed: {
...mapState(['isSavingChanges', 'submitChangesError', 'savedContentMeta']), ...mapState(['isSavingChanges', 'submitChangesError']),
isLoadingContent() { isLoadingContent() {
return this.$apollo.queries.sourceContent.loading; return this.$apollo.queries.sourceContent.loading;
}, },
...@@ -62,24 +57,15 @@ export default { ...@@ -62,24 +57,15 @@ export default {
...mapActions(['setContent', 'submitChanges', 'dismissSubmitChangesError']), ...mapActions(['setContent', 'submitChanges', 'dismissSubmitChangesError']),
onSubmit({ content }) { onSubmit({ content }) {
this.setContent(content); this.setContent(content);
this.submitChanges();
return this.submitChanges().then(() => this.$router.push(SUCCESS_ROUTE));
}, },
}, },
}; };
</script> </script>
<template> <template>
<div class="container d-flex gl-flex-direction-column pt-2 h-100"> <div class="container d-flex gl-flex-direction-column pt-2 h-100">
<!-- Success view --> <template v-if="appData.isSupportedContent">
<saved-changes-message
v-if="savedContentMeta"
:branch="savedContentMeta.branch"
:commit="savedContentMeta.commit"
:merge-request="savedContentMeta.mergeRequest"
:return-url="appData.returnUrl"
/>
<!-- Main view -->
<template v-else-if="appData.isSupportedContent">
<skeleton-loader v-if="isLoadingContent" class="w-75 gl-align-self-center gl-mt-5" /> <skeleton-loader v-if="isLoadingContent" class="w-75 gl-align-self-center gl-mt-5" />
<submit-changes-error <submit-changes-error
v-if="submitChangesError" v-if="submitChangesError"
...@@ -97,7 +83,6 @@ export default { ...@@ -97,7 +83,6 @@ export default {
/> />
</template> </template>
<!-- Error view -->
<invalid-content-message v-else class="w-75" /> <invalid-content-message v-else class="w-75" />
</div> </div>
</template> </template>
<script>
import { mapState } from 'vuex';
import SavedChangesMessage from '../components/saved_changes_message.vue';
import { HOME_ROUTE } from '../router/constants';
export default {
components: {
SavedChangesMessage,
},
computed: {
...mapState(['savedContentMeta', 'returnUrl']),
},
created() {
if (!this.savedContentMeta) {
this.$router.push(HOME_ROUTE);
}
},
};
</script>
<template>
<div v-if="savedContentMeta" class="container">
<saved-changes-message
:branch="savedContentMeta.branch"
:commit="savedContentMeta.commit"
:merge-request="savedContentMeta.mergeRequest"
:return-url="returnUrl"
/>
</div>
</template>
// eslint-disable-next-line import/prefer-default-export export const HOME_ROUTE = { name: 'home' };
export const HOME_ROUTE_NAME = 'home'; export const SUCCESS_ROUTE = { name: 'success' };
import Home from '../pages/home.vue'; import Home from '../pages/home.vue';
import { HOME_ROUTE_NAME } from './constants'; import Success from '../pages/success.vue';
import { HOME_ROUTE, SUCCESS_ROUTE } from './constants';
export default [ export default [
{ {
name: HOME_ROUTE_NAME, ...HOME_ROUTE,
path: '/', path: '/',
component: Home, component: Home,
}, },
{
...SUCCESS_ROUTE,
path: '/success',
component: Success,
},
]; ];
import Vuex from 'vuex'; import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import createState from '~/static_site_editor/store/state'; import createState from '~/static_site_editor/store/state';
import { SUCCESS_ROUTE } from '~/static_site_editor/router/constants';
import Home from '~/static_site_editor/pages/home.vue'; import Home from '~/static_site_editor/pages/home.vue';
import SkeletonLoader from '~/static_site_editor/components/skeleton_loader.vue'; import SkeletonLoader from '~/static_site_editor/components/skeleton_loader.vue';
import EditArea from '~/static_site_editor/components/edit_area.vue'; import EditArea from '~/static_site_editor/components/edit_area.vue';
import InvalidContentMessage from '~/static_site_editor/components/invalid_content_message.vue'; import InvalidContentMessage from '~/static_site_editor/components/invalid_content_message.vue';
import SubmitChangesError from '~/static_site_editor/components/submit_changes_error.vue'; import SubmitChangesError from '~/static_site_editor/components/submit_changes_error.vue';
import SavedChangesMessage from '~/static_site_editor/components/saved_changes_message.vue';
import { import {
returnUrl, returnUrl,
sourceContent as content, sourceContent as content,
sourceContentTitle as title, sourceContentTitle as title,
savedContentMeta,
submitChangesError, submitChangesError,
} from '../mock_data'; } from '../mock_data';
...@@ -27,6 +23,7 @@ describe('static_site_editor/pages/home', () => { ...@@ -27,6 +23,7 @@ describe('static_site_editor/pages/home', () => {
let wrapper; let wrapper;
let store; let store;
let $apollo; let $apollo;
let $router;
let setContentActionMock; let setContentActionMock;
let submitChangesActionMock; let submitChangesActionMock;
let dismissSubmitChangesErrorActionMock; let dismissSubmitChangesErrorActionMock;
...@@ -63,12 +60,19 @@ describe('static_site_editor/pages/home', () => { ...@@ -63,12 +60,19 @@ describe('static_site_editor/pages/home', () => {
}; };
}; };
const buildRouter = () => {
$router = {
push: jest.fn(),
};
};
const buildWrapper = (data = {}) => { const buildWrapper = (data = {}) => {
wrapper = shallowMount(Home, { wrapper = shallowMount(Home, {
localVue, localVue,
store, store,
mocks: { mocks: {
$apollo, $apollo,
$router,
}, },
data() { data() {
return { return {
...@@ -83,10 +87,10 @@ describe('static_site_editor/pages/home', () => { ...@@ -83,10 +87,10 @@ describe('static_site_editor/pages/home', () => {
const findInvalidContentMessage = () => wrapper.find(InvalidContentMessage); const findInvalidContentMessage = () => wrapper.find(InvalidContentMessage);
const findSkeletonLoader = () => wrapper.find(SkeletonLoader); const findSkeletonLoader = () => wrapper.find(SkeletonLoader);
const findSubmitChangesError = () => wrapper.find(SubmitChangesError); const findSubmitChangesError = () => wrapper.find(SubmitChangesError);
const findSavedChangesMessage = () => wrapper.find(SavedChangesMessage);
beforeEach(() => { beforeEach(() => {
buildApollo(); buildApollo();
buildRouter();
buildStore(); buildStore();
}); });
...@@ -96,23 +100,6 @@ describe('static_site_editor/pages/home', () => { ...@@ -96,23 +100,6 @@ describe('static_site_editor/pages/home', () => {
$apollo = null; $apollo = null;
}); });
it('renders the saved changes message when changes are submitted successfully', () => {
buildStore({ initialState: { returnUrl, savedContentMeta } });
buildWrapper();
expect(findSavedChangesMessage().exists()).toBe(true);
expect(findSavedChangesMessage().props()).toEqual({
returnUrl,
...savedContentMeta,
});
});
it('does not render the saved changes message when changes are not submitted', () => {
buildWrapper();
expect(findSavedChangesMessage().exists()).toBe(false);
});
describe('when content is loaded', () => { describe('when content is loaded', () => {
beforeEach(() => { beforeEach(() => {
buildStore({ initialState: { isSavingChanges: true } }); buildStore({ initialState: { isSavingChanges: true } });
...@@ -123,20 +110,14 @@ describe('static_site_editor/pages/home', () => { ...@@ -123,20 +110,14 @@ describe('static_site_editor/pages/home', () => {
expect(findEditArea().exists()).toBe(true); expect(findEditArea().exists()).toBe(true);
}); });
it('provides source content to the edit area', () => { it('provides source content, returnUrl, and isSavingChanges to the edit area', () => {
expect(findEditArea().props()).toMatchObject({ expect(findEditArea().props()).toMatchObject({
title, title,
content, content,
returnUrl,
savingChanges: true,
}); });
}); });
it('provides returnUrl to the edit area', () => {
expect(findEditArea().props('returnUrl')).toBe(returnUrl);
});
it('provides isSavingChanges to the edit area', () => {
expect(findEditArea().props('savingChanges')).toBe(true);
});
}); });
it('does not render edit area when content is not loaded', () => { it('does not render edit area when content is not loaded', () => {
...@@ -210,6 +191,8 @@ describe('static_site_editor/pages/home', () => { ...@@ -210,6 +191,8 @@ describe('static_site_editor/pages/home', () => {
const newContent = `new ${content}`; const newContent = `new ${content}`;
beforeEach(() => { beforeEach(() => {
submitChangesActionMock.mockResolvedValueOnce();
buildWrapper({ sourceContent: { title, content } }); buildWrapper({ sourceContent: { title, content } });
findEditArea().vm.$emit('submit', { content: newContent }); findEditArea().vm.$emit('submit', { content: newContent });
}); });
...@@ -221,5 +204,11 @@ describe('static_site_editor/pages/home', () => { ...@@ -221,5 +204,11 @@ describe('static_site_editor/pages/home', () => {
it('dispatches submitChanges action', () => { it('dispatches submitChanges action', () => {
expect(submitChangesActionMock).toHaveBeenCalled(); expect(submitChangesActionMock).toHaveBeenCalled();
}); });
it('pushes success route when submitting changes succeeds', () => {
return wrapper.vm.$nextTick().then(() => {
expect($router.push).toHaveBeenCalledWith(SUCCESS_ROUTE);
});
});
}); });
}); });
import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import createState from '~/static_site_editor/store/state';
import Success from '~/static_site_editor/pages/success.vue';
import SavedChangesMessage from '~/static_site_editor/components/saved_changes_message.vue';
import { savedContentMeta, returnUrl } from '../mock_data';
import { HOME_ROUTE } from '~/static_site_editor/router/constants';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('static_site_editor/pages/success', () => {
let wrapper;
let store;
let router;
const buildRouter = () => {
router = {
push: jest.fn(),
};
};
const buildStore = (initialState = {}) => {
store = new Vuex.Store({
state: createState({
savedContentMeta,
returnUrl,
...initialState,
}),
});
};
const buildWrapper = () => {
wrapper = shallowMount(Success, {
localVue,
store,
mocks: {
$router: router,
},
});
};
const findSavedChangesMessage = () => wrapper.find(SavedChangesMessage);
beforeEach(() => {
buildRouter();
buildStore();
});
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
it('renders saved changes message', () => {
buildWrapper();
expect(findSavedChangesMessage().exists()).toBe(true);
});
it('passes returnUrl to the saved changes message', () => {
buildWrapper();
expect(findSavedChangesMessage().props('returnUrl')).toBe(returnUrl);
});
it('passes saved content metadata to the saved changes message', () => {
buildWrapper();
expect(findSavedChangesMessage().props('branch')).toBe(savedContentMeta.branch);
expect(findSavedChangesMessage().props('commit')).toBe(savedContentMeta.commit);
expect(findSavedChangesMessage().props('mergeRequest')).toBe(savedContentMeta.mergeRequest);
});
it('redirects to the HOME route when content has not been submitted', () => {
buildStore({ savedContentMeta: null });
buildWrapper();
expect(router.push).toHaveBeenCalledWith(HOME_ROUTE);
});
});
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