summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/markdown
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-03-17 21:08:46 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-17 21:08:46 +0000
commit0ad8135c1feeefa23ec883e409fb65b8b52882a1 (patch)
tree9d303513f4ea47cf835bbd894d940454eb8e2d14 /spec/frontend/vue_shared/components/markdown
parentc18d1c1bd2d0339ddcff4d320ee306fa03692986 (diff)
downloadgitlab-ce-0ad8135c1feeefa23ec883e409fb65b8b52882a1.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared/components/markdown')
-rw-r--r--spec/frontend/vue_shared/components/markdown/markdown_editor_spec.js81
1 files changed, 63 insertions, 18 deletions
diff --git a/spec/frontend/vue_shared/components/markdown/markdown_editor_spec.js b/spec/frontend/vue_shared/components/markdown/markdown_editor_spec.js
index 8cb773ddfa3..681ff6c8dd3 100644
--- a/spec/frontend/vue_shared/components/markdown/markdown_editor_spec.js
+++ b/spec/frontend/vue_shared/components/markdown/markdown_editor_spec.js
@@ -63,6 +63,18 @@ describe('vue_shared/component/markdown/markdown_editor', () => {
const findLocalStorageSync = () => wrapper.findComponent(LocalStorageSync);
const findContentEditor = () => wrapper.findComponent(ContentEditor);
+ const enableContentEditor = async () => {
+ findMarkdownField().vm.$emit('enableContentEditor');
+ await nextTick();
+ await waitForPromises();
+ };
+
+ const enableMarkdownEditor = async () => {
+ findContentEditor().vm.$emit('enableMarkdownEditor');
+ await nextTick();
+ await waitForPromises();
+ };
+
beforeEach(() => {
window.uploads_path = 'uploads';
mock = new MockAdapter(axios);
@@ -90,6 +102,18 @@ describe('vue_shared/component/markdown/markdown_editor', () => {
});
});
+ it('enables content editor switcher when contentEditorEnabled prop is true', () => {
+ buildWrapper({ propsData: { enableContentEditor: true } });
+
+ expect(findMarkdownField().text()).toContain('Rich text');
+ });
+
+ it('hides content editor switcher when contentEditorEnabled prop is false', () => {
+ buildWrapper({ propsData: { enableContentEditor: false } });
+
+ expect(findMarkdownField().text()).not.toContain('Rich text');
+ });
+
it('passes down any additional props to markdown field component', () => {
const propsData = {
line: { text: 'hello world', richText: 'hello world' },
@@ -110,6 +134,36 @@ describe('vue_shared/component/markdown/markdown_editor', () => {
});
});
+ describe('disabled', () => {
+ it('disables markdown field when disabled prop is true', () => {
+ buildWrapper({ propsData: { disabled: true } });
+
+ expect(findMarkdownField().find('textarea').attributes('disabled')).toBe('disabled');
+ });
+
+ it('enables markdown field when disabled prop is false', () => {
+ buildWrapper({ propsData: { disabled: false } });
+
+ expect(findMarkdownField().find('textarea').attributes('disabled')).toBe(undefined);
+ });
+
+ it('disables content editor when disabled prop is true', async () => {
+ buildWrapper({ propsData: { disabled: true } });
+
+ await enableContentEditor();
+
+ expect(findContentEditor().props('editable')).toBe(false);
+ });
+
+ it('enables content editor when disabled prop is false', async () => {
+ buildWrapper({ propsData: { disabled: false } });
+
+ await enableContentEditor();
+
+ expect(findContentEditor().props('editable')).toBe(true);
+ });
+ });
+
describe('autosize', () => {
it('autosizes the textarea when the value changes', async () => {
buildWrapper();
@@ -129,12 +183,10 @@ describe('vue_shared/component/markdown/markdown_editor', () => {
it('does not autosize the textarea if markdown editor is disabled', async () => {
buildWrapper();
- findMarkdownField().vm.$emit('enableContentEditor');
+ await enableContentEditor();
wrapper.setProps({ value: 'Lots of newlines\n\n\n\n\n\n\nMore content\n\n\nand newlines' });
- await nextTick();
- await waitForPromises();
expect(Autosize.update).not.toHaveBeenCalled();
});
});
@@ -200,9 +252,7 @@ describe('vue_shared/component/markdown/markdown_editor', () => {
it(`emits ${EDITING_MODE_CONTENT_EDITOR} event when enableContentEditor emitted from markdown editor`, async () => {
buildWrapper();
- findMarkdownField().vm.$emit('enableContentEditor');
-
- await nextTick();
+ await enableContentEditor();
expect(wrapper.emitted(EDITING_MODE_CONTENT_EDITOR)).toHaveLength(1);
});
@@ -212,11 +262,8 @@ describe('vue_shared/component/markdown/markdown_editor', () => {
stubs: { ContentEditor: stubComponent(ContentEditor) },
});
- findMarkdownField().vm.$emit('enableContentEditor');
-
- await nextTick();
-
- findContentEditor().vm.$emit('enableMarkdownEditor');
+ await enableContentEditor();
+ await enableMarkdownEditor();
expect(wrapper.emitted(EDITING_MODE_MARKDOWN_FIELD)).toHaveLength(1);
});
@@ -262,9 +309,9 @@ describe('vue_shared/component/markdown/markdown_editor', () => {
});
describe(`when markdown field triggers enableContentEditor event`, () => {
- beforeEach(() => {
+ beforeEach(async () => {
buildWrapper();
- findMarkdownField().vm.$emit('enableContentEditor');
+ await enableContentEditor();
});
it('displays the content editor', () => {
@@ -300,9 +347,9 @@ describe('vue_shared/component/markdown/markdown_editor', () => {
});
describe(`when editingMode is ${EDITING_MODE_CONTENT_EDITOR}`, () => {
- beforeEach(() => {
+ beforeEach(async () => {
buildWrapper({ propsData: { autosaveKey: 'issue/1234' } });
- findMarkdownField().vm.$emit('enableContentEditor');
+ await enableContentEditor();
});
describe('when autofocus is true', () => {
@@ -343,9 +390,7 @@ describe('vue_shared/component/markdown/markdown_editor', () => {
});
describe(`when richText editor triggers enableMarkdownEditor event`, () => {
- beforeEach(() => {
- findContentEditor().vm.$emit('enableMarkdownEditor');
- });
+ beforeEach(enableMarkdownEditor);
it('hides the content editor', () => {
expect(findContentEditor().exists()).toBe(false);