Kaynağa Gözat

Merge pull request #163 from blink1073/test-suite

Start writing test suite
Dave Willmer 9 yıl önce
ebeveyn
işleme
6ea826c2fe

+ 2 - 3
package.json

@@ -36,7 +36,6 @@
     "mocha": "^2.2.5",
     "rimraf": "^2.4.2",
     "style-loader": "^0.13.0",
-    "tsconfig-cli": "^0.1.1",
     "typedoc": "^0.3.11",
     "typescript": "^1.8.0",
     "watch": "^0.17.1",
@@ -47,7 +46,7 @@
     "clean:example": "rimraf example/build",
     "build:example": "cd example && npm run update && npm run build",
     "build:src": "tsc --project src && node scripts/copycss.js",
-    "build:test": "tsconfig -u test/src/tsconfig.json && tsc --project test/src && webpack --config test/webpack.conf.js",
+    "build:test": "tsc --project test/src",
     "build": "npm run build:src && npm run build:test",
     "docs": "typedoc --options scripts/tdoptions.json",
     "postinstall": "npm dedupe",
@@ -57,7 +56,7 @@
     "test:firefox": "karma start --browsers=Firefox test/karma.conf.js",
     "test:ie": "karma start --browsers=IE test/karma.conf.js",
     "test:debug": "karma start --browsers=Chrome --singleRun=false --debug=true test/karma.conf.js",
-    "test": "npm run test:firefox",
+    "test": "mocha test/build/**/*.spec.js",
     "watch:example": "watch 'npm run build && npm run build:example' src --wait 10",
     "watch": "watch 'npm run build' src"
   },

+ 2 - 2
src/notebook/editor/model.ts

@@ -134,7 +134,7 @@ class EditorModel implements IEditorModel {
   }
 
   /**
-   * The mode for the editor filename.
+   * The editor filename.
    */
   get filename(): string {
     return this._filename;
@@ -143,7 +143,7 @@ class EditorModel implements IEditorModel {
     if (newValue === this._filename) {
       return;
     }
-    let oldValue = this._fixedHeight;
+    let oldValue = this._filename;
     let name = 'filename';
     this._filename = newValue;
     this.stateChanged.emit({ name, oldValue, newValue });

+ 224 - 0
test/src/notebook/editor/model.spec.ts

@@ -0,0 +1,224 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+'use-strict';
+
+import expect = require('expect.js');
+
+import {
+  EditorModel
+} from '../../../lib/editor/model';
+
+
+describe('jupyter-js-notebook', () => {
+
+  describe('EditorModel', () => {
+
+    describe('#constructor()', () => {
+
+      it('should create an editor model', () => {
+        let model = new EditorModel();
+        expect(model instanceof EditorModel).to.be(true);
+      });
+
+      it('should accept editor options', () => {
+        let options = {
+          text: 'foo',
+          mimetype: 'text/python',
+          filename: 'bar.py',
+          fixedHeight: true,
+          lineNumbers: true,
+          readOnly: true,
+          tabSize: 2
+        }
+        let model = new EditorModel(options);
+        for (let key of Object.keys(options)) {
+          expect((model as any)[key]).to.be((options as any)[key]);
+        }
+      });
+
+    });
+
+    describe('#stateChanged', () => {
+
+      it('should be emitted when the state changes', () => {
+        let model = new EditorModel();
+        let called = false;
+        model.stateChanged.connect((editor, change) => {
+          expect(change.name).to.be('text');
+          expect(change.oldValue).to.be('');
+          expect(change.newValue).to.be('foo');
+          called = true;
+        });
+        model.text = 'foo';
+        expect(called).to.be(true);
+      });
+
+    });
+
+    describe('#filename', () => {
+
+      it('should default to an empty string', () => {
+        let model = new EditorModel();
+        expect(model.filename).to.be('');
+      });
+
+      it('should emit a stateChanged signal when changed', () => {
+        let model = new EditorModel();
+        let called = false;
+        model.stateChanged.connect((editor, change) => {
+          expect(change.name).to.be('filename');
+          expect(change.oldValue).to.be('');
+          expect(change.newValue).to.be('foo.txt');
+          called = true;
+        });
+        model.filename = 'foo.txt';
+        expect(called).to.be(true);
+      });
+
+    });
+
+    describe('#fixedHeight', () => {
+
+      it('should default to false', () => {
+        let model = new EditorModel();
+        expect(model.fixedHeight).to.be(false);
+      });
+
+      it('should emit a stateChanged signal when changed', () => {
+        let model = new EditorModel();
+        let called = false;
+        model.stateChanged.connect((editor, change) => {
+          expect(change.name).to.be('fixedHeight');
+          expect(change.oldValue).to.be(false);
+          expect(change.newValue).to.be(true);
+          called = true;
+        });
+        model.fixedHeight = true;
+        expect(called).to.be(true);
+      });
+
+    });
+
+    describe('#mimetype', () => {
+
+      it('should default to an empty string', () => {
+        let model = new EditorModel();
+        expect(model.mimetype).to.be('');
+      });
+
+      it('should emit a stateChanged signal when changed', () => {
+        let model = new EditorModel();
+        let called = false;
+        model.stateChanged.connect((editor, change) => {
+          expect(change.name).to.be('mimetype');
+          expect(change.oldValue).to.be('');
+          expect(change.newValue).to.be('text/python');
+          called = true;
+        });
+        model.mimetype = 'text/python';
+        expect(called).to.be(true);
+      });
+
+    });
+
+    describe('#mimetype', () => {
+
+      it('should default to false', () => {
+        let model = new EditorModel();
+        expect(model.lineNumbers).to.be(false);
+      });
+
+      it('should emit a stateChanged signal when changed', () => {
+        let model = new EditorModel();
+        let called = false;
+        model.stateChanged.connect((editor, change) => {
+          expect(change.name).to.be('lineNumbers');
+          expect(change.oldValue).to.be(false);
+          expect(change.newValue).to.be(true);
+          called = true;
+        });
+        model.lineNumbers = true;
+        expect(called).to.be(true);
+      });
+
+    });
+
+    describe('#tabSize', () => {
+
+      it('should default to `4`', () => {
+        let model = new EditorModel();
+        expect(model.tabSize).to.be(4);
+      });
+
+      it('should emit a stateChanged signal when changed', () => {
+        let model = new EditorModel();
+        let called = false;
+        model.stateChanged.connect((editor, change) => {
+          expect(change.name).to.be('tabSize');
+          expect(change.oldValue).to.be(4);
+          expect(change.newValue).to.be(2);
+          called = true;
+        });
+        model.tabSize = 2;
+        expect(called).to.be(true);
+      });
+
+    });
+
+    describe('#text', () => {
+
+      it('should default to an empty string', () => {
+        let model = new EditorModel();
+        expect(model.text).to.be('');
+      });
+
+      it('should emit a stateChanged signal when changed', () => {
+        let model = new EditorModel();
+        let called = false;
+        model.stateChanged.connect((editor, change) => {
+          expect(change.name).to.be('text');
+          expect(change.oldValue).to.be('');
+          expect(change.newValue).to.be('foo');
+          called = true;
+        });
+        model.text = 'foo';
+        expect(called).to.be(true);
+      });
+
+    });
+
+    describe('#isDisposed', () => {
+
+      it('should indicate whether the model is disposed', () => {
+        let model = new EditorModel();
+        expect(model.isDisposed).to.be(false);
+        model.dispose();
+        expect(model.isDisposed).to.be(true);
+      });
+
+    });
+
+    describe('#dispose()', () => {
+
+      it('should clear signal data on the model', () => {
+        let model = new EditorModel();
+        let called = false;
+        model.stateChanged.connect(() => { called = true; });
+        model.dispose();
+        model.text = 'foo';
+        expect(called).to.be(false);
+      });
+
+      it('should be safe to call multiple times', () => {
+        let model = new EditorModel();
+        model.dispose();
+        model.dispose();
+      });
+
+    });
+
+  });
+
+
+
+});

+ 9 - 13
test/src/notebook/tsconfig.json

@@ -1,14 +1,10 @@
 {
-    "compilerOptions": {
-        "noImplicitAny": true,
-        "noEmitOnError": true,
-        "module": "commonjs",
-        "moduleResolution": "node",
-        "target": "ES5",
-        "outDir": "../build"
-    },
-    "files": [
-        "index.ts",
-        "typings.d.ts"
-    ]
-}
+  "compilerOptions": {
+    "noImplicitAny": true,
+    "noEmitOnError": true,
+    "module": "commonjs",
+    "moduleResolution": "node",
+    "target": "ES5",
+    "outDir": "../build"
+  }
+}