Commit 8710212e authored by Mireya Andres's avatar Mireya Andres Committed by Frédéric Caplette

Fix schema registration in the pipeline editor

Changelog: fixed
parent f3a1cbfc
...@@ -15,12 +15,10 @@ export default { ...@@ -15,12 +15,10 @@ export default {
onCiConfigUpdate(content) { onCiConfigUpdate(content) {
this.$emit('updateCiConfig', content); this.$emit('updateCiConfig', content);
}, },
registerCiSchema() { registerCiSchema({ detail: { instance } }) {
if (this.glFeatures.schemaLinting) { if (this.glFeatures.schemaLinting) {
const editorInstance = this.$refs.editor.getEditor(); instance.use({ definition: CiSchemaExtension });
instance.registerCiSchema();
editorInstance.use({ definition: CiSchemaExtension });
editorInstance.registerCiSchema();
} }
}, },
}, },
...@@ -33,7 +31,7 @@ export default { ...@@ -33,7 +31,7 @@ export default {
ref="editor" ref="editor"
:file-name="ciConfigPath" :file-name="ciConfigPath"
v-bind="$attrs" v-bind="$attrs"
@[$options.readyEvent]="registerCiSchema" @[$options.readyEvent]="registerCiSchema($event)"
@input="onCiConfigUpdate" @input="onCiConfigUpdate"
v-on="$listeners" v-on="$listeners"
/> />
......
...@@ -97,7 +97,7 @@ export default { ...@@ -97,7 +97,7 @@ export default {
ref="editor" ref="editor"
data-editor-loading data-editor-loading
data-qa-selector="source_editor_container" data-qa-selector="source_editor_container"
@[$options.readyEvent]="$emit($options.readyEvent)" @[$options.readyEvent]="$emit($options.readyEvent, $event)"
> >
<pre class="editor-loading-content">{{ value }}</pre> <pre class="editor-loading-content">{{ value }}</pre>
</div> </div>
......
...@@ -17,19 +17,12 @@ describe('Pipeline Editor | Text editor component', () => { ...@@ -17,19 +17,12 @@ describe('Pipeline Editor | Text editor component', () => {
let editorReadyListener; let editorReadyListener;
let mockUse; let mockUse;
let mockRegisterCiSchema; let mockRegisterCiSchema;
let mockEditorInstance;
let editorInstanceDetail;
const MockSourceEditor = { const MockSourceEditor = {
template: '<div/>', template: '<div/>',
props: ['value', 'fileName'], props: ['value', 'fileName'],
mounted() {
this.$emit(EDITOR_READY_EVENT);
},
methods: {
getEditor: () => ({
use: mockUse,
registerCiSchema: mockRegisterCiSchema,
}),
},
}; };
const createComponent = (glFeatures = {}, mountFn = shallowMount) => { const createComponent = (glFeatures = {}, mountFn = shallowMount) => {
...@@ -58,6 +51,21 @@ describe('Pipeline Editor | Text editor component', () => { ...@@ -58,6 +51,21 @@ describe('Pipeline Editor | Text editor component', () => {
const findEditor = () => wrapper.findComponent(MockSourceEditor); const findEditor = () => wrapper.findComponent(MockSourceEditor);
beforeEach(() => {
editorReadyListener = jest.fn();
mockUse = jest.fn();
mockRegisterCiSchema = jest.fn();
mockEditorInstance = {
use: mockUse,
registerCiSchema: mockRegisterCiSchema,
};
editorInstanceDetail = {
detail: {
instance: mockEditorInstance,
},
};
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -67,10 +75,6 @@ describe('Pipeline Editor | Text editor component', () => { ...@@ -67,10 +75,6 @@ describe('Pipeline Editor | Text editor component', () => {
describe('template', () => { describe('template', () => {
beforeEach(() => { beforeEach(() => {
editorReadyListener = jest.fn();
mockUse = jest.fn();
mockRegisterCiSchema = jest.fn();
createComponent(); createComponent();
}); });
...@@ -87,7 +91,7 @@ describe('Pipeline Editor | Text editor component', () => { ...@@ -87,7 +91,7 @@ describe('Pipeline Editor | Text editor component', () => {
}); });
it('bubbles up events', () => { it('bubbles up events', () => {
findEditor().vm.$emit(EDITOR_READY_EVENT); findEditor().vm.$emit(EDITOR_READY_EVENT, editorInstanceDetail);
expect(editorReadyListener).toHaveBeenCalled(); expect(editorReadyListener).toHaveBeenCalled();
}); });
...@@ -97,11 +101,7 @@ describe('Pipeline Editor | Text editor component', () => { ...@@ -97,11 +101,7 @@ describe('Pipeline Editor | Text editor component', () => {
describe('when `schema_linting` feature flag is on', () => { describe('when `schema_linting` feature flag is on', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ schemaLinting: true }); createComponent({ schemaLinting: true });
// Since the editor will have already mounted, the event will have fired. findEditor().vm.$emit(EDITOR_READY_EVENT, editorInstanceDetail);
// To ensure we properly test this, we clear the mock and re-remit the event.
mockRegisterCiSchema.mockClear();
mockUse.mockClear();
findEditor().vm.$emit(EDITOR_READY_EVENT);
}); });
it('configures editor with syntax highlight', () => { it('configures editor with syntax highlight', () => {
...@@ -113,7 +113,7 @@ describe('Pipeline Editor | Text editor component', () => { ...@@ -113,7 +113,7 @@ describe('Pipeline Editor | Text editor component', () => {
describe('when `schema_linting` feature flag is off', () => { describe('when `schema_linting` feature flag is off', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
findEditor().vm.$emit(EDITOR_READY_EVENT); findEditor().vm.$emit(EDITOR_READY_EVENT, editorInstanceDetail);
}); });
it('does not call the register CI schema function', () => { it('does not call the register CI schema function', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment