2022-04-04 11:22:00 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { Document } from 'yaml';
|
|
|
|
import YamlEditor from '~/pipeline_wizard/components/editor.vue';
|
|
|
|
|
|
|
|
describe('Pages Yaml Editor wrapper', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
let wrapper;
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
const defaultOptions = {
|
|
|
|
propsData: { doc: new Document({ foo: 'bar' }), filename: 'foo.yml' },
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('mount hook', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = mount(YamlEditor, defaultOptions);
|
|
|
|
});
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
it('editor is mounted', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.vm.editor).not.toBeUndefined();
|
2022-04-04 11:22:00 +05:30
|
|
|
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 });
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.emitted('touch')).toBeUndefined();
|
2022-04-04 11:22:00 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('highlight', () => {
|
|
|
|
const highlight = 'foo';
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = mount(YamlEditor, defaultOptions);
|
|
|
|
});
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|