|
16 | 16 |
|
17 | 17 | import { shallowMount } from '@vue/test-utils';
|
18 | 18 | import { CancellablePromise } from 'api/cancellablePromise';
|
| 19 | +import Executor from 'apps/editor/execution/executor'; |
19 | 20 | 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'; |
20 | 25 | import AceEditor from './AceEditor.vue';
|
21 | 26 |
|
22 | 27 | 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 | + |
23 | 41 | it('should render', () => {
|
24 | 42 | spyOn(dataCatalog, 'getChildren').and.returnValue(CancellablePromise.resolve([]));
|
25 | 43 |
|
26 | 44 | const wrapper = shallowMount(AceEditor, {
|
27 |
| - propsData: { |
| 45 | + props: { |
28 | 46 | value: 'some query',
|
29 | 47 | 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 |
42 | 49 | }
|
43 | 50 | });
|
44 | 51 | expect(wrapper.element).toMatchSnapshot();
|
45 | 52 | });
|
| 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 | + }); |
46 | 107 | });
|
0 commit comments