diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/frontend/editor | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) | |
download | gitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/frontend/editor')
-rw-r--r-- | spec/frontend/editor/editor_ci_schema_ext_spec.js | 107 | ||||
-rw-r--r-- | spec/frontend/editor/editor_lite_extension_base_spec.js | 4 | ||||
-rw-r--r-- | spec/frontend/editor/editor_lite_spec.js | 14 | ||||
-rw-r--r-- | spec/frontend/editor/editor_markdown_ext_spec.js | 4 |
4 files changed, 118 insertions, 11 deletions
diff --git a/spec/frontend/editor/editor_ci_schema_ext_spec.js b/spec/frontend/editor/editor_ci_schema_ext_spec.js new file mode 100644 index 00000000000..9dd88aad7e6 --- /dev/null +++ b/spec/frontend/editor/editor_ci_schema_ext_spec.js @@ -0,0 +1,107 @@ +import { languages } from 'monaco-editor'; +import { TEST_HOST } from 'helpers/test_constants'; +import EditorLite from '~/editor/editor_lite'; +import { CiSchemaExtension } from '~/editor/extensions/editor_ci_schema_ext'; +import { EXTENSION_CI_SCHEMA_FILE_NAME_MATCH } from '~/editor/constants'; + +describe('~/editor/editor_ci_config_ext', () => { + const defaultBlobPath = '.gitlab-ci.yml'; + + let editor; + let instance; + let editorEl; + let originalGitlabUrl; + + const createMockEditor = ({ blobPath = defaultBlobPath } = {}) => { + setFixtures('<div id="editor"></div>'); + editorEl = document.getElementById('editor'); + editor = new EditorLite(); + instance = editor.createInstance({ + el: editorEl, + blobPath, + blobContent: '', + }); + instance.use(new CiSchemaExtension()); + }; + + beforeAll(() => { + originalGitlabUrl = gon.gitlab_url; + gon.gitlab_url = TEST_HOST; + }); + + afterAll(() => { + gon.gitlab_url = originalGitlabUrl; + }); + + beforeEach(() => { + createMockEditor(); + }); + + afterEach(() => { + instance.dispose(); + editorEl.remove(); + }); + + describe('registerCiSchema', () => { + beforeEach(() => { + jest.spyOn(languages.yaml.yamlDefaults, 'setDiagnosticsOptions'); + }); + + describe('register validations options with monaco for yaml language', () => { + const mockProjectNamespace = 'namespace1'; + const mockProjectPath = 'project1'; + + const getConfiguredYmlSchema = () => { + return languages.yaml.yamlDefaults.setDiagnosticsOptions.mock.calls[0][0].schemas[0]; + }; + + it('with expected basic validation configuration', () => { + instance.registerCiSchema({ + projectNamespace: mockProjectNamespace, + projectPath: mockProjectPath, + }); + + const expectedOptions = { + validate: true, + enableSchemaRequest: true, + hover: true, + completion: true, + }; + + expect(languages.yaml.yamlDefaults.setDiagnosticsOptions).toHaveBeenCalledTimes(1); + expect(languages.yaml.yamlDefaults.setDiagnosticsOptions).toHaveBeenCalledWith( + expect.objectContaining(expectedOptions), + ); + }); + + it('with an schema uri that contains project and ref', () => { + const mockRef = 'AABBCCDD'; + + instance.registerCiSchema({ + projectNamespace: mockProjectNamespace, + projectPath: mockProjectPath, + ref: mockRef, + }); + + expect(getConfiguredYmlSchema()).toEqual({ + uri: `${TEST_HOST}/${mockProjectNamespace}/${mockProjectPath}/-/schema/${mockRef}/${EXTENSION_CI_SCHEMA_FILE_NAME_MATCH}`, + fileMatch: [defaultBlobPath], + }); + }); + + it('with an alternative file name match', () => { + createMockEditor({ blobPath: 'dir1/dir2/another-ci-filename.yml' }); + + instance.registerCiSchema({ + projectNamespace: mockProjectNamespace, + projectPath: mockProjectPath, + }); + + expect(getConfiguredYmlSchema()).toEqual({ + uri: `${TEST_HOST}/${mockProjectNamespace}/${mockProjectPath}/-/schema/master/${EXTENSION_CI_SCHEMA_FILE_NAME_MATCH}`, + fileMatch: ['another-ci-filename.yml'], + }); + }); + }); + }); +}); diff --git a/spec/frontend/editor/editor_lite_extension_base_spec.js b/spec/frontend/editor/editor_lite_extension_base_spec.js index ff53640b096..5490e9dc7b5 100644 --- a/spec/frontend/editor/editor_lite_extension_base_spec.js +++ b/spec/frontend/editor/editor_lite_extension_base_spec.js @@ -1,5 +1,5 @@ import { ERROR_INSTANCE_REQUIRED_FOR_EXTENSION } from '~/editor/constants'; -import { EditorLiteExtension } from '~/editor/editor_lite_extension_base'; +import { EditorLiteExtension } from '~/editor/extensions/editor_lite_extension_base'; describe('The basis for an Editor Lite extension', () => { let ext; @@ -16,7 +16,7 @@ describe('The basis for an Editor Lite extension', () => { if (instance) { if (options) { - Object.entries(options).forEach(prop => { + Object.entries(options).forEach((prop) => { expect(instance[prop]).toBeUndefined(); }); // Both instance and options are passed diff --git a/spec/frontend/editor/editor_lite_spec.js b/spec/frontend/editor/editor_lite_spec.js index 3a7680f6d17..c3099997287 100644 --- a/spec/frontend/editor/editor_lite_spec.js +++ b/spec/frontend/editor/editor_lite_spec.js @@ -2,7 +2,7 @@ import { editor as monacoEditor, languages as monacoLanguages, Uri } from 'monaco-editor'; import waitForPromises from 'helpers/wait_for_promises'; import Editor from '~/editor/editor_lite'; -import { EditorLiteExtension } from '~/editor/editor_lite_extension_base'; +import { EditorLiteExtension } from '~/editor/extensions/editor_lite_extension_base'; import { DEFAULT_THEME, themes } from '~/ide/lib/themes'; import { EDITOR_LITE_INSTANCE_ERROR_NO_EL, URI_PREFIX } from '~/editor/constants'; @@ -324,13 +324,13 @@ describe('Base editor', () => { ${'multiple simple objects'} | ${[FooObjExt, BarObjExt]} | ${['foo', 'bar']} | ${[fooRes, barRes]} ${'combination of ES6 classes and objects'} | ${[AlphaExt, BarObjExt]} | ${['alpha', 'bar']} | ${[alphaRes, barRes]} `('is extensible with $type', ({ extensions, methods, expectations } = {}) => { - methods.forEach(method => { + methods.forEach((method) => { expect(instance[method]).toBeUndefined(); }); instance.use(extensions); - methods.forEach(method => { + methods.forEach((method) => { expect(instance[method]).toBeDefined(); }); @@ -359,7 +359,7 @@ describe('Base editor', () => { it.each([WithStaticMethod, WithStaticMethodExtended])( 'properly resolves data for an extension with private data', - ExtClass => { + (ExtClass) => { const base = 1; expect(instance.base).toBeUndefined(); expect(instance.boo).toBeUndefined(); @@ -408,7 +408,7 @@ describe('Base editor', () => { }; beforeEach(() => { - editorExtensionSpy = jest.spyOn(Editor, 'pushToImportsArray').mockImplementation(arr => { + editorExtensionSpy = jest.spyOn(Editor, 'pushToImportsArray').mockImplementation((arr) => { arr.push( Promise.resolve({ default: {}, @@ -524,7 +524,7 @@ describe('Base editor', () => { }); it('sets default syntax highlighting theme', () => { - const expectedTheme = themes.find(t => t.name === DEFAULT_THEME); + const expectedTheme = themes.find((t) => t.name === DEFAULT_THEME); editor = new Editor(); @@ -533,7 +533,7 @@ describe('Base editor', () => { }); it('sets correct theme if it is set in users preferences', () => { - const expectedTheme = themes.find(t => t.name !== DEFAULT_THEME); + const expectedTheme = themes.find((t) => t.name !== DEFAULT_THEME); expect(expectedTheme.name).not.toBe(DEFAULT_THEME); diff --git a/spec/frontend/editor/editor_markdown_ext_spec.js b/spec/frontend/editor/editor_markdown_ext_spec.js index b432d4d66ad..3f64dcfd7a0 100644 --- a/spec/frontend/editor/editor_markdown_ext_spec.js +++ b/spec/frontend/editor/editor_markdown_ext_spec.js @@ -1,6 +1,6 @@ import { Range, Position } from 'monaco-editor'; import EditorLite from '~/editor/editor_lite'; -import { EditorMarkdownExtension } from '~/editor/editor_markdown_ext'; +import { EditorMarkdownExtension } from '~/editor/extensions/editor_markdown_ext'; describe('Markdown Extension for Editor Lite', () => { let editor; @@ -114,7 +114,7 @@ describe('Markdown Extension for Editor Lite', () => { }); describe('moveCursor', () => { - const setPosition = endCol => { + const setPosition = (endCol) => { const currentPos = new Position(2, endCol); instance.setPosition(currentPos); }; |