Commit 08504786 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'web-ide-fix' into 'master'

Remove unnecessary Edit tab in WebIDE

See merge request gitlab-org/gitlab!81366
parents 889cb709 578ef143
...@@ -147,6 +147,9 @@ export default { ...@@ -147,6 +147,9 @@ export default {
fileType() { fileType() {
return this.previewMode?.id || ''; return this.previewMode?.id || '';
}, },
showTabs() {
return !this.shouldHideEditor && this.isEditModeActive && this.previewMode;
},
}, },
watch: { watch: {
'file.name': { 'file.name': {
...@@ -194,6 +197,9 @@ export default { ...@@ -194,6 +197,9 @@ export default {
this.refreshEditorDimensions(); this.refreshEditorDimensions();
} }
}, },
showTabs() {
this.$nextTick(() => this.refreshEditorDimensions());
},
rightPaneIsOpen() { rightPaneIsOpen() {
this.refreshEditorDimensions(); this.refreshEditorDimensions();
}, },
...@@ -410,7 +416,7 @@ export default { ...@@ -410,7 +416,7 @@ export default {
} }
}, },
refreshEditorDimensions() { refreshEditorDimensions() {
if (this.showEditor) { if (this.showEditor && this.editor) {
this.editor.updateDimensions(); this.editor.updateDimensions();
} }
}, },
...@@ -495,7 +501,7 @@ export default { ...@@ -495,7 +501,7 @@ export default {
<template> <template>
<div id="ide" class="blob-viewer-container blob-editor-container"> <div id="ide" class="blob-viewer-container blob-editor-container">
<div v-if="!shouldHideEditor && isEditModeActive" class="ide-mode-tabs clearfix"> <div v-if="showTabs" class="ide-mode-tabs clearfix">
<ul class="nav-links float-left border-bottom-0"> <ul class="nav-links float-left border-bottom-0">
<li :class="editTabCSS"> <li :class="editTabCSS">
<a <a
...@@ -506,7 +512,7 @@ export default { ...@@ -506,7 +512,7 @@ export default {
>{{ __('Edit') }}</a >{{ __('Edit') }}</a
> >
</li> </li>
<li v-if="previewMode" :class="previewTabCSS"> <li :class="previewTabCSS">
<a <a
href="javascript:void(0);" href="javascript:void(0);"
role="button" role="button"
......
...@@ -169,12 +169,11 @@ describe('RepoEditor', () => { ...@@ -169,12 +169,11 @@ describe('RepoEditor', () => {
expect(findEditor().isVisible()).toBe(true); expect(findEditor().isVisible()).toBe(true);
}); });
it('renders only an edit tab', async () => { it('renders no tabs', async () => {
await createComponent(); await createComponent();
const tabs = findTabs(); const tabs = findTabs();
expect(tabs).toHaveLength(1); expect(tabs).toHaveLength(0);
expect(tabs.at(0).text()).toBe('Edit');
}); });
}); });
...@@ -196,25 +195,48 @@ describe('RepoEditor', () => { ...@@ -196,25 +195,48 @@ describe('RepoEditor', () => {
mock.restore(); mock.restore();
}); });
it('renders an Edit and a Preview Tab', async () => { describe('when files is markdown', () => {
await createComponent({ activeFile }); let layoutSpy;
const tabs = findTabs();
expect(tabs).toHaveLength(2); beforeEach(async () => {
expect(tabs.at(0).text()).toBe('Edit'); await createComponent({ activeFile });
expect(tabs.at(1).text()).toBe('Preview Markdown'); layoutSpy = jest.spyOn(wrapper.vm.editor, 'layout');
}); });
it('renders markdown for tempFile', async () => { it('renders an Edit and a Preview Tab', () => {
// by default files created in the spec are temp: no need for explicitly sending the param const tabs = findTabs();
await createComponent({ activeFile });
findPreviewTab().trigger('click'); expect(tabs).toHaveLength(2);
await waitForPromises(); expect(tabs.at(0).text()).toBe('Edit');
expect(wrapper.find(ContentViewer).html()).toContain(defaultFileProps.content); expect(tabs.at(1).text()).toBe('Preview Markdown');
});
it('renders markdown for tempFile', async () => {
findPreviewTab().trigger('click');
await waitForPromises();
expect(wrapper.find(ContentViewer).html()).toContain(defaultFileProps.content);
});
it('should not trigger layout', async () => {
expect(layoutSpy).not.toHaveBeenCalled();
});
describe('when file changes to non-markdown file', () => {
beforeEach(async () => {
wrapper.setProps({ file: dummyFile.empty });
});
it('should hide tabs', () => {
expect(findTabs()).toHaveLength(0);
});
it('should trigger refresh dimensions', async () => {
expect(layoutSpy).toHaveBeenCalledTimes(1);
});
});
}); });
it('shows no tabs when not in Edit mode', async () => { it('when not in edit mode, shows no tabs', async () => {
await createComponent({ await createComponent({
state: { state: {
currentActivityView: leftSidebarViews.review.name, currentActivityView: leftSidebarViews.review.name,
...@@ -405,7 +427,7 @@ describe('RepoEditor', () => { ...@@ -405,7 +427,7 @@ describe('RepoEditor', () => {
it.each` it.each`
mode | isVisible mode | isVisible
${'edit'} | ${true} ${'edit'} | ${false}
${'review'} | ${false} ${'review'} | ${false}
${'commit'} | ${false} ${'commit'} | ${false}
`('tabs in $mode are $isVisible', async ({ mode, isVisible } = {}) => { `('tabs in $mode are $isVisible', async ({ mode, isVisible } = {}) => {
......
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