Commit 7ba4cc53 authored by Denys Mishunov's avatar Denys Mishunov

React to value changes on the component

parent c198b964
...@@ -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({
......
...@@ -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(() => {
...@@ -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));
}); });
......
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