Commit 5693bc36 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '212561-fix-empty-edit-area' into 'master'

fix: Publish toolbar dissappears when submitting empty content

See merge request gitlab-org/gitlab!29410
parents 5103cfae 93a2599d
...@@ -12,8 +12,8 @@ export default { ...@@ -12,8 +12,8 @@ export default {
Toolbar, Toolbar,
}, },
computed: { computed: {
...mapState(['content', 'isLoadingContent', 'isSavingChanges']), ...mapState(['content', 'isLoadingContent', 'isSavingChanges', 'isContentLoaded']),
...mapGetters(['isContentLoaded', 'contentChanged']), ...mapGetters(['contentChanged']),
}, },
mounted() { mounted() {
this.loadContent(); this.loadContent();
......
export const isContentLoaded = ({ originalContent }) => Boolean(originalContent); // eslint-disable-next-line import/prefer-default-export
export const contentChanged = ({ originalContent, content }) => originalContent !== content; export const contentChanged = ({ originalContent, content }) => originalContent !== content;
...@@ -6,6 +6,7 @@ export default { ...@@ -6,6 +6,7 @@ export default {
}, },
[types.RECEIVE_CONTENT_SUCCESS](state, { title, content }) { [types.RECEIVE_CONTENT_SUCCESS](state, { title, content }) {
state.isLoadingContent = false; state.isLoadingContent = false;
state.isContentLoaded = true;
state.title = title; state.title = title;
state.content = content; state.content = content;
state.originalContent = content; state.originalContent = content;
......
...@@ -6,6 +6,8 @@ const createState = (initialState = {}) => ({ ...@@ -6,6 +6,8 @@ const createState = (initialState = {}) => ({
isLoadingContent: false, isLoadingContent: false,
isSavingChanges: false, isSavingChanges: false,
isContentLoaded: false,
originalContent: '', originalContent: '',
content: '', content: '',
title: '', title: '',
......
---
title: 'fix: Publish toolbar dissappears when submitting empty content'
merge_request: 29410
author:
type: fixed
...@@ -30,7 +30,6 @@ describe('StaticSiteEditor', () => { ...@@ -30,7 +30,6 @@ describe('StaticSiteEditor', () => {
store = new Vuex.Store({ store = new Vuex.Store({
state: createState(initialState), state: createState(initialState),
getters: { getters: {
isContentLoaded: () => false,
contentChanged: () => false, contentChanged: () => false,
...getters, ...getters,
}, },
...@@ -43,9 +42,11 @@ describe('StaticSiteEditor', () => { ...@@ -43,9 +42,11 @@ describe('StaticSiteEditor', () => {
}; };
const buildContentLoadedStore = ({ initialState, getters } = {}) => { const buildContentLoadedStore = ({ initialState, getters } = {}) => {
buildStore({ buildStore({
initialState, initialState: {
isContentLoaded: true,
...initialState,
},
getters: { getters: {
isContentLoaded: () => true,
...getters, ...getters,
}, },
}); });
...@@ -85,7 +86,7 @@ describe('StaticSiteEditor', () => { ...@@ -85,7 +86,7 @@ describe('StaticSiteEditor', () => {
const content = 'edit area content'; const content = 'edit area content';
beforeEach(() => { beforeEach(() => {
buildStore({ initialState: { content }, getters: { isContentLoaded: () => true } }); buildContentLoadedStore({ initialState: { content } });
buildWrapper(); buildWrapper();
}); });
......
import createState from '~/static_site_editor/store/state'; import createState from '~/static_site_editor/store/state';
import { isContentLoaded, contentChanged } from '~/static_site_editor/store/getters'; import { contentChanged } from '~/static_site_editor/store/getters';
import { sourceContent as content } from '../mock_data'; import { sourceContent as content } from '../mock_data';
describe('Static Site Editor Store getters', () => { describe('Static Site Editor Store getters', () => {
describe('isContentLoaded', () => {
it('returns true when originalContent is not empty', () => {
expect(isContentLoaded(createState({ originalContent: content }))).toBe(true);
});
it('returns false when originalContent is empty', () => {
expect(isContentLoaded(createState({ originalContent: '' }))).toBe(false);
});
});
describe('contentChanged', () => { describe('contentChanged', () => {
it('returns true when content and originalContent are different', () => { it('returns true when content and originalContent are different', () => {
const state = createState({ content, originalContent: 'something else' }); const state = createState({ content, originalContent: 'something else' });
......
...@@ -19,6 +19,7 @@ describe('Static Site Editor Store mutations', () => { ...@@ -19,6 +19,7 @@ describe('Static Site Editor Store mutations', () => {
mutation | stateProperty | payload | expectedValue mutation | stateProperty | payload | expectedValue
${types.LOAD_CONTENT} | ${'isLoadingContent'} | ${undefined} | ${true} ${types.LOAD_CONTENT} | ${'isLoadingContent'} | ${undefined} | ${true}
${types.RECEIVE_CONTENT_SUCCESS} | ${'isLoadingContent'} | ${contentLoadedPayload} | ${false} ${types.RECEIVE_CONTENT_SUCCESS} | ${'isLoadingContent'} | ${contentLoadedPayload} | ${false}
${types.RECEIVE_CONTENT_SUCCESS} | ${'isContentLoaded'} | ${contentLoadedPayload} | ${true}
${types.RECEIVE_CONTENT_SUCCESS} | ${'title'} | ${contentLoadedPayload} | ${title} ${types.RECEIVE_CONTENT_SUCCESS} | ${'title'} | ${contentLoadedPayload} | ${title}
${types.RECEIVE_CONTENT_SUCCESS} | ${'content'} | ${contentLoadedPayload} | ${content} ${types.RECEIVE_CONTENT_SUCCESS} | ${'content'} | ${contentLoadedPayload} | ${content}
${types.RECEIVE_CONTENT_SUCCESS} | ${'originalContent'} | ${contentLoadedPayload} | ${content} ${types.RECEIVE_CONTENT_SUCCESS} | ${'originalContent'} | ${contentLoadedPayload} | ${content}
......
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