|
@@ -1,10 +1,6 @@
|
|
|
// Copyright (c) Jupyter Development Team.
|
|
|
-// Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
-// tslint:disable-next-line
|
|
|
-/// <reference path="../../../packages/codemirror/typings/codemirror/codemirror.d.ts"/>
|
|
|
-
|
|
|
-import { expect } from 'chai';
|
|
|
+import 'jest';
|
|
|
|
|
|
import { generate, simulate } from 'simulate-event';
|
|
|
|
|
@@ -48,7 +44,7 @@ describe('CodeMirrorEditor', () => {
|
|
|
|
|
|
describe('#constructor()', () => {
|
|
|
it('should create a CodeMirrorEditor', () => {
|
|
|
- expect(editor).to.be.an.instanceof(CodeMirrorEditor);
|
|
|
+ expect(editor).toBeInstanceOf(CodeMirrorEditor);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -60,9 +56,9 @@ describe('CodeMirrorEditor', () => {
|
|
|
edge = args;
|
|
|
};
|
|
|
editor.edgeRequested.connect(listener);
|
|
|
- expect(edge).to.be.null;
|
|
|
+ expect(edge).toBeNull();
|
|
|
editor.editor.triggerOnKeyDown(event);
|
|
|
- expect(edge).to.equal('top');
|
|
|
+ expect(edge).toBe('top');
|
|
|
});
|
|
|
|
|
|
it('should emit a signal when the bottom edge is requested', () => {
|
|
@@ -72,26 +68,24 @@ describe('CodeMirrorEditor', () => {
|
|
|
edge = args;
|
|
|
};
|
|
|
editor.edgeRequested.connect(listener);
|
|
|
- expect(edge).to.be.null;
|
|
|
+ expect(edge).toBeNull();
|
|
|
editor.editor.triggerOnKeyDown(event);
|
|
|
- expect(edge).to.equal('bottom');
|
|
|
+ expect(edge).toBe('bottom');
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#uuid', () => {
|
|
|
it('should be the unique id of the editor', () => {
|
|
|
- expect(editor.uuid).to.be.ok;
|
|
|
+ expect(editor.uuid).toBeTruthy();
|
|
|
const uuid = 'foo';
|
|
|
editor = new LogFileEditor({ model, host, uuid });
|
|
|
- expect(editor.uuid).to.equal('foo');
|
|
|
+ expect(editor.uuid).toBe('foo');
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#selectionStyle', () => {
|
|
|
it('should be the selection style of the editor', () => {
|
|
|
- expect(editor.selectionStyle).to.deep.equal(
|
|
|
- CodeEditor.defaultSelectionStyle
|
|
|
- );
|
|
|
+ expect(editor.selectionStyle).toEqual(CodeEditor.defaultSelectionStyle);
|
|
|
});
|
|
|
|
|
|
it('should be settable', () => {
|
|
@@ -101,105 +95,105 @@ describe('CodeMirrorEditor', () => {
|
|
|
color: 'black'
|
|
|
};
|
|
|
editor.selectionStyle = style;
|
|
|
- expect(editor.selectionStyle).to.deep.equal(style);
|
|
|
+ expect(editor.selectionStyle).toEqual(style);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#editor', () => {
|
|
|
it('should be the codemirror editor wrapped by the editor', () => {
|
|
|
const cm = editor.editor;
|
|
|
- expect(cm.getDoc()).to.equal(editor.doc);
|
|
|
+ expect(cm.getDoc()).toBe(editor.doc);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#doc', () => {
|
|
|
it('should be the codemirror doc wrapped by the editor', () => {
|
|
|
const doc = editor.doc;
|
|
|
- expect(doc.getEditor()).to.equal(editor.editor);
|
|
|
+ expect(doc.getEditor()).toBe(editor.editor);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#lineCount', () => {
|
|
|
it('should get the number of lines in the editor', () => {
|
|
|
- expect(editor.lineCount).to.equal(1);
|
|
|
+ expect(editor.lineCount).toBe(1);
|
|
|
editor.model.value.text = 'foo\nbar\nbaz';
|
|
|
- expect(editor.lineCount).to.equal(3);
|
|
|
+ expect(editor.lineCount).toBe(3);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#getOption()', () => {
|
|
|
it('should get whether line numbers should be shown', () => {
|
|
|
- expect(editor.getOption('lineNumbers')).to.equal(false);
|
|
|
+ expect(editor.getOption('lineNumbers')).toBe(false);
|
|
|
});
|
|
|
|
|
|
it('should get whether horizontally scrolling should be used', () => {
|
|
|
- expect(editor.getOption('lineWrap')).to.equal('on');
|
|
|
+ expect(editor.getOption('lineWrap')).toBe('on');
|
|
|
});
|
|
|
|
|
|
it('should get whether the editor is readonly', () => {
|
|
|
- expect(editor.getOption('readOnly')).to.equal(false);
|
|
|
+ expect(editor.getOption('readOnly')).toBe(false);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#setOption()', () => {
|
|
|
it('should set whether line numbers should be shown', () => {
|
|
|
editor.setOption('lineNumbers', true);
|
|
|
- expect(editor.getOption('lineNumbers')).to.equal(true);
|
|
|
+ expect(editor.getOption('lineNumbers')).toBe(true);
|
|
|
});
|
|
|
|
|
|
it('should set whether horizontally scrolling should be used', () => {
|
|
|
editor.setOption('lineWrap', 'off');
|
|
|
- expect(editor.getOption('lineWrap')).to.equal('off');
|
|
|
+ expect(editor.getOption('lineWrap')).toBe('off');
|
|
|
});
|
|
|
|
|
|
it('should set whether the editor is readonly', () => {
|
|
|
editor.setOption('readOnly', true);
|
|
|
- expect(editor.getOption('readOnly')).to.equal(true);
|
|
|
+ expect(editor.getOption('readOnly')).toBe(true);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#model', () => {
|
|
|
it('should get the model used by the editor', () => {
|
|
|
- expect(editor.model).to.equal(model);
|
|
|
+ expect(editor.model).toBe(model);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#lineHeight', () => {
|
|
|
it('should get the text height of a line in the editor', () => {
|
|
|
- expect(editor.lineHeight).to.be.above(0);
|
|
|
+ expect(editor.lineHeight).toBeGreaterThan(0);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#charWidth', () => {
|
|
|
it('should get the character width in the editor', () => {
|
|
|
- expect(editor.charWidth).to.be.above(0);
|
|
|
+ expect(editor.charWidth).toBeGreaterThan(0);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#isDisposed', () => {
|
|
|
it('should test whether the editor is disposed', () => {
|
|
|
- expect(editor.isDisposed).to.equal(false);
|
|
|
+ expect(editor.isDisposed).toBe(false);
|
|
|
editor.dispose();
|
|
|
- expect(editor.isDisposed).to.equal(true);
|
|
|
+ expect(editor.isDisposed).toBe(true);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#dispose()', () => {
|
|
|
it('should dispose of the resources used by the editor', () => {
|
|
|
- expect(editor.isDisposed).to.equal(false);
|
|
|
+ expect(editor.isDisposed).toBe(false);
|
|
|
editor.dispose();
|
|
|
- expect(editor.isDisposed).to.equal(true);
|
|
|
+ expect(editor.isDisposed).toBe(true);
|
|
|
editor.dispose();
|
|
|
- expect(editor.isDisposed).to.equal(true);
|
|
|
+ expect(editor.isDisposed).toBe(true);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#getLine()', () => {
|
|
|
it('should get a line of text', () => {
|
|
|
model.value.text = 'foo\nbar';
|
|
|
- expect(editor.getLine(0)).to.equal('foo');
|
|
|
- expect(editor.getLine(1)).to.equal('bar');
|
|
|
- expect(editor.getLine(2)).to.be.undefined;
|
|
|
+ expect(editor.getLine(0)).toBe('foo');
|
|
|
+ expect(editor.getLine(1)).toBe('bar');
|
|
|
+ expect(editor.getLine(2)).toBeUndefined();
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -210,12 +204,12 @@ describe('CodeMirrorEditor', () => {
|
|
|
column: 2,
|
|
|
line: 1
|
|
|
};
|
|
|
- expect(editor.getOffsetAt(pos)).to.equal(6);
|
|
|
+ expect(editor.getOffsetAt(pos)).toBe(6);
|
|
|
pos = {
|
|
|
column: 2,
|
|
|
line: 5
|
|
|
};
|
|
|
- expect(editor.getOffsetAt(pos)).to.equal(7);
|
|
|
+ expect(editor.getOffsetAt(pos)).toBe(7);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -223,11 +217,11 @@ describe('CodeMirrorEditor', () => {
|
|
|
it('should get the position for a given offset', () => {
|
|
|
model.value.text = 'foo\nbar';
|
|
|
let pos = editor.getPositionAt(6);
|
|
|
- expect(pos.column).to.equal(2);
|
|
|
- expect(pos.line).to.equal(1);
|
|
|
+ expect(pos.column).toBe(2);
|
|
|
+ expect(pos.line).toBe(1);
|
|
|
pos = editor.getPositionAt(101);
|
|
|
- expect(pos.column).to.equal(3);
|
|
|
- expect(pos.line).to.equal(1);
|
|
|
+ expect(pos.column).toBe(3);
|
|
|
+ expect(pos.line).toBe(1);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -235,7 +229,7 @@ describe('CodeMirrorEditor', () => {
|
|
|
it('should undo one edit', () => {
|
|
|
model.value.text = 'foo';
|
|
|
editor.undo();
|
|
|
- expect(model.value.text).to.equal('');
|
|
|
+ expect(model.value.text).toBe('');
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -244,7 +238,7 @@ describe('CodeMirrorEditor', () => {
|
|
|
model.value.text = 'foo';
|
|
|
editor.undo();
|
|
|
editor.redo();
|
|
|
- expect(model.value.text).to.equal('foo');
|
|
|
+ expect(model.value.text).toBe('foo');
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -253,32 +247,32 @@ describe('CodeMirrorEditor', () => {
|
|
|
model.value.text = 'foo';
|
|
|
editor.clearHistory();
|
|
|
editor.undo();
|
|
|
- expect(model.value.text).to.equal('foo');
|
|
|
+ expect(model.value.text).toBe('foo');
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#focus()', () => {
|
|
|
it('should give focus to the editor', () => {
|
|
|
- expect(host.contains(document.activeElement)).to.equal(false);
|
|
|
+ expect(host.contains(document.activeElement)).toBe(false);
|
|
|
editor.focus();
|
|
|
- expect(host.contains(document.activeElement)).to.equal(true);
|
|
|
+ expect(host.contains(document.activeElement)).toBe(true);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#hasFocus()', () => {
|
|
|
it('should test whether the editor has focus', () => {
|
|
|
- expect(editor.hasFocus()).to.equal(false);
|
|
|
+ expect(editor.hasFocus()).toBe(false);
|
|
|
editor.focus();
|
|
|
- expect(editor.hasFocus()).to.equal(true);
|
|
|
+ expect(editor.hasFocus()).toBe(true);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#blur()', () => {
|
|
|
it('should blur the editor', () => {
|
|
|
editor.focus();
|
|
|
- expect(host.contains(document.activeElement)).to.equal(true);
|
|
|
+ expect(host.contains(document.activeElement)).toBe(true);
|
|
|
editor.blur();
|
|
|
- expect(host.contains(document.activeElement)).to.equal(false);
|
|
|
+ expect(host.contains(document.activeElement)).toBe(false);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -286,16 +280,16 @@ describe('CodeMirrorEditor', () => {
|
|
|
describe('focus', () => {
|
|
|
it('should add the focus class to the host', () => {
|
|
|
simulate(editor.editor.getInputField(), 'focus');
|
|
|
- expect(host.classList.contains('jp-mod-focused')).to.equal(true);
|
|
|
+ expect(host.classList.contains('jp-mod-focused')).toBe(true);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('blur', () => {
|
|
|
it('should remove the focus class from the host', () => {
|
|
|
simulate(editor.editor.getInputField(), 'focus');
|
|
|
- expect(host.classList.contains('jp-mod-focused')).to.equal(true);
|
|
|
+ expect(host.classList.contains('jp-mod-focused')).toBe(true);
|
|
|
simulate(editor.editor.getInputField(), 'blur');
|
|
|
- expect(host.classList.contains('jp-mod-focused')).to.equal(false);
|
|
|
+ expect(host.classList.contains('jp-mod-focused')).toBe(false);
|
|
|
});
|
|
|
});
|
|
|
});
|
|
@@ -303,7 +297,7 @@ describe('CodeMirrorEditor', () => {
|
|
|
describe('#refresh()', () => {
|
|
|
it('should repaint the editor', () => {
|
|
|
editor.refresh();
|
|
|
- expect(editor).to.be.ok;
|
|
|
+ expect(editor).toBeTruthy();
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -317,13 +311,13 @@ describe('CodeMirrorEditor', () => {
|
|
|
const disposable = editor.addKeydownHandler(handler);
|
|
|
let evt = generate('keydown', { keyCode: ENTER });
|
|
|
editor.editor.triggerOnKeyDown(evt);
|
|
|
- expect(called).to.equal(1);
|
|
|
+ expect(called).toBe(1);
|
|
|
disposable.dispose();
|
|
|
- expect(disposable.isDisposed).to.equal(true);
|
|
|
+ expect(disposable.isDisposed).toBe(true);
|
|
|
|
|
|
evt = generate('keydown', { keyCode: ENTER });
|
|
|
editor.editor.triggerOnKeyDown(evt);
|
|
|
- expect(called).to.equal(1);
|
|
|
+ expect(called).toBe(1);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -331,7 +325,7 @@ describe('CodeMirrorEditor', () => {
|
|
|
it('should set the size of the editor in pixels', () => {
|
|
|
editor.setSize({ width: 100, height: 100 });
|
|
|
editor.setSize(null);
|
|
|
- expect(editor).to.be.ok;
|
|
|
+ expect(editor).toBeTruthy();
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -339,7 +333,7 @@ describe('CodeMirrorEditor', () => {
|
|
|
it('should reveal the given position in the editor', () => {
|
|
|
model.value.text = TEXT;
|
|
|
editor.revealPosition({ line: 50, column: 0 });
|
|
|
- expect(editor).to.be.ok;
|
|
|
+ expect(editor).toBeTruthy();
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -350,7 +344,7 @@ describe('CodeMirrorEditor', () => {
|
|
|
const end = { line: 52, column: 0 };
|
|
|
editor.setSelection({ start, end });
|
|
|
editor.revealSelection(editor.getSelection());
|
|
|
- expect(editor).to.be.ok;
|
|
|
+ expect(editor).toBeTruthy();
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -359,9 +353,9 @@ describe('CodeMirrorEditor', () => {
|
|
|
model.value.text = TEXT;
|
|
|
const coord = editor.getCoordinateForPosition({ line: 10, column: 1 });
|
|
|
if (typeof process !== 'undefined') {
|
|
|
- expect(coord.left).to.equal(0);
|
|
|
+ expect(coord.left).toBe(0);
|
|
|
} else {
|
|
|
- expect(coord.left).to.be.above(0);
|
|
|
+ expect(coord.left).toBeGreaterThan(0);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
@@ -371,8 +365,8 @@ describe('CodeMirrorEditor', () => {
|
|
|
model.value.text = TEXT;
|
|
|
const coord = editor.getCoordinateForPosition({ line: 10, column: 1 });
|
|
|
const newPos = editor.getPositionForCoordinate(coord)!;
|
|
|
- expect(newPos.line).to.be.ok;
|
|
|
- expect(newPos.column).to.be.ok;
|
|
|
+ expect(newPos.line).toBeTruthy();
|
|
|
+ expect(newPos.column).toBeTruthy();
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -380,13 +374,13 @@ describe('CodeMirrorEditor', () => {
|
|
|
it('should get the primary position of the cursor', () => {
|
|
|
model.value.text = TEXT;
|
|
|
let pos = editor.getCursorPosition();
|
|
|
- expect(pos.line).to.equal(0);
|
|
|
- expect(pos.column).to.equal(0);
|
|
|
+ expect(pos.line).toBe(0);
|
|
|
+ expect(pos.column).toBe(0);
|
|
|
|
|
|
editor.setCursorPosition({ line: 12, column: 3 });
|
|
|
pos = editor.getCursorPosition();
|
|
|
- expect(pos.line).to.equal(12);
|
|
|
- expect(pos.column).to.equal(3);
|
|
|
+ expect(pos.line).toBe(12);
|
|
|
+ expect(pos.column).toBe(3);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -395,16 +389,16 @@ describe('CodeMirrorEditor', () => {
|
|
|
model.value.text = TEXT;
|
|
|
editor.setCursorPosition({ line: 12, column: 3 });
|
|
|
const pos = editor.getCursorPosition();
|
|
|
- expect(pos.line).to.equal(12);
|
|
|
- expect(pos.column).to.equal(3);
|
|
|
+ expect(pos.line).toBe(12);
|
|
|
+ expect(pos.column).toBe(3);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#getSelection()', () => {
|
|
|
it('should get the primary selection of the editor', () => {
|
|
|
const selection = editor.getSelection();
|
|
|
- expect(selection.start.line).to.equal(0);
|
|
|
- expect(selection.end.line).to.equal(0);
|
|
|
+ expect(selection.start.line).toBe(0);
|
|
|
+ expect(selection.end.line).toBe(0);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -414,8 +408,8 @@ describe('CodeMirrorEditor', () => {
|
|
|
const start = { line: 50, column: 0 };
|
|
|
const end = { line: 52, column: 0 };
|
|
|
editor.setSelection({ start, end });
|
|
|
- expect(editor.getSelection().start).to.deep.equal(start);
|
|
|
- expect(editor.getSelection().end).to.deep.equal(end);
|
|
|
+ expect(editor.getSelection().start).toEqual(start);
|
|
|
+ expect(editor.getSelection().end).toEqual(end);
|
|
|
});
|
|
|
|
|
|
it('should remove any secondary cursors', () => {
|
|
@@ -430,7 +424,7 @@ describe('CodeMirrorEditor', () => {
|
|
|
};
|
|
|
editor.setSelections([range0, range1]);
|
|
|
editor.setSelection(range1);
|
|
|
- expect(editor.getSelections().length).to.equal(1);
|
|
|
+ expect(editor.getSelections().length).toBe(1);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -447,8 +441,8 @@ describe('CodeMirrorEditor', () => {
|
|
|
};
|
|
|
editor.setSelections([range0, range1]);
|
|
|
const selections = editor.getSelections();
|
|
|
- expect(selections[0].start.line).to.equal(50);
|
|
|
- expect(selections[1].end.line).to.equal(54);
|
|
|
+ expect(selections[0].start.line).toBe(50);
|
|
|
+ expect(selections[1].end.line).toBe(54);
|
|
|
});
|
|
|
});
|
|
|
|
|
@@ -465,25 +459,25 @@ describe('CodeMirrorEditor', () => {
|
|
|
};
|
|
|
editor.setSelections([range0, range1]);
|
|
|
const selections = editor.getSelections();
|
|
|
- expect(selections[0].start.line).to.equal(50);
|
|
|
- expect(selections[1].end.line).to.equal(54);
|
|
|
+ expect(selections[0].start.line).toBe(50);
|
|
|
+ expect(selections[1].end.line).toBe(54);
|
|
|
});
|
|
|
|
|
|
it('should set a default selection for an empty array', () => {
|
|
|
model.value.text = TEXT;
|
|
|
editor.setSelections([]);
|
|
|
const selection = editor.getSelection();
|
|
|
- expect(selection.start.line).to.equal(0);
|
|
|
- expect(selection.end.line).to.equal(0);
|
|
|
+ expect(selection.start.line).toBe(0);
|
|
|
+ expect(selection.end.line).toBe(0);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('#onKeydown()', () => {
|
|
|
it('should run when there is a keydown event on the editor', () => {
|
|
|
const event = generate('keydown', { keyCode: UP_ARROW });
|
|
|
- expect(editor.methods).to.not.contain('onKeydown');
|
|
|
+ expect(editor.methods).toEqual(expect.not.arrayContaining(['onKeydown']));
|
|
|
editor.editor.triggerOnKeyDown(event);
|
|
|
- expect(editor.methods).to.contain('onKeydown');
|
|
|
+ expect(editor.methods).toEqual(expect.arrayContaining(['onKeydown']));
|
|
|
});
|
|
|
});
|
|
|
});
|