Jelajahi Sumber

Tests for CodeMirrorEditorFactory

Vidar Tonaas Fauske 8 tahun lalu
induk
melakukan
53b9c4bad8
2 mengubah file dengan 106 tambahan dan 0 penghapusan
  1. 105 0
      test/src/codemirror/factory.spec.ts
  2. 1 0
      test/src/index.ts

+ 105 - 0
test/src/codemirror/factory.spec.ts

@@ -0,0 +1,105 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import expect = require('expect.js');
+
+import {
+  CodeEditor
+} from '../../../lib/codeeditor';
+
+import {
+  CodeMirrorEditorFactory, CodeMirrorEditor
+} from '../../../lib/codemirror';
+
+
+class ExposeCodeMirrorEditorFactory extends CodeMirrorEditorFactory {
+  public inlineCodeMirrorOptions: CodeMirror.EditorConfiguration;
+  public documentCodeMirrorOptions: CodeMirror.EditorConfiguration;
+}
+
+
+describe('CodeMirrorEditorFactory', () => {
+  let host: HTMLElement;
+  let model: CodeEditor.IModel;
+
+  const options: CodeMirror.EditorConfiguration = {
+    lineNumbers: false,
+    lineWrapping: true,
+    extraKeys: {
+      'Ctrl-Tab': 'indentAuto',
+    },
+    undoDepth: 5,
+  };
+
+  beforeEach(() => {
+    host = document.createElement('div');
+    document.body.appendChild(host);
+    model = new CodeEditor.Model();
+  });
+
+  afterEach(() => {
+    document.body.removeChild(host);
+  });
+
+  describe('#constructor()', () => {
+
+    it('should create a CodeMirrorEditorFactory', () => {
+      let factory = new CodeMirrorEditorFactory();
+      expect(factory).to.be.a(CodeMirrorEditorFactory);
+    });
+
+    it('should create a CodeMirrorEditorFactory', () => {
+
+      let factory = new ExposeCodeMirrorEditorFactory(options);
+      expect(factory).to.be.a(CodeMirrorEditorFactory);
+      expect(factory.inlineCodeMirrorOptions).to.eql(options);
+      expect(factory.documentCodeMirrorOptions).to.eql(options);
+    });
+
+  });
+
+  describe('#newInlineEditor', () => {
+
+    it('should create a new editor', () => {
+      let factory = new CodeMirrorEditorFactory();
+      let editor = factory.newInlineEditor({host, model});
+      expect(editor).to.be.a(CodeMirrorEditor);
+      editor.dispose();
+    });
+
+    it('should create a new editor with given options', () => {
+      let factory = new CodeMirrorEditorFactory(options);
+      let editor = factory.newInlineEditor({host, model});
+      expect(editor).to.be.a(CodeMirrorEditor);
+      let inner = (editor as CodeMirrorEditor).editor;
+      for (let key of Object.keys(options)) {
+        expect(inner.getOption(key)).to.equal((options as any)[key]);
+      }
+      editor.dispose();
+    });
+
+  });
+
+  describe('#newDocumentEditor', () => {
+
+    it('should create a new editor', () => {
+      let factory = new CodeMirrorEditorFactory();
+      let editor = factory.newDocumentEditor({host, model});
+      expect(editor).to.be.a(CodeMirrorEditor);
+      editor.dispose();
+    });
+
+    it('should create a new editor with given options', () => {
+      let factory = new CodeMirrorEditorFactory(options);
+      let editor = factory.newDocumentEditor({host, model});
+      expect(editor).to.be.a(CodeMirrorEditor);
+      let inner = (editor as CodeMirrorEditor).editor;
+      for (let key of Object.keys(options)) {
+        expect(inner.getOption(key)).to.equal((options as any)[key]);
+      }
+      editor.dispose();
+    });
+
+  });
+
+});

+ 1 - 0
test/src/index.ts

@@ -11,6 +11,7 @@ import './codeeditor/editor.spec';
 import './codeeditor/widget.spec';
 
 import './codemirror/editor.spec';
+import './codemirror/factory.spec';
 
 import './commandlinker/commandlinker.spec';