Commit ce94b55f authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'dmishunov-editor-lite-reusability' into 'master'

Improve re-usability of Editor Lite

See merge request gitlab-org/gitlab!45083
parents 8f02467b e16a692a
...@@ -123,7 +123,7 @@ export default { ...@@ -123,7 +123,7 @@ export default {
}; };
</script> </script>
<template> <template>
<div class="form-group file-editor"> <div class="form-group">
<label :for="firstInputId">{{ s__('Snippets|Files') }}</label> <label :for="firstInputId">{{ s__('Snippets|Files') }}</label>
<snippet-blob-edit <snippet-blob-edit
v-for="(blobId, index) in blobIds" v-for="(blobId, index) in blobIds"
......
...@@ -57,6 +57,9 @@ export default { ...@@ -57,6 +57,9 @@ export default {
fileName(newVal) { fileName(newVal) {
this.editor.updateModelLanguage(newVal); this.editor.updateModelLanguage(newVal);
}, },
value(newVal) {
this.editor.setValue(newVal);
},
}, },
mounted() { mounted() {
this.editor = initEditorLite({ this.editor = initEditorLite({
...@@ -83,9 +86,12 @@ export default { ...@@ -83,9 +86,12 @@ export default {
}; };
</script> </script>
<template> <template>
<div class="file-content code"> <div
<div id="editor" ref="editor" data-editor-loading @editor-ready="$emit('editor-ready')"> :id="`editor-lite-${fileGlobalId}`"
<pre class="editor-loading-content">{{ value }}</pre> ref="editor"
</div> data-editor-loading
@editor-ready="$emit('editor-ready')"
>
<pre class="editor-loading-content">{{ value }}</pre>
</div> </div>
</template> </template>
.monaco-editor.gl-editor-lite { [id^='editor-lite-'] {
.line-numbers { height: 500px;
@include gl-pt-0;
}
} }
...@@ -79,7 +79,7 @@ module QA ...@@ -79,7 +79,7 @@ module QA
private private
def text_area def text_area
find('#editor textarea', visible: false) find('.monaco-editor textarea', visible: false)
end end
end end
end end
......
...@@ -26,7 +26,7 @@ module QA ...@@ -26,7 +26,7 @@ module QA
private private
def text_area def text_area
find('#editor textarea', visible: false) find('.monaco-editor textarea', visible: false)
end end
end end
end end
......
...@@ -2,17 +2,13 @@ ...@@ -2,17 +2,13 @@
exports[`Editor Lite component rendering matches the snapshot 1`] = ` exports[`Editor Lite component rendering matches the snapshot 1`] = `
<div <div
class="file-content code" data-editor-loading=""
id="editor-lite-snippet_777"
> >
<div <pre
data-editor-loading="" class="editor-loading-content"
id="editor"
> >
<pre Lorem ipsum dolor sit amet, consectetur adipiscing elit.
class="editor-loading-content" </pre>
>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</pre>
</div>
</div> </div>
`; `;
...@@ -10,6 +10,7 @@ describe('Editor Lite component', () => { ...@@ -10,6 +10,7 @@ describe('Editor Lite component', () => {
const onDidChangeModelContent = jest.fn(); const onDidChangeModelContent = jest.fn();
const updateModelLanguage = jest.fn(); const updateModelLanguage = jest.fn();
const getValue = jest.fn(); const getValue = jest.fn();
const setValue = jest.fn();
const value = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; const value = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
const fileName = 'lorem.txt'; const fileName = 'lorem.txt';
const fileGlobalId = 'snippet_777'; const fileGlobalId = 'snippet_777';
...@@ -17,6 +18,7 @@ describe('Editor Lite component', () => { ...@@ -17,6 +18,7 @@ describe('Editor Lite component', () => {
onDidChangeModelContent, onDidChangeModelContent,
updateModelLanguage, updateModelLanguage,
getValue, getValue,
setValue,
dispose: jest.fn(), dispose: jest.fn(),
})); }));
Editor.mockImplementation(() => { Editor.mockImplementation(() => {
...@@ -68,7 +70,7 @@ describe('Editor Lite component', () => { ...@@ -68,7 +70,7 @@ describe('Editor Lite component', () => {
createComponent({ value: undefined }); createComponent({ value: undefined });
expect(spy).not.toHaveBeenCalled(); expect(spy).not.toHaveBeenCalled();
expect(wrapper.find('#editor').exists()).toBe(true); expect(wrapper.find('[id^="editor-lite-"]').exists()).toBe(true);
}); });
it('initialises Editor Lite instance', () => { it('initialises Editor Lite instance', () => {
...@@ -94,6 +96,17 @@ describe('Editor Lite component', () => { ...@@ -94,6 +96,17 @@ describe('Editor Lite component', () => {
}); });
}); });
it('reacts to the changes in the pased value', async () => {
const newValue = 'New Value';
wrapper.setProps({
value: newValue,
});
await nextTick();
expect(setValue).toHaveBeenCalledWith(newValue);
});
it('registers callback with editor onChangeContent', () => { it('registers callback with editor onChangeContent', () => {
expect(onDidChangeModelContent).toHaveBeenCalledWith(expect.any(Function)); expect(onDidChangeModelContent).toHaveBeenCalledWith(expect.any(Function));
}); });
......
...@@ -31,7 +31,7 @@ module Spec ...@@ -31,7 +31,7 @@ module Spec
end end
def snippet_get_first_blob_value def snippet_get_first_blob_value
page.find('.file-content', match: :first) page.find('.gl-editor-lite', match: :first)
end end
def snippet_description_value def snippet_description_value
...@@ -53,7 +53,7 @@ module Spec ...@@ -53,7 +53,7 @@ module Spec
end end
def snippet_fill_in_content(value) def snippet_fill_in_content(value)
page.within('.file-editor') do page.within('.gl-editor-lite') do
el = find('.inputarea') el = find('.inputarea')
el.send_keys value el.send_keys value
end end
......
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