1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
import { mount } from '@vue/test-utils';
import { Document } from 'yaml';
import YamlEditor from '~/pipeline_wizard/components/editor.vue';
describe('Pages Yaml Editor wrapper', () => {
let wrapper;
const defaultOptions = {
propsData: { doc: new Document({ foo: 'bar' }), filename: 'foo.yml' },
};
describe('mount hook', () => {
beforeEach(() => {
wrapper = mount(YamlEditor, defaultOptions);
});
it('editor is mounted', () => {
expect(wrapper.vm.editor).not.toBeUndefined();
expect(wrapper.find('.gl-source-editor').exists()).toBe(true);
});
});
describe('watchers', () => {
describe('doc', () => {
const doc = new Document({ baz: ['bar'] });
beforeEach(() => {
wrapper = mount(YamlEditor, defaultOptions);
});
it("causes the editor's value to be set to the stringified document", async () => {
await wrapper.setProps({ doc });
expect(wrapper.vm.editor.getValue()).toEqual(doc.toString());
});
it('emits an update:yaml event with the yaml representation of doc', async () => {
await wrapper.setProps({ doc });
const changeEvents = wrapper.emitted('update:yaml');
expect(changeEvents[2]).toEqual([doc.toString()]);
});
it('does not cause the touch event to be emitted', () => {
wrapper.setProps({ doc });
expect(wrapper.emitted('touch')).toBeUndefined();
});
});
describe('highlight', () => {
const highlight = 'foo';
beforeEach(() => {
wrapper = mount(YamlEditor, defaultOptions);
});
it('calls editor.highlight(path, keep=true)', async () => {
const highlightSpy = jest.spyOn(wrapper.vm.yamlEditorExtension.obj, 'highlight');
await wrapper.setProps({ highlight });
expect(highlightSpy).toHaveBeenCalledWith(expect.anything(), highlight, true);
});
});
});
});
|