diff options
Diffstat (limited to 'spec/frontend/editor/editor_lite_spec.js')
-rw-r--r-- | spec/frontend/editor/editor_lite_spec.js | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/spec/frontend/editor/editor_lite_spec.js b/spec/frontend/editor/editor_lite_spec.js index 92a136835bf..e4edeab172b 100644 --- a/spec/frontend/editor/editor_lite_spec.js +++ b/spec/frontend/editor/editor_lite_spec.js @@ -2,13 +2,15 @@ import { editor as monacoEditor, languages as monacoLanguages, Uri } from 'monac import Editor from '~/editor/editor_lite'; import { DEFAULT_THEME, themes } from '~/ide/lib/themes'; +const URI_PREFIX = 'gitlab'; + describe('Base editor', () => { let editorEl; let editor; const blobContent = 'Foo Bar'; const blobPath = 'test.md'; - const uri = new Uri('gitlab', false, blobPath); - const fakeModel = { foo: 'bar' }; + const blobGlobalId = 'snippet_777'; + const fakeModel = { foo: 'bar', dispose: jest.fn() }; beforeEach(() => { setFixtures('<div id="editor" data-editor-loading></div>'); @@ -21,6 +23,8 @@ describe('Base editor', () => { editorEl.remove(); }); + const createUri = (...paths) => Uri.file([URI_PREFIX, ...paths].join('/')); + it('initializes Editor with basic properties', () => { expect(editor).toBeDefined(); expect(editor.editorEl).toBe(null); @@ -65,7 +69,7 @@ describe('Base editor', () => { it('creates model to be supplied to Monaco editor', () => { editor.createInstance({ el: editorEl, blobPath, blobContent }); - expect(modelSpy).toHaveBeenCalledWith(blobContent, undefined, uri); + expect(modelSpy).toHaveBeenCalledWith(blobContent, undefined, createUri(blobPath)); expect(setModel).toHaveBeenCalledWith(fakeModel); }); @@ -75,6 +79,16 @@ describe('Base editor', () => { expect(editor.editorEl).not.toBe(null); expect(instanceSpy).toHaveBeenCalledWith(editorEl, expect.anything()); }); + + it('with blobGlobalId, creates model with id in uri', () => { + editor.createInstance({ el: editorEl, blobPath, blobContent, blobGlobalId }); + + expect(modelSpy).toHaveBeenCalledWith( + blobContent, + undefined, + createUri(blobGlobalId, blobPath), + ); + }); }); describe('implementation', () => { @@ -82,10 +96,6 @@ describe('Base editor', () => { editor.createInstance({ el: editorEl, blobPath, blobContent }); }); - afterEach(() => { - editor.model.dispose(); - }); - it('correctly proxies value from the model', () => { expect(editor.getValue()).toEqual(blobContent); }); @@ -132,10 +142,6 @@ describe('Base editor', () => { editor.createInstance({ el: editorEl, blobPath, blobContent }); }); - afterEach(() => { - editor.model.dispose(); - }); - it('is extensible with the extensions', () => { expect(editor.foo).toBeUndefined(); |