|
@@ -11,7 +11,7 @@ import {
|
|
|
} from 'phosphor-properties';
|
|
|
|
|
|
import {
|
|
|
- simulate, generate
|
|
|
+ generate
|
|
|
} from 'simulate-event';
|
|
|
|
|
|
import {
|
|
@@ -62,10 +62,19 @@ describe('notebook/cells/editor', () => {
|
|
|
describe('#constructor()', () => {
|
|
|
|
|
|
it('should create a cell editor widget', () => {
|
|
|
- let widget = new CellEditorWidget(new CellModel());
|
|
|
+ let widget = new CellEditorWidget();
|
|
|
expect(widget).to.be.a(CellEditorWidget);
|
|
|
});
|
|
|
|
|
|
+ it('should accept editor configuration options', () => {
|
|
|
+ let widget = new CellEditorWidget({
|
|
|
+ value: 'foo',
|
|
|
+ mode: 'bar'
|
|
|
+ });
|
|
|
+ expect(widget.editor.getOption('value')).to.be('foo');
|
|
|
+ expect(widget.editor.getOption('mode')).to.be('bar');
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
describe('#lineNumbers', () => {
|
|
@@ -112,7 +121,8 @@ describe('notebook/cells/editor', () => {
|
|
|
describe('#textChanged', () => {
|
|
|
|
|
|
it('should emit a signal when editor text is changed', () => {
|
|
|
- let widget = new CellEditorWidget(new CellModel());
|
|
|
+ let widget = new CellEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
let doc = widget.editor.getDoc();
|
|
|
let want = { oldValue: '', newValue: 'foo' };
|
|
|
let fromPos = { line: 0, ch: 0 };
|
|
@@ -135,7 +145,8 @@ describe('notebook/cells/editor', () => {
|
|
|
});
|
|
|
|
|
|
it('should not emit a signal if editor text already matches model', () => {
|
|
|
- let widget = new CellEditorWidget(new CellModel());
|
|
|
+ let widget = new CellEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
let doc = widget.editor.getDoc();
|
|
|
let fromPos = { line: 0, ch: 0 };
|
|
|
let toPos = { line: 0, ch: 3 };
|
|
@@ -154,7 +165,8 @@ describe('notebook/cells/editor', () => {
|
|
|
describe('#completionRequested', () => {
|
|
|
|
|
|
it('should emit a signal when the user requests a tab completion', () => {
|
|
|
- let widget = new CellEditorWidget(new CellModel());
|
|
|
+ let widget = new CellEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
let doc = widget.editor.getDoc();
|
|
|
let want = { currentValue: 'foo', line: 0, ch: 3 };
|
|
|
let fromPos = { line: 0, ch: 0 };
|
|
@@ -181,24 +193,23 @@ describe('notebook/cells/editor', () => {
|
|
|
|
|
|
it('should be settable', () => {
|
|
|
let model = new CellModel();
|
|
|
- let widget = new CellEditorWidget(new CellModel());
|
|
|
- expect(widget.model).to.be.ok();
|
|
|
- expect(widget.model).to.be.a(CellModel);
|
|
|
- expect(widget.model).to.not.be(model);
|
|
|
+ let widget = new CellEditorWidget();
|
|
|
+ expect(widget.model).to.be(null);
|
|
|
widget.model = model;
|
|
|
expect(widget.model).to.be(model);
|
|
|
});
|
|
|
|
|
|
it('should be safe to set multiple times', () => {
|
|
|
let model = new CellModel();
|
|
|
- let widget = new CellEditorWidget(model);
|
|
|
- expect(widget.model).to.be(model);
|
|
|
+ let widget = new CellEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
widget.model = model;
|
|
|
expect(widget.model).to.be(model);
|
|
|
});
|
|
|
|
|
|
it('should empty the code mirror if set to null', () => {
|
|
|
- let widget = new CellEditorWidget(new CellModel());
|
|
|
+ let widget = new CellEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
widget.model.source = 'foo';
|
|
|
expect(widget.editor.getDoc().getValue()).to.be('foo');
|
|
|
widget.model = null;
|
|
@@ -210,7 +221,8 @@ describe('notebook/cells/editor', () => {
|
|
|
describe('#dispose()', () => {
|
|
|
|
|
|
it('should dispose of the resources held by the widget', () => {
|
|
|
- let widget = new CellEditorWidget(new CellModel());
|
|
|
+ let widget = new CellEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
expect(widget.model).to.be.ok();
|
|
|
widget.dispose();
|
|
|
expect(widget.isDisposed).to.be(true);
|
|
@@ -222,7 +234,8 @@ describe('notebook/cells/editor', () => {
|
|
|
describe('#getCursorPosition()', () => {
|
|
|
|
|
|
it('should return the cursor position of the editor', () => {
|
|
|
- let widget = new CellEditorWidget(new CellModel());
|
|
|
+ let widget = new CellEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
let doc = widget.editor.getDoc();
|
|
|
let fromPos = { line: 0, ch: 0 };
|
|
|
let toPos = { line: 0, ch: 0 };
|
|
@@ -237,7 +250,8 @@ describe('notebook/cells/editor', () => {
|
|
|
describe('#setCursorPosition()', () => {
|
|
|
|
|
|
it('should set the cursor position of the editor', () => {
|
|
|
- let widget = new CellEditorWidget(new CellModel());
|
|
|
+ let widget = new CellEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
expect(widget.getCursorPosition()).to.be(0);
|
|
|
widget.model.source = 'foo';
|
|
|
expect(widget.getCursorPosition()).to.be(0);
|
|
@@ -250,7 +264,8 @@ describe('notebook/cells/editor', () => {
|
|
|
describe('#onModelStateChanged()', () => {
|
|
|
|
|
|
it('should run the model state changes', () => {
|
|
|
- let widget = new LogEditorWidget(new CellModel());
|
|
|
+ let widget = new LogEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
expect(widget.methods).to.not.contain('onModelStateChanged');
|
|
|
widget.model.source = 'foo';
|
|
|
expect(widget.methods).to.contain('onModelStateChanged');
|
|
@@ -261,7 +276,8 @@ describe('notebook/cells/editor', () => {
|
|
|
describe('#onDocChange()', () => {
|
|
|
|
|
|
it('should run when the code mirror document changes', () => {
|
|
|
- let widget = new LogEditorWidget(new CellModel());
|
|
|
+ let widget = new LogEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
let doc = widget.editor.getDoc();
|
|
|
let fromPos = { line: 0, ch: 0 };
|
|
|
let toPos = { line: 0, ch: 0 };
|
|
@@ -275,7 +291,8 @@ describe('notebook/cells/editor', () => {
|
|
|
describe('#onEditorKeydown()', () => {
|
|
|
|
|
|
it('should run when there is a keydown event on the editor', () => {
|
|
|
- let widget = new LogEditorWidget(new CellModel());
|
|
|
+ let widget = new LogEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
let event = generate('keydown', { keyCode: UP_ARROW });
|
|
|
expect(widget.methods).to.not.contain('onEditorKeydown');
|
|
|
widget.editor.triggerOnKeyDown(event);
|
|
@@ -287,7 +304,8 @@ describe('notebook/cells/editor', () => {
|
|
|
describe('#onTabEvent()', () => {
|
|
|
|
|
|
it('should run when there is a tab keydown event on the editor', () => {
|
|
|
- let widget = new LogEditorWidget(new CellModel());
|
|
|
+ let widget = new LogEditorWidget();
|
|
|
+ widget.model = new CellModel();
|
|
|
let event = generate('keydown', { keyCode: TAB });
|
|
|
expect(widget.methods).to.not.contain('onTabEvent');
|
|
|
widget.editor.triggerOnKeyDown(event);
|