Commit 667300e4 authored by derek-knox's avatar derek-knox

Applied initial round of feedback

Fixed tests and applied suggestions
parent a600662a
...@@ -50,8 +50,8 @@ export default { ...@@ -50,8 +50,8 @@ export default {
parsedSource: parseSourceFile(this.preProcess(true, this.content)), parsedSource: parseSourceFile(this.preProcess(true, this.content)),
editorMode: EDITOR_TYPES.wysiwyg, editorMode: EDITOR_TYPES.wysiwyg,
isModified: false, isModified: false,
isDrawerOpen: false,
hasMatter: false, hasMatter: false,
isDrawerOpen: false,
}; };
}, },
imageRepository: imageRepository(), imageRepository: imageRepository(),
...@@ -62,13 +62,16 @@ export default { ...@@ -62,13 +62,16 @@ export default {
editableMatter() { editableMatter() {
return this.isDrawerOpen ? this.parsedSource.matter() : {}; return this.isDrawerOpen ? this.parsedSource.matter() : {};
}, },
hasSettingsButton() { hasSettings() {
return this.hasMatter && this.isWysiwygMode; return this.hasMatter && this.isWysiwygMode;
}, },
isWysiwygMode() { isWysiwygMode() {
return this.editorMode === EDITOR_TYPES.wysiwyg; return this.editorMode === EDITOR_TYPES.wysiwyg;
}, },
}, },
created() {
this.refreshEditHelpers();
},
methods: { methods: {
preProcess(isWrap, value) { preProcess(isWrap, value) {
const formattedContent = formatter(value); const formattedContent = formatter(value);
...@@ -138,7 +141,7 @@ export default { ...@@ -138,7 +141,7 @@ export default {
<unsaved-changes-confirm-dialog :modified="isModified" /> <unsaved-changes-confirm-dialog :modified="isModified" />
<publish-toolbar <publish-toolbar
class="gl-fixed gl-left-0 gl-bottom-0 gl-w-full" class="gl-fixed gl-left-0 gl-bottom-0 gl-w-full"
:is-show-edit="hasSettingsButton" :has-settings="hasSettings"
:return-url="returnUrl" :return-url="returnUrl"
:saveable="isModified" :saveable="isModified"
:saving-changes="savingChanges" :saving-changes="savingChanges"
......
...@@ -6,7 +6,7 @@ export default { ...@@ -6,7 +6,7 @@ export default {
GlButton, GlButton,
}, },
props: { props: {
isShowEdit: { hasSettings: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
...@@ -36,9 +36,9 @@ export default { ...@@ -36,9 +36,9 @@ export default {
s__('StaticSiteEditor|Return to site') s__('StaticSiteEditor|Return to site')
}}</gl-button> }}</gl-button>
<gl-button <gl-button
v-if="isShowEdit" v-if="hasSettings"
ref="settings" ref="settings"
:loading="savingChanges" :disabled="savingChanges"
@click="$emit('editSettings')" @click="$emit('editSettings')"
> >
<span>{{ __('Settings') }}</span> <span>{{ __('Settings') }}</span>
......
...@@ -48,6 +48,7 @@ describe('~/static_site_editor/components/edit_area.vue', () => { ...@@ -48,6 +48,7 @@ describe('~/static_site_editor/components/edit_area.vue', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
it('renders edit header', () => { it('renders edit header', () => {
...@@ -55,8 +56,8 @@ describe('~/static_site_editor/components/edit_area.vue', () => { ...@@ -55,8 +56,8 @@ describe('~/static_site_editor/components/edit_area.vue', () => {
expect(findEditHeader().props('title')).toBe(title); expect(findEditHeader().props('title')).toBe(title);
}); });
it('does not render edit drawer', () => { it('renders edit drawer', () => {
expect(findEditDrawer().exists()).toBe(false); expect(findEditDrawer().exists()).toBe(true);
}); });
it('renders rich content editor with a format pass', () => { it('renders rich content editor with a format pass', () => {
...@@ -78,6 +79,18 @@ describe('~/static_site_editor/components/edit_area.vue', () => { ...@@ -78,6 +79,18 @@ describe('~/static_site_editor/components/edit_area.vue', () => {
expect(findUnsavedChangesConfirmDialog().props('modified')).toBe(false); expect(findUnsavedChangesConfirmDialog().props('modified')).toBe(false);
}); });
it.each`
key
${'isModified'}
${'hasMatter'}
`('updates $key data when refreshEditHelpers is called', ({ key }) => {
const spy = jest.spyOn(wrapper.vm.parsedSource, key);
wrapper.vm.refreshEditHelpers();
expect(spy).toHaveBeenCalled();
});
describe('when content changes', () => { describe('when content changes', () => {
beforeEach(() => { beforeEach(() => {
findRichContentEditor().vm.$emit('input', newBody); findRichContentEditor().vm.$emit('input', newBody);
...@@ -154,17 +167,7 @@ describe('~/static_site_editor/components/edit_area.vue', () => { ...@@ -154,17 +167,7 @@ describe('~/static_site_editor/components/edit_area.vue', () => {
}); });
}); });
describe('when hasMatter', () => { describe('when content has front matter', () => {
beforeEach(() => {
wrapper.setData({ hasMatter: true, isDrawerOpen: false });
wrapper.vm.$nextTick();
});
afterEach(() => {
wrapper.setData({ hasMatter: false });
});
it('renders a closed edit drawer', () => { it('renders a closed edit drawer', () => {
expect(findEditDrawer().exists()).toBe(true); expect(findEditDrawer().exists()).toBe(true);
expect(findEditDrawer().props('isOpen')).toBe(false); expect(findEditDrawer().props('isOpen')).toBe(false);
...@@ -174,13 +177,12 @@ describe('~/static_site_editor/components/edit_area.vue', () => { ...@@ -174,13 +177,12 @@ describe('~/static_site_editor/components/edit_area.vue', () => {
findPublishToolbar().vm.$emit('editSettings'); findPublishToolbar().vm.$emit('editSettings');
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.isDrawerOpen).toBe(true);
expect(findEditDrawer().props('isOpen')).toBe(true); expect(findEditDrawer().props('isOpen')).toBe(true);
}); });
}); });
it('closes the edit drawer', () => { it('closes the edit drawer', () => {
wrapper.setData({ isDrawerOpen: true }); buildWrapper({ isDrawerOpen: true });
findEditDrawer().vm.$emit('close'); findEditDrawer().vm.$emit('close');
...@@ -204,6 +206,20 @@ describe('~/static_site_editor/components/edit_area.vue', () => { ...@@ -204,6 +206,20 @@ describe('~/static_site_editor/components/edit_area.vue', () => {
}); });
}); });
describe('when content lacks front matter', () => {
beforeEach(() => {
buildWrapper({ content: body });
});
afterEach(() => {
wrapper.destroy();
});
it('does not render edit drawer', () => {
expect(findEditDrawer().exists()).toBe(false);
});
});
describe('when content is submitted', () => { describe('when content is submitted', () => {
it('should format the content', () => { it('should format the content', () => {
findPublishToolbar().vm.$emit('submit', content); findPublishToolbar().vm.$emit('submit', content);
......
...@@ -27,6 +27,7 @@ describe('~/static_site_editor/components/edit_drawer.vue', () => { ...@@ -27,6 +27,7 @@ describe('~/static_site_editor/components/edit_drawer.vue', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
it('renders the GlDrawer', () => { it('renders the GlDrawer', () => {
...@@ -41,7 +42,7 @@ describe('~/static_site_editor/components/edit_drawer.vue', () => { ...@@ -41,7 +42,7 @@ describe('~/static_site_editor/components/edit_drawer.vue', () => {
expect(findFrontMatterControls().props('settings')).toBe(wrapper.props('settings')); expect(findFrontMatterControls().props('settings')).toBe(wrapper.props('settings'));
}); });
it('is closed be default', () => { it('is closed by default', () => {
expect(findGlDrawer().props('open')).toBe(false); expect(findGlDrawer().props('open')).toBe(false);
}); });
......
...@@ -10,7 +10,7 @@ describe('Static Site Editor Toolbar', () => { ...@@ -10,7 +10,7 @@ describe('Static Site Editor Toolbar', () => {
const buildWrapper = (propsData = {}) => { const buildWrapper = (propsData = {}) => {
wrapper = shallowMount(PublishToolbar, { wrapper = shallowMount(PublishToolbar, {
propsData: { propsData: {
isShowEdit: false, hasSettings: false,
saveable: false, saveable: false,
...propsData, ...propsData,
}, },
...@@ -58,7 +58,7 @@ describe('Static Site Editor Toolbar', () => { ...@@ -58,7 +58,7 @@ describe('Static Site Editor Toolbar', () => {
describe('when providing settings CTA', () => { describe('when providing settings CTA', () => {
it('enables Submit Changes button', () => { it('enables Submit Changes button', () => {
buildWrapper({ isShowEdit: true }); buildWrapper({ hasSettings: true });
expect(findEditSettingsButton().exists()).toBe(true); expect(findEditSettingsButton().exists()).toBe(true);
}); });
......
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