Commit 3f1cbee6 authored by Miguel Rincon's avatar Miguel Rincon

Merge branch '270095-editor-lite-cursor' into 'master'

Fixing the recursive update of the Editor Lite

See merge request gitlab-org/gitlab!45546
parents 0518cd09 d9200f19
...@@ -58,7 +58,9 @@ export default { ...@@ -58,7 +58,9 @@ export default {
this.editor.updateModelLanguage(newVal); this.editor.updateModelLanguage(newVal);
}, },
value(newVal) { value(newVal) {
if (this.editor.getValue() !== newVal) {
this.editor.setValue(newVal); this.editor.setValue(newVal);
}
}, },
}, },
mounted() { mounted() {
......
...@@ -96,17 +96,6 @@ describe('Editor Lite component', () => { ...@@ -96,17 +96,6 @@ 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));
}); });
...@@ -127,5 +116,29 @@ describe('Editor Lite component', () => { ...@@ -127,5 +116,29 @@ describe('Editor Lite component', () => {
expect(wrapper.emitted()['editor-ready']).toBeDefined(); expect(wrapper.emitted()['editor-ready']).toBeDefined();
}); });
describe('reaction to the value update', () => {
it('reacts to the changes in the passed value', async () => {
const newValue = 'New Value';
wrapper.setProps({
value: newValue,
});
await nextTick();
expect(setValue).toHaveBeenCalledWith(newValue);
});
it("does not update value if the passed one is exactly the same as the editor's content", async () => {
const newValue = `${value}`; // to make sure we're creating a new String with the same content and not just a reference
wrapper.setProps({
value: newValue,
});
await nextTick();
expect(setValue).not.toHaveBeenCalled();
});
});
}); });
}); });
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