Commit e96ae9be authored by Denys Mishunov's avatar Denys Mishunov

Udpating the specs

Some spoecs needed to be updated to match the API being moved
to instance instead of the root editor
parent 77146a4c
import { editor as monacoEditor, languages as monacoLanguages, Position, Uri } from 'monaco-editor'; import { editor as monacoEditor, languages as monacoLanguages, Uri } from 'monaco-editor';
import { DEFAULT_THEME, themes } from '~/ide/lib/themes'; import { DEFAULT_THEME, themes } from '~/ide/lib/themes';
import languages from '~/ide/lib/languages'; import languages from '~/ide/lib/languages';
import { defaultEditorOptions } from '~/ide/lib/editor_options'; import { defaultEditorOptions } from '~/ide/lib/editor_options';
......
...@@ -6,10 +6,12 @@ jest.mock('~/editor/editor_lite'); ...@@ -6,10 +6,12 @@ jest.mock('~/editor/editor_lite');
jest.mock('~/editor/editor_markdown_ext'); jest.mock('~/editor/editor_markdown_ext');
describe('Blob Editing', () => { describe('Blob Editing', () => {
const mockInstance = 'foo';
beforeEach(() => { beforeEach(() => {
setFixtures( setFixtures(
`<div class="js-edit-blob-form"><div id="file_path"></div><div id="iditor"></div><input id="file-content"></div>`, `<div class="js-edit-blob-form"><div id="file_path"></div><div id="editor"></div><input id="file-content"></div>`,
); );
jest.spyOn(EditorLite.prototype, 'createInstance').mockReturnValue(mockInstance);
}); });
const initEditor = (isMarkdown = false) => { const initEditor = (isMarkdown = false) => {
...@@ -26,6 +28,6 @@ describe('Blob Editing', () => { ...@@ -26,6 +28,6 @@ describe('Blob Editing', () => {
it('loads MarkdownExtension only for the markdown files', async () => { it('loads MarkdownExtension only for the markdown files', async () => {
await initEditor(true); await initEditor(true);
expect(EditorLite.prototype.use).toHaveBeenCalledWith(MarkdownExtension); expect(EditorLite.prototype.use).toHaveBeenCalledWith(MarkdownExtension, mockInstance);
}); });
}); });
...@@ -78,18 +78,18 @@ describe('Markdown Extension for Editor Lite', () => { ...@@ -78,18 +78,18 @@ describe('Markdown Extension for Editor Lite', () => {
selectSecondString(); selectSecondString();
instance.replaceSelectedText(expectedStr); instance.replaceSelectedText(expectedStr);
expect(editor.getValue()).toBe(`${firstLine}\n${expectedStr}\n${thirdLine}`); expect(instance.getValue()).toBe(`${firstLine}\n${expectedStr}\n${thirdLine}`);
}); });
it('prepends the supplied text if no text is selected', () => { it('prepends the supplied text if no text is selected', () => {
instance.replaceSelectedText(expectedStr); instance.replaceSelectedText(expectedStr);
expect(editor.getValue()).toBe(`${expectedStr}${firstLine}\n${secondLine}\n${thirdLine}`); expect(instance.getValue()).toBe(`${expectedStr}${firstLine}\n${secondLine}\n${thirdLine}`);
}); });
it('replaces selection with empty string if no text is supplied', () => { it('replaces selection with empty string if no text is supplied', () => {
selectSecondString(); selectSecondString();
instance.replaceSelectedText(); instance.replaceSelectedText();
expect(editor.getValue()).toBe(`${firstLine}\n\n${thirdLine}`); expect(instance.getValue()).toBe(`${firstLine}\n\n${thirdLine}`);
}); });
it('puts cursor at the end of the new string and collapses selection by default', () => { it('puts cursor at the end of the new string and collapses selection by default', () => {
......
...@@ -15,11 +15,13 @@ describe('Snippet editor', () => { ...@@ -15,11 +15,13 @@ describe('Snippet editor', () => {
const updatedMockContent = 'New Foo Bar'; const updatedMockContent = 'New Foo Bar';
const mockEditor = { const mockEditor = {
createInstance: jest.fn(),
updateModelLanguage: jest.fn(), updateModelLanguage: jest.fn(),
getValue: jest.fn().mockReturnValueOnce(updatedMockContent), getValue: jest.fn().mockReturnValueOnce(updatedMockContent),
}; };
Editor.mockImplementation(() => mockEditor); const createInstance = jest.fn().mockImplementation(() => ({ ...mockEditor }));
Editor.mockImplementation(() => ({
createInstance,
}));
function setUpFixture(name, content) { function setUpFixture(name, content) {
setHTMLFixture(` setHTMLFixture(`
...@@ -56,7 +58,7 @@ describe('Snippet editor', () => { ...@@ -56,7 +58,7 @@ describe('Snippet editor', () => {
}); });
it('correctly initializes Editor', () => { it('correctly initializes Editor', () => {
expect(mockEditor.createInstance).toHaveBeenCalledWith({ expect(createInstance).toHaveBeenCalledWith({
el: editorEl, el: editorEl,
blobPath: mockName, blobPath: mockName,
blobContent: mockContent, blobContent: mockContent,
......
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