Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[editor] Fix drag and drop from assist to the AceEditor component in …
…editor v2
  • Loading branch information
JohanAhlen committed Mar 10, 2021
1 parent a130ab6 commit 4dc127d
Show file tree
Hide file tree
Showing 2 changed files with 484 additions and 442 deletions.
Expand Up @@ -16,31 +16,92 @@

import { shallowMount } from '@vue/test-utils';
import { CancellablePromise } from 'api/cancellablePromise';
import Executor from 'apps/editor/execution/executor';
import dataCatalog from 'catalog/dataCatalog';
import { Ace } from 'ext/ace';
import { INSERT_AT_CURSOR_EVENT } from 'ko/bindings/ace/ko.aceEditor';
import huePubSub from 'utils/huePubSub';
import { nextTick } from 'vue';
import AceEditor from './AceEditor.vue';

describe('AceEditor.vue', () => {
const mockExecutor = ({
connector: ko.observable({
dialect: 'foo',
id: 'foo'
}),
namespace: ko.observable({
id: 'foo'
}),
compute: ko.observable({
id: 'foo'
})
} as unknown) as Executor;

it('should render', () => {
spyOn(dataCatalog, 'getChildren').and.returnValue(CancellablePromise.resolve([]));

const wrapper = shallowMount(AceEditor, {
propsData: {
props: {
value: 'some query',
id: 'some-id',
executor: {
connector: ko.observable({
dialect: 'foo',
id: 'foo'
}),
namespace: ko.observable({
id: 'foo'
}),
compute: ko.observable({
id: 'foo'
})
}
executor: mockExecutor
}
});
expect(wrapper.element).toMatchSnapshot();
});

it('should handle drag and drop pubsub event targeting this editor', async () => {
spyOn(dataCatalog, 'getChildren').and.returnValue(CancellablePromise.resolve([]));

const wrapper = shallowMount(AceEditor, {
props: {
value: '',
id: 'some-id',
executor: mockExecutor
}
});

await nextTick();

expect(wrapper.emitted()['ace-created']).toBeTruthy();

const editor = (wrapper.emitted()['ace-created'][0] as Ace.Editor[])[0];

const draggedText = 'Some dropped text';
huePubSub.publish(INSERT_AT_CURSOR_EVENT, {
text: draggedText,
targetEditor: editor,
cursorEndAdjust: 0
});

expect(editor.getValue()).toEqual(draggedText);
});

it('should not handle drag and drop pubsub event targeting another editor', async () => {
spyOn(dataCatalog, 'getChildren').and.returnValue(CancellablePromise.resolve([]));

const wrapper = shallowMount(AceEditor, {
props: {
value: '',
id: 'some-id',
executor: mockExecutor
}
});

await nextTick();

expect(wrapper.emitted()['ace-created']).toBeTruthy();

const editor = (wrapper.emitted()['ace-created'][0] as Ace.Editor[])[0];

const draggedText = 'Some dropped text';
huePubSub.publish(INSERT_AT_CURSOR_EVENT, {
text: draggedText,
targetEditor: {}, // Other instance
cursorEndAdjust: 0
});

expect(editor.getValue()).not.toEqual(draggedText);
});
});

0 comments on commit 4dc127d

Please sign in to comment.