Переглянути джерело

Add widget test, clean up.

Afshin Darian 8 роки тому
батько
коміт
1c47218f36

+ 10 - 1
src/csvwidget/widget.ts

@@ -102,12 +102,21 @@ class CSVWidget extends Widget {
     if (this.isDisposed) {
       return;
     }
+
     super.dispose();
+    disconnectReceiver(this);
+
     this._model.dispose();
+    this._model = null;
+
     this._table.dispose();
+    this._table = null;
+
     this._toolbar.dispose();
+    this._toolbar = null;
+
     this._warning.dispose();
-    disconnectReceiver(this);
+    this._warning = null;
   }
 
   /**

+ 1 - 1
test/src/csvwidget/table.spec.ts

@@ -81,7 +81,7 @@ describe('csvwidget/table', () => {
 
     });
 
-    describe('#content', () => {
+    describe('#delimiter', () => {
 
       it('should default to `,`', () => {
         let model = new CSVModel();

+ 99 - 0
test/src/csvwidget/widget.spec.ts

@@ -0,0 +1,99 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import expect = require('expect.js');
+
+import {
+  ServiceManager, utils
+} from '@jupyterlab/services';
+
+import {
+  CSVModel
+} from '../../../lib/csvwidget/table';
+
+import {
+  CSVWidget
+} from '../../../lib/csvwidget/widget';
+
+import {
+  Context, DocumentRegistry, TextModelFactory
+} from '../../../lib/docregistry';
+
+import {
+  CSV_DATA
+} from './data.csv';
+
+
+function createContext(): Context<DocumentRegistry.IModel> {
+  let factory = new TextModelFactory();
+  let manager = new ServiceManager();
+  let path = utils.uuid() + '.csv';
+  return new Context({ factory, manager, path });
+}
+
+
+describe('csvwidget/widget', () => {
+
+  const context = createContext();
+
+  describe('CSVWidget', () => {
+
+    describe('#constructor()', () => {
+
+      it('should instantiate a `CSVWidget`', () => {
+        let widget = new CSVWidget({ context });
+        expect(widget).to.be.a(CSVWidget);
+        widget.dispose();
+      });
+
+      it('should set a max exceeded listener on its warning area', done => {
+        let widget = new CSVWidget({ context });
+        let warning = widget.node.querySelector('.jp-CSVWidget-warning');
+        expect(warning).to.be.ok();
+        expect(warning.innerHTML).to.be.empty();
+        widget.model.content = CSV_DATA;
+        requestAnimationFrame(() => {
+          expect(warning.innerHTML).to.not.be.empty();
+          widget.dispose();
+          done();
+        });
+      });
+
+    });
+
+    describe('#model', () => {
+
+      it('should be a `CSVModel`', () => {
+        let widget = new CSVWidget({ context });
+        expect(widget.model).to.be.a(CSVModel);
+        widget.dispose();
+      });
+
+    });
+
+    describe('#dispose()', () => {
+
+      it('should dispose of the resources held by the widget', () => {
+        let widget = new CSVWidget({ context });
+        expect(widget.isDisposed).to.be(false);
+        expect(widget.model).to.be.ok();
+        widget.dispose();
+        expect(widget.isDisposed).to.be(true);
+        expect(widget.model).to.not.be.ok();
+      });
+
+      it('should be safe to call multiple times', () => {
+        let widget = new CSVWidget({ context });
+        expect(widget.isDisposed).to.be(false);
+        expect(widget.model).to.be.ok();
+        widget.dispose();
+        widget.dispose();
+        expect(widget.isDisposed).to.be(true);
+        expect(widget.model).to.not.be.ok();
+      });
+
+    });
+
+  });
+
+});

+ 1 - 0
test/src/index.ts

@@ -19,6 +19,7 @@ import './console/panel.spec';
 
 import './csvwidget/table.spec';
 import './csvwidget/toolbar.spec';
+import './csvwidget/widget.spec';
 
 import './dialog/dialog.spec';