2018-06-08 01:09:59 -04:00
|
|
|
import { editor as monacoEditor } from 'monaco-editor';
|
2018-06-07 17:34:50 -04:00
|
|
|
import Editor from '~/ide/lib/editor';
|
2018-03-20 10:12:48 -04:00
|
|
|
import { file } from '../helpers';
|
|
|
|
|
|
|
|
describe('Multi-file editor library', () => {
|
|
|
|
let instance;
|
|
|
|
let el;
|
|
|
|
let holder;
|
|
|
|
|
2018-06-07 17:34:50 -04:00
|
|
|
beforeEach(() => {
|
2018-03-20 10:12:48 -04:00
|
|
|
el = document.createElement('div');
|
|
|
|
holder = document.createElement('div');
|
|
|
|
el.appendChild(holder);
|
|
|
|
|
|
|
|
document.body.appendChild(el);
|
|
|
|
|
2018-06-07 17:34:50 -04:00
|
|
|
instance = Editor.create();
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
instance.dispose();
|
|
|
|
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates instance of editor', () => {
|
2018-06-07 17:34:50 -04:00
|
|
|
expect(Editor.editorInstance).not.toBeNull();
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('creates instance returns cached instance', () => {
|
2018-06-07 17:34:50 -04:00
|
|
|
expect(Editor.create()).toEqual(instance);
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('createInstance', () => {
|
|
|
|
it('creates editor instance', () => {
|
2018-06-08 01:09:59 -04:00
|
|
|
spyOn(monacoEditor, 'create').and.callThrough();
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
instance.createInstance(holder);
|
|
|
|
|
2018-06-08 01:09:59 -04:00
|
|
|
expect(monacoEditor.create).toHaveBeenCalled();
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('creates dirty diff controller', () => {
|
|
|
|
instance.createInstance(holder);
|
|
|
|
|
|
|
|
expect(instance.dirtyDiffController).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates model manager', () => {
|
|
|
|
instance.createInstance(holder);
|
|
|
|
|
|
|
|
expect(instance.modelManager).not.toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createDiffInstance', () => {
|
|
|
|
it('creates editor instance', () => {
|
2018-06-08 01:09:59 -04:00
|
|
|
spyOn(monacoEditor, 'createDiffEditor').and.callThrough();
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
instance.createDiffInstance(holder);
|
|
|
|
|
2018-06-08 01:09:59 -04:00
|
|
|
expect(monacoEditor.createDiffEditor).toHaveBeenCalledWith(holder, {
|
2018-03-26 10:10:17 -04:00
|
|
|
model: null,
|
|
|
|
contextmenu: true,
|
|
|
|
minimap: {
|
|
|
|
enabled: false,
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
2018-05-01 05:46:28 -04:00
|
|
|
readOnly: true,
|
2018-03-26 10:10:17 -04:00
|
|
|
scrollBeyondLastLine: false,
|
2020-01-06 10:07:26 -05:00
|
|
|
renderWhitespace: 'none',
|
2018-03-26 10:10:17 -04:00
|
|
|
quickSuggestions: false,
|
|
|
|
occurrencesHighlight: false,
|
2018-04-01 11:47:10 -04:00
|
|
|
wordWrap: 'on',
|
2018-04-05 05:24:18 -04:00
|
|
|
renderSideBySide: true,
|
2018-05-01 05:46:28 -04:00
|
|
|
renderLineHighlight: 'all',
|
|
|
|
hideCursorInOverviewRuler: false,
|
2018-03-26 10:10:17 -04:00
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createModel', () => {
|
|
|
|
it('calls model manager addModel', () => {
|
|
|
|
spyOn(instance.modelManager, 'addModel');
|
|
|
|
|
|
|
|
instance.createModel('FILE');
|
|
|
|
|
2018-04-07 05:08:34 -04:00
|
|
|
expect(instance.modelManager.addModel).toHaveBeenCalledWith('FILE', null);
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('attachModel', () => {
|
|
|
|
let model;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
instance.createInstance(document.createElement('div'));
|
|
|
|
|
|
|
|
model = instance.createModel(file());
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the current model on the instance', () => {
|
|
|
|
instance.attachModel(model);
|
|
|
|
|
|
|
|
expect(instance.currentModel).toBe(model);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('attaches the model to the current instance', () => {
|
|
|
|
spyOn(instance.instance, 'setModel');
|
|
|
|
|
|
|
|
instance.attachModel(model);
|
|
|
|
|
|
|
|
expect(instance.instance.setModel).toHaveBeenCalledWith(model.getModel());
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets original & modified when diff editor', () => {
|
2018-03-26 10:10:17 -04:00
|
|
|
spyOn(instance.instance, 'getEditorType').and.returnValue('vs.editor.IDiffEditor');
|
2018-03-20 10:12:48 -04:00
|
|
|
spyOn(instance.instance, 'setModel');
|
|
|
|
|
|
|
|
instance.attachModel(model);
|
|
|
|
|
|
|
|
expect(instance.instance.setModel).toHaveBeenCalledWith({
|
|
|
|
original: model.getOriginalModel(),
|
|
|
|
modified: model.getModel(),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('attaches the model to the dirty diff controller', () => {
|
|
|
|
spyOn(instance.dirtyDiffController, 'attachModel');
|
|
|
|
|
|
|
|
instance.attachModel(model);
|
|
|
|
|
2018-03-26 10:10:17 -04:00
|
|
|
expect(instance.dirtyDiffController.attachModel).toHaveBeenCalledWith(model);
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('re-decorates with the dirty diff controller', () => {
|
|
|
|
spyOn(instance.dirtyDiffController, 'reDecorate');
|
|
|
|
|
|
|
|
instance.attachModel(model);
|
|
|
|
|
2018-03-26 10:10:17 -04:00
|
|
|
expect(instance.dirtyDiffController.reDecorate).toHaveBeenCalledWith(model);
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
describe('attachMergeRequestModel', () => {
|
|
|
|
let model;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
instance.createDiffInstance(document.createElement('div'));
|
|
|
|
|
|
|
|
const f = file();
|
|
|
|
f.mrChanges = { diff: 'ABC' };
|
|
|
|
f.baseRaw = 'testing';
|
|
|
|
|
|
|
|
model = instance.createModel(f);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets original & modified', () => {
|
|
|
|
spyOn(instance.instance, 'setModel');
|
|
|
|
|
|
|
|
instance.attachMergeRequestModel(model);
|
|
|
|
|
|
|
|
expect(instance.instance.setModel).toHaveBeenCalledWith({
|
|
|
|
original: model.getBaseModel(),
|
|
|
|
modified: model.getModel(),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-20 10:12:48 -04:00
|
|
|
describe('clearEditor', () => {
|
|
|
|
it('resets the editor model', () => {
|
|
|
|
instance.createInstance(document.createElement('div'));
|
|
|
|
|
|
|
|
spyOn(instance.instance, 'setModel');
|
|
|
|
|
|
|
|
instance.clearEditor();
|
|
|
|
|
|
|
|
expect(instance.instance.setModel).toHaveBeenCalledWith(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('dispose', () => {
|
|
|
|
it('calls disposble dispose method', () => {
|
|
|
|
spyOn(instance.disposable, 'dispose').and.callThrough();
|
|
|
|
|
|
|
|
instance.dispose();
|
|
|
|
|
|
|
|
expect(instance.disposable.dispose).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('resets instance', () => {
|
|
|
|
instance.createInstance(document.createElement('div'));
|
|
|
|
|
|
|
|
expect(instance.instance).not.toBeNull();
|
|
|
|
|
|
|
|
instance.dispose();
|
|
|
|
|
|
|
|
expect(instance.instance).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not dispose modelManager', () => {
|
|
|
|
spyOn(instance.modelManager, 'dispose');
|
|
|
|
|
|
|
|
instance.dispose();
|
|
|
|
|
|
|
|
expect(instance.modelManager.dispose).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not dispose decorationsController', () => {
|
|
|
|
spyOn(instance.decorationsController, 'dispose');
|
|
|
|
|
|
|
|
instance.dispose();
|
|
|
|
|
|
|
|
expect(instance.decorationsController.dispose).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2018-03-28 10:30:58 -04:00
|
|
|
|
|
|
|
describe('updateDiffView', () => {
|
|
|
|
describe('edit mode', () => {
|
|
|
|
it('does not update options', () => {
|
|
|
|
instance.createInstance(holder);
|
|
|
|
|
|
|
|
spyOn(instance.instance, 'updateOptions');
|
|
|
|
|
|
|
|
instance.updateDiffView();
|
|
|
|
|
|
|
|
expect(instance.instance.updateOptions).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('diff mode', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
instance.createDiffInstance(holder);
|
|
|
|
|
|
|
|
spyOn(instance.instance, 'updateOptions').and.callThrough();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets renderSideBySide to false if el is less than 700 pixels', () => {
|
|
|
|
spyOnProperty(instance.instance.getDomNode(), 'offsetWidth').and.returnValue(600);
|
|
|
|
|
|
|
|
expect(instance.instance.updateOptions).not.toHaveBeenCalledWith({
|
|
|
|
renderSideBySide: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets renderSideBySide to false if el is more than 700 pixels', () => {
|
|
|
|
spyOnProperty(instance.instance.getDomNode(), 'offsetWidth').and.returnValue(800);
|
|
|
|
|
|
|
|
expect(instance.instance.updateOptions).not.toHaveBeenCalledWith({
|
|
|
|
renderSideBySide: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isDiffEditorType', () => {
|
|
|
|
it('returns true when diff editor', () => {
|
|
|
|
instance.createDiffInstance(holder);
|
|
|
|
|
|
|
|
expect(instance.isDiffEditorType).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when not diff editor', () => {
|
|
|
|
instance.createInstance(holder);
|
|
|
|
|
|
|
|
expect(instance.isDiffEditorType).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2018-06-15 14:22:56 -04:00
|
|
|
|
|
|
|
it('sets quickSuggestions to false when language is markdown', () => {
|
|
|
|
instance.createInstance(holder);
|
|
|
|
|
|
|
|
spyOn(instance.instance, 'updateOptions').and.callThrough();
|
|
|
|
|
|
|
|
const model = instance.createModel({
|
|
|
|
...file(),
|
|
|
|
key: 'index.md',
|
|
|
|
path: 'index.md',
|
|
|
|
});
|
|
|
|
|
|
|
|
instance.attachModel(model);
|
|
|
|
|
|
|
|
expect(instance.instance.updateOptions).toHaveBeenCalledWith({
|
|
|
|
readOnly: false,
|
|
|
|
quickSuggestions: false,
|
|
|
|
});
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|