diff options
Diffstat (limited to 'spec/frontend/pipeline_editor/components/text_editor_spec.js')
-rw-r--r-- | spec/frontend/pipeline_editor/components/text_editor_spec.js | 67 |
1 files changed, 58 insertions, 9 deletions
diff --git a/spec/frontend/pipeline_editor/components/text_editor_spec.js b/spec/frontend/pipeline_editor/components/text_editor_spec.js index 18f71ebc95c..9221d64c44b 100644 --- a/spec/frontend/pipeline_editor/components/text_editor_spec.js +++ b/spec/frontend/pipeline_editor/components/text_editor_spec.js @@ -1,30 +1,69 @@ import { shallowMount } from '@vue/test-utils'; -import EditorLite from '~/vue_shared/components/editor_lite.vue'; -import { mockCiYml } from '../mock_data'; +import { + mockCiConfigPath, + mockCiYml, + mockCommitSha, + mockProjectPath, + mockProjectNamespace, +} from '../mock_data'; import TextEditor from '~/pipeline_editor/components/text_editor.vue'; describe('~/pipeline_editor/components/text_editor.vue', () => { let wrapper; - const editorReadyListener = jest.fn(); - const createComponent = (attrs = {}, mountFn = shallowMount) => { + let editorReadyListener; + let mockUse; + let mockRegisterCiSchema; + + const MockEditorLite = { + template: '<div/>', + props: ['value', 'fileName'], + mounted() { + this.$emit('editor-ready'); + }, + methods: { + getEditor: () => ({ + use: mockUse, + registerCiSchema: mockRegisterCiSchema, + }), + }, + }; + + const createComponent = (opts = {}, mountFn = shallowMount) => { wrapper = mountFn(TextEditor, { + provide: { + projectPath: mockProjectPath, + projectNamespace: mockProjectNamespace, + }, + propsData: { + ciConfigPath: mockCiConfigPath, + commitSha: mockCommitSha, + }, attrs: { value: mockCiYml, - ...attrs, }, listeners: { 'editor-ready': editorReadyListener, }, + stubs: { + EditorLite: MockEditorLite, + }, + ...opts, }); }; - const findEditor = () => wrapper.find(EditorLite); + const findEditor = () => wrapper.find(MockEditorLite); + + beforeEach(() => { + editorReadyListener = jest.fn(); + mockUse = jest.fn(); + mockRegisterCiSchema = jest.fn(); - it('contains an editor', () => { createComponent(); + }); + it('contains an editor', () => { expect(findEditor().exists()).toBe(true); }); @@ -32,8 +71,18 @@ describe('~/pipeline_editor/components/text_editor.vue', () => { expect(findEditor().props('value')).toBe(mockCiYml); }); - it('editor is configured for .yml', () => { - expect(findEditor().props('fileName')).toBe('*.yml'); + it('editor is configured for the CI config path', () => { + expect(findEditor().props('fileName')).toBe(mockCiConfigPath); + }); + + it('editor is configured with syntax highligting', async () => { + expect(mockUse).toHaveBeenCalledTimes(1); + expect(mockRegisterCiSchema).toHaveBeenCalledTimes(1); + expect(mockRegisterCiSchema).toHaveBeenCalledWith({ + projectNamespace: mockProjectNamespace, + projectPath: mockProjectPath, + ref: mockCommitSha, + }); }); it('bubbles up events', () => { |