Skip to content

Commit 4dc127d

Browse files
committed
[editor] Fix drag and drop from assist to the AceEditor component in editor v2
1 parent a130ab6 commit 4dc127d

File tree

2 files changed

+484
-442
lines changed

2 files changed

+484
-442
lines changed

desktop/core/src/desktop/js/apps/editor/components/aceEditor/AceEditor.test.ts

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,92 @@
1616

1717
import { shallowMount } from '@vue/test-utils';
1818
import { CancellablePromise } from 'api/cancellablePromise';
19+
import Executor from 'apps/editor/execution/executor';
1920
import dataCatalog from 'catalog/dataCatalog';
21+
import { Ace } from 'ext/ace';
22+
import { INSERT_AT_CURSOR_EVENT } from 'ko/bindings/ace/ko.aceEditor';
23+
import huePubSub from 'utils/huePubSub';
24+
import { nextTick } from 'vue';
2025
import AceEditor from './AceEditor.vue';
2126

2227
describe('AceEditor.vue', () => {
28+
const mockExecutor = ({
29+
connector: ko.observable({
30+
dialect: 'foo',
31+
id: 'foo'
32+
}),
33+
namespace: ko.observable({
34+
id: 'foo'
35+
}),
36+
compute: ko.observable({
37+
id: 'foo'
38+
})
39+
} as unknown) as Executor;
40+
2341
it('should render', () => {
2442
spyOn(dataCatalog, 'getChildren').and.returnValue(CancellablePromise.resolve([]));
2543

2644
const wrapper = shallowMount(AceEditor, {
27-
propsData: {
45+
props: {
2846
value: 'some query',
2947
id: 'some-id',
30-
executor: {
31-
connector: ko.observable({
32-
dialect: 'foo',
33-
id: 'foo'
34-
}),
35-
namespace: ko.observable({
36-
id: 'foo'
37-
}),
38-
compute: ko.observable({
39-
id: 'foo'
40-
})
41-
}
48+
executor: mockExecutor
4249
}
4350
});
4451
expect(wrapper.element).toMatchSnapshot();
4552
});
53+
54+
it('should handle drag and drop pubsub event targeting this editor', async () => {
55+
spyOn(dataCatalog, 'getChildren').and.returnValue(CancellablePromise.resolve([]));
56+
57+
const wrapper = shallowMount(AceEditor, {
58+
props: {
59+
value: '',
60+
id: 'some-id',
61+
executor: mockExecutor
62+
}
63+
});
64+
65+
await nextTick();
66+
67+
expect(wrapper.emitted()['ace-created']).toBeTruthy();
68+
69+
const editor = (wrapper.emitted()['ace-created'][0] as Ace.Editor[])[0];
70+
71+
const draggedText = 'Some dropped text';
72+
huePubSub.publish(INSERT_AT_CURSOR_EVENT, {
73+
text: draggedText,
74+
targetEditor: editor,
75+
cursorEndAdjust: 0
76+
});
77+
78+
expect(editor.getValue()).toEqual(draggedText);
79+
});
80+
81+
it('should not handle drag and drop pubsub event targeting another editor', async () => {
82+
spyOn(dataCatalog, 'getChildren').and.returnValue(CancellablePromise.resolve([]));
83+
84+
const wrapper = shallowMount(AceEditor, {
85+
props: {
86+
value: '',
87+
id: 'some-id',
88+
executor: mockExecutor
89+
}
90+
});
91+
92+
await nextTick();
93+
94+
expect(wrapper.emitted()['ace-created']).toBeTruthy();
95+
96+
const editor = (wrapper.emitted()['ace-created'][0] as Ace.Editor[])[0];
97+
98+
const draggedText = 'Some dropped text';
99+
huePubSub.publish(INSERT_AT_CURSOR_EVENT, {
100+
text: draggedText,
101+
targetEditor: {}, // Other instance
102+
cursorEndAdjust: 0
103+
});
104+
105+
expect(editor.getValue()).not.toEqual(draggedText);
106+
});
46107
});

0 commit comments

Comments
 (0)