Browse Source

wip update tests

Steven Silvester 8 years ago
parent
commit
c091d8d6ae

+ 31 - 31
test/src/completer/handler.spec.ts

@@ -12,13 +12,9 @@ import {
 } from '@jupyterlab/services';
 
 import {
-  BaseCellWidget, CellModel
+  BaseCellWidget, CellModel, CellEditorWidget
 } from '../../../lib/notebook/cells';
 
-import {
-  ICompletionRequest, ICellEditorWidget, ITextChange
-} from '../../../lib/notebook/cells/editor';
-
 import {
   CompleterWidget, CellCompleterHandler, CompleterModel
 } from '../../../lib/completer';
@@ -39,7 +35,7 @@ class TestCompleterModel extends CompleterModel {
     return super.createPatch(patch);
   }
 
-  handleTextChange(change: ITextChange): void {
+  handleTextChange(change: CellEditorWidget.ITextChange): void {
     this.methods.push('handleTextChange');
     super.handleTextChange(change);
   }
@@ -49,23 +45,23 @@ class TestCompleterModel extends CompleterModel {
 class TestCompleterHandler extends CellCompleterHandler {
   methods: string[] = [];
 
-  makeRequest(request: ICompletionRequest): Promise<void> {
+  makeRequest(request: CellEditorWidget.ICompletionRequest): Promise<void> {
     let promise = super.makeRequest(request);
     this.methods.push('makeRequest');
     return promise;
   }
 
-  onReply(pending: number, request: ICompletionRequest, msg: KernelMessage.ICompleteReplyMsg): void {
+  onReply(pending: number, request: CellEditorWidget.ICompletionRequest, msg: KernelMessage.ICompleteReplyMsg): void {
     super.onReply(pending, request, msg);
     this.methods.push('onReply');
   }
 
-  onTextChanged(editor: ICellEditorWidget, change: ITextChange): void {
+  onTextChanged(editor: CellEditorWidget, change: CellEditorWidget.ITextChange): void {
     super.onTextChanged(editor, change);
     this.methods.push('onTextChanged');
   }
 
-  onCompletionRequested(editor: ICellEditorWidget, request: ICompletionRequest): void {
+  onCompletionRequested(editor: CellEditorWidget, request: CellEditorWidget.ICompletionRequest): void {
     super.onCompletionRequested(editor, request);
     this.methods.push('onCompletionRequested');
   }
@@ -79,6 +75,11 @@ class TestCompleterHandler extends CellCompleterHandler {
 const kernelPromise = Kernel.startNew();
 
 
+function createCellWidget(): BaseCellWidget {
+  return new BaseCellWidget({ model: new CellModel(), renderer });
+}
+
+
 describe('completer/handler', () => {
 
   let kernel: Kernel.IKernel;
@@ -141,7 +142,7 @@ describe('completer/handler', () => {
         let handler = new CellCompleterHandler({
           completer: new CompleterWidget()
         });
-        let cell = new BaseCellWidget({ renderer });
+        let cell = createCellWidget();
         expect(handler.activeCell).to.be(null);
         handler.activeCell = cell;
         expect(handler.activeCell).to.be.a(BaseCellWidget);
@@ -152,8 +153,8 @@ describe('completer/handler', () => {
         let handler = new CellCompleterHandler({
           completer: new CompleterWidget()
         });
-        let one = new BaseCellWidget({ renderer });
-        let two = new BaseCellWidget({ renderer });
+        let one = createCellWidget();
+        let two = createCellWidget();
         expect(handler.activeCell).to.be(null);
         handler.activeCell = one;
         expect(handler.activeCell).to.be.a(BaseCellWidget);
@@ -210,7 +211,7 @@ describe('completer/handler', () => {
         let handler = new TestCompleterHandler({
           completer: new CompleterWidget()
         });
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -231,7 +232,7 @@ describe('completer/handler', () => {
         let handler = new TestCompleterHandler({
           completer: new CompleterWidget()
         });
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -271,7 +272,7 @@ describe('completer/handler', () => {
         let completer = new CompleterWidget();
         let handler = new TestCompleterHandler({ completer });
         let options = ['a', 'b', 'c'];
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -305,7 +306,7 @@ describe('completer/handler', () => {
         let completer = new CompleterWidget();
         let handler = new TestCompleterHandler({ completer });
         let options = ['a', 'b', 'c'];
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -343,7 +344,7 @@ describe('completer/handler', () => {
         let handler = new TestCompleterHandler({
           completer: new CompleterWidget()
         });
-        let change: ITextChange = {
+        let change: CellEditorWidget.ITextChange = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -353,7 +354,7 @@ describe('completer/handler', () => {
           oldValue: 'fo',
           newValue: 'foo'
         };
-        let cell = new BaseCellWidget({ renderer });
+        let cell = createCellWidget();
 
         handler.activeCell = cell;
         expect(handler.methods).to.not.contain('onTextChanged');
@@ -366,7 +367,7 @@ describe('completer/handler', () => {
           model: new TestCompleterModel()
         });
         let handler = new TestCompleterHandler({ completer });
-        let change: ITextChange = {
+        let change: CellEditorWidget.ITextChange = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -376,7 +377,7 @@ describe('completer/handler', () => {
           oldValue: 'fo',
           newValue: 'foo'
         };
-        let cell = new BaseCellWidget({ renderer });
+        let cell = createCellWidget();
         let model = completer.model as TestCompleterModel;
 
         handler.activeCell = cell;
@@ -393,7 +394,7 @@ describe('completer/handler', () => {
         let handler = new TestCompleterHandler({
           completer: new CompleterWidget()
         });
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -402,7 +403,7 @@ describe('completer/handler', () => {
           position: 0,
           currentValue: 'foo'
         };
-        let cell = new BaseCellWidget({ renderer });
+        let cell = createCellWidget();
 
         handler.activeCell = cell;
         expect(handler.methods).to.not.contain('onCompletionRequested');
@@ -415,7 +416,7 @@ describe('completer/handler', () => {
           model: new TestCompleterModel()
         });
         let handler = new TestCompleterHandler({ completer });
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -424,7 +425,7 @@ describe('completer/handler', () => {
           position: 0,
           currentValue: 'foo'
         };
-        let cell = new BaseCellWidget({ renderer });
+        let cell = createCellWidget();
 
         handler.kernel = kernel;
         handler.activeCell = cell;
@@ -453,7 +454,7 @@ describe('completer/handler', () => {
         let handler = new TestCompleterHandler({ completer });
         let model = completer.model as TestCompleterModel;
 
-        handler.activeCell = new BaseCellWidget({ renderer });
+        handler.activeCell = createCellWidget()
         expect(model.methods).to.not.contain('createPatch');
         completer.selected.emit('foo');
         expect(model.methods).to.contain('createPatch');
@@ -464,8 +465,8 @@ describe('completer/handler', () => {
         let patch = 'foobar';
         let completer = new CompleterWidget({ model });
         let handler = new TestCompleterHandler({ completer });
-        let cell = new BaseCellWidget({ renderer });
-        let request: ICompletionRequest = {
+        let cell = createCellWidget();
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -475,13 +476,12 @@ describe('completer/handler', () => {
           currentValue: 'foo'
         };
 
-        cell.model = new CellModel();
         handler.activeCell = cell;
-        handler.activeCell.model.source = request.currentValue;
+        handler.activeCell.model.value.text = request.currentValue;
         model.original = request;
         model.cursor = { start: 0, end: 3 };
         completer.selected.emit(patch);
-        expect(handler.activeCell.model.source).to.equal(patch);
+        expect(handler.activeCell.model.value.text).to.equal(patch);
       });
 
     });

+ 29 - 29
test/src/completer/model.spec.ts

@@ -12,8 +12,8 @@ import {
 } from '../../../lib/completer';
 
 import {
-  ICompletionRequest, ICoords, ITextChange
-} from '../../../lib/notebook/cells/editor';
+  CellEditorWidget
+} from '../../../lib/notebook/cells';
 
 
 describe('completer/model', () => {
@@ -60,7 +60,7 @@ describe('completer/model', () => {
       it('should signal when original request changes', () => {
         let model = new CompleterModel();
         let called = 0;
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -81,7 +81,7 @@ describe('completer/model', () => {
       it('should not signal when original request has not changed', () => {
         let model = new CompleterModel();
         let called = 0;
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -107,9 +107,9 @@ describe('completer/model', () => {
         let currentValue = 'foo';
         let oldValue = currentValue;
         let newValue = 'foob';
-        let coords: ICoords = null;
+        let coords: CellEditorWidget.ICoordinate = null;
         let cursor: CompleterWidget.ICursorSpan = { start: 0, end: 0 };
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -118,7 +118,7 @@ describe('completer/model', () => {
           position: 0,
           currentValue: currentValue
         };
-        let change: ITextChange = {
+        let change: CellEditorWidget.ITextChange = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -144,9 +144,9 @@ describe('completer/model', () => {
         let currentValue = 'foo';
         let oldValue = currentValue;
         let newValue = 'foob';
-        let coords: ICoords = null;
+        let coords: CellEditorWidget.ICoordinate = null;
         let cursor: CompleterWidget.ICursorSpan = { start: 0, end: 0 };
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -155,7 +155,7 @@ describe('completer/model', () => {
           position: 0,
           currentValue: currentValue
         };
-        let change: ITextChange = {
+        let change: CellEditorWidget.ITextChange = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -252,7 +252,7 @@ describe('completer/model', () => {
 
       it('should return the original request', () => {
         let model = new CompleterModel();
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -279,9 +279,9 @@ describe('completer/model', () => {
         let currentValue = 'foo';
         let oldValue = currentValue;
         let newValue = 'foob';
-        let coords: ICoords = null;
+        let coords: CellEditorWidget.ICoordinate = null;
         let cursor: CompleterWidget.ICursorSpan = { start: 0, end: 0 };
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -290,7 +290,7 @@ describe('completer/model', () => {
           position: 0,
           currentValue: currentValue
         };
-        let change: ITextChange = {
+        let change: CellEditorWidget.ITextChange = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -311,9 +311,9 @@ describe('completer/model', () => {
         let currentValue = 'foo';
         let oldValue = currentValue;
         let newValue = 'foob';
-        let coords: ICoords = null;
+        let coords: CellEditorWidget.ICoordinate = null;
         let cursor: CompleterWidget.ICursorSpan = { start: 0, end: 0 };
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -322,7 +322,7 @@ describe('completer/model', () => {
           position: 0,
           currentValue: currentValue
         };
-        let change: ITextChange = {
+        let change: CellEditorWidget.ITextChange = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -343,9 +343,9 @@ describe('completer/model', () => {
         let currentValue = 'foo';
         let oldValue = currentValue;
         let newValue = 'fo';
-        let coords: ICoords = null;
+        let coords: CellEditorWidget.ICoordinate = null;
         let cursor: CompleterWidget.ICursorSpan = { start: 0, end: 0 };
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -354,7 +354,7 @@ describe('completer/model', () => {
           position: 0,
           currentValue: currentValue
         };
-        let change: ITextChange = {
+        let change: CellEditorWidget.ITextChange = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -382,7 +382,7 @@ describe('completer/model', () => {
       it('should not set if original request is nonexistent', () => {
         let model = new CompleterModel();
         let cursor: CompleterWidget.ICursorSpan = { start: 0, end: 0 };
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -438,9 +438,9 @@ describe('completer/model', () => {
         let currentValue = 'foo';
         let oldValue = currentValue;
         let newValue = 'foob';
-        let coords: ICoords = null;
+        let coords: CellEditorWidget.ICoordinate = null;
         let cursor: CompleterWidget.ICursorSpan = { start: 0, end: 0 };
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -449,7 +449,7 @@ describe('completer/model', () => {
           position: 0,
           currentValue: currentValue
         };
-        let change: ITextChange = {
+        let change: CellEditorWidget.ITextChange = {
           ch: 4,
           chHeight: 0,
           chWidth: 0,
@@ -469,8 +469,8 @@ describe('completer/model', () => {
         let currentValue = 'foo';
         let oldValue = currentValue;
         let newValue = 'foo ';
-        let coords: ICoords = null;
-        let request: ICompletionRequest = {
+        let coords: CellEditorWidget.ICoordinate = null;
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -479,7 +479,7 @@ describe('completer/model', () => {
           position: 0,
           currentValue: currentValue
         };
-        let change: ITextChange = {
+        let change: CellEditorWidget.ITextChange = {
           ch: 4,
           chHeight: 0,
           chWidth: 0,
@@ -502,7 +502,7 @@ describe('completer/model', () => {
         let patch = 'foobar';
         let want: CompleterWidget.IPatch = { text: patch, position: patch.length };
         let cursor: CompleterWidget.ICursorSpan = { start: 0, end: 3 };
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -527,7 +527,7 @@ describe('completer/model', () => {
         let patch = 'barbaz';
         let want: CompleterWidget.IPatch = { text: 'foo\nbarbaz', position: 10 };
         let cursor: CompleterWidget.ICursorSpan = { start: 4, end: 7 };
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,

+ 6 - 6
test/src/completer/widget.spec.ts

@@ -16,8 +16,8 @@ import {
 } from 'simulate-event';
 
 import {
-  ICompletionRequest, ICoords
-} from '../../../lib/notebook/cells/editor';
+  CellEditorWidget
+} from '../../../lib/notebook/cells';
 
 import {
   CompleterWidget, CompleterModel
@@ -550,8 +550,8 @@ describe('completer/widget', () => {
           let anchor = document.createElement('div');
           let content = new Widget();
           let model = new CompleterModel();
-          let coords: ICoords = { left: 0, right: 0, top: 100, bottom: 120 };
-          let request: ICompletionRequest = {
+          let coords: CellEditorWidget.ICoordinate = { left: 0, right: 0, top: 100, bottom: 120 };
+          let request: CellEditorWidget.ICompletionRequest = {
             ch: 0,
             chHeight: 0,
             chWidth: 0,
@@ -605,7 +605,7 @@ describe('completer/widget', () => {
       it('should emit a selection if there is only one match', () => {
         let anchor = new Widget();
         let model = new CompleterModel();
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,
@@ -642,7 +642,7 @@ describe('completer/widget', () => {
       it('should un-hide widget if multiple options are available', () => {
         let anchor = new Widget();
         let model = new CompleterModel();
-        let request: ICompletionRequest = {
+        let request: CellEditorWidget.ICompletionRequest = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,

+ 14 - 17
test/src/console/content.spec.ts

@@ -32,13 +32,9 @@ import {
 } from '../../../lib/inspector';
 
 import {
-  CodeCellWidget
+  CodeCellWidget, CodeCellModel, CellEditorWidget
 } from '../../../lib/notebook/cells';
 
-import {
-  EdgeLocation, ICellEditorWidget, ITextChange
-} from '../../../lib/notebook/cells/editor';
-
 import {
   createCodeCellRenderer
 } from '../notebook/utils';
@@ -81,14 +77,14 @@ class TestContent extends ConsoleContent {
     this.methods.push('onAfterAttach');
   }
 
-  protected onEdgeRequest(editor: ICellEditorWidget, location: EdgeLocation): Promise<void> {
+  protected onEdgeRequest(editor: CellEditorWidget, location: CellEditorWidget.EdgeLocation): Promise<void> {
     return super.onEdgeRequest(editor, location).then(() => {
       this.methods.push('onEdgeRequest');
       this.edgeRequested.emit(void 0);
     });
   }
 
-  protected onTextChange(editor: ICellEditorWidget, args: ITextChange): void {
+  protected onTextChange(editor: CellEditorWidget, args: CellEditorWidget.ITextChange): void {
     super.onTextChange(editor, args);
     this.methods.push('onTextChange');
   }
@@ -235,7 +231,8 @@ describe('console/content', () => {
 
       it('should add a code cell to the content widget', () => {
         let renderer = createCodeCellRenderer();
-        let cell = new CodeCellWidget({ renderer, rendermime });
+        let model = new CodeCellModel();
+        let cell = new CodeCellWidget({ model, renderer, rendermime });
         Widget.attach(widget, document.body);
         expect(widget.cells.length).to.be(0);
         widget.addCell(cell);
@@ -296,7 +293,7 @@ describe('console/content', () => {
         let force = false;
         let timeout = 9000;
         Widget.attach(widget, document.body);
-        widget.prompt.model.source = 'for x in range(5):';
+        widget.prompt.model.value.text = 'for x in range(5):';
         expect(widget.content.widgets.length).to.be(1);
         widget.execute(force, timeout).then(() => {
           expect(widget.content.widgets.length).to.be(1);
@@ -326,9 +323,9 @@ describe('console/content', () => {
         Widget.attach(widget, document.body);
 
         let model = widget.prompt.model;
-        expect(model.source).to.be.empty();
+        expect(model.value.text).to.be.empty();
         widget.insertLinebreak();
-        expect(model.source).to.be('\n');
+        expect(model.value.text).to.be('\n');
       });
 
     });
@@ -337,7 +334,7 @@ describe('console/content', () => {
 
       it('should serialize the contents of a console', () => {
         Widget.attach(widget, document.body);
-        widget.prompt.model.source = 'foo';
+        widget.prompt.model.value.text = 'foo';
 
         let serialized = widget.serialize();
         expect(serialized).to.have.length(2);
@@ -387,7 +384,7 @@ describe('console/content', () => {
           widget.activate();
           requestAnimationFrame(() => {
             expect(widget.methods).to.contain('onActivateRequest');
-            expect(widget.prompt.editor.hasFocus()).to.be(true);
+            expect(widget.prompt.editor.editor.hasFocus()).to.be(true);
             done();
           });
         });
@@ -420,16 +417,16 @@ describe('console/content', () => {
           local.edgeRequested.connect(() => {
             expect(local.methods).to.contain('onEdgeRequest');
             requestAnimationFrame(() => {
-              expect(local.prompt.model.source).to.be(code);
+              expect(local.prompt.model.value.text).to.be(code);
               local.dispose();
               done();
             });
           });
           Widget.attach(local, document.body);
           requestAnimationFrame(() => {
-            local.prompt.model.source = code;
+            local.prompt.model.value.text = code;
             local.execute(force).then(() => {
-              expect(local.prompt.model.source).to.not.be(code);
+              expect(local.prompt.model.value.text).to.not.be(code);
               expect(local.methods).to.not.contain('onEdgeRequest');
               local.prompt.editor.edgeRequested.emit('top');
             }).catch(done);
@@ -442,7 +439,7 @@ describe('console/content', () => {
     describe('#onTextChange()', () => {
 
       it('should be called upon an editor text change', () => {
-        let change: ITextChange = {
+        let change: CellEditorWidget.ITextChange = {
           ch: 0,
           chHeight: 0,
           chWidth: 0,

+ 2 - 2
test/src/console/foreign.spec.ts

@@ -85,8 +85,8 @@ const rendermime = defaultRenderMime();
 const renderer: ForeignHandler.IRenderer = {
   createCell: () => {
     let renderer = createCodeCellRenderer();
-    let cell = new CodeCellWidget({ rendermime, renderer });
-    cell.model = new CodeCellModel();
+    let model = new CodeCellModel();
+    let cell = new CodeCellWidget({ model, rendermime, renderer });
     return cell;
   }
 };

+ 1 - 1
test/src/console/panel.spec.ts

@@ -112,7 +112,7 @@ describe('console/panel', () => {
           panel.activate();
           requestAnimationFrame(() => {
             expect(panel.methods).to.contain('onActivateRequest');
-            expect(panel.content.prompt.editor.hasFocus()).to.be(true);
+            expect(panel.content.prompt.editor.editor.hasFocus()).to.be(true);
             done();
           });
         });