2021-01-29 00:20:46 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import EditorLite from '~/vue_shared/components/editor_lite.vue';
|
|
|
|
import { mockCiYml } from '../mock_data';
|
|
|
|
|
|
|
|
import TextEditor from '~/pipeline_editor/components/text_editor.vue';
|
|
|
|
|
|
|
|
describe('~/pipeline_editor/components/text_editor.vue', () => {
|
|
|
|
let wrapper;
|
2021-02-22 17:27:13 +05:30
|
|
|
const editorReadyListener = jest.fn();
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const createComponent = (attrs = {}, mountFn = shallowMount) => {
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = mountFn(TextEditor, {
|
2021-02-22 17:27:13 +05:30
|
|
|
attrs: {
|
2021-01-29 00:20:46 +05:30
|
|
|
value: mockCiYml,
|
2021-02-22 17:27:13 +05:30
|
|
|
...attrs,
|
|
|
|
},
|
|
|
|
listeners: {
|
|
|
|
'editor-ready': editorReadyListener,
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findEditor = () => wrapper.find(EditorLite);
|
|
|
|
|
|
|
|
it('contains an editor', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findEditor().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('editor contains the value provided', () => {
|
|
|
|
expect(findEditor().props('value')).toBe(mockCiYml);
|
|
|
|
});
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('editor is configured for .yml', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(findEditor().props('fileName')).toBe('*.yml');
|
|
|
|
});
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('bubbles up events', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
findEditor().vm.$emit('editor-ready');
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(editorReadyListener).toHaveBeenCalled();
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
});
|