Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should call model change handler if model exists', () => {
const completer = new Completer({
editor: null,
model: new TestCompleterModel()
});
const handler = new TestCompletionHandler({ completer, connector });
const editor = createEditorWidget().editor;
const model = completer.model as TestCompleterModel;
handler.editor = editor;
expect(model.methods).to.not.contain('handleTextChange');
editor.model.value.text = 'bar';
editor.setCursorPosition({ line: 0, column: 2 });
// This signal is emitted (again) because the cursor position that
// a natural user would create need to be recreated here.
(editor.model.value.changed as any).emit({ type: 'set', value: 'bar' });
expect(model.methods).to.contain('handleTextChange');
});
editor.setCursorPosition(position);
let request: Completer.ITextState = {
column: position.column,
lineHeight: editor.lineHeight,
charWidth: editor.charWidth,
line: position.line,
text: 'a'
};
model.original = request;
model.cursor = { start: text.length - 1, end: text.length };
model.setOptions(['abc', 'abd', 'abe', 'abi']);
let widget = new Completer({ model, editor: code.editor });
Widget.attach(widget, document.body);
MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
simulate(document.body, 'scroll');
// Because the scroll handling is asynchronous, this test uses a large
// timeout (500ms) to guarantee the scroll handling has finished.
await sleep(500);
let top = parseInt(window.getComputedStyle(widget.node).top, 10);
let bottom = Math.floor(coords.bottom);
expect(top + panel.node.scrollTop).to.equal(bottom);
widget.dispose();
code.dispose();
panel.dispose();
});
});
canStartKernel: true,
rendermime,
contentFactory,
mimeTypeService: editorServices.mimeTypeService
});
docRegistry.addModelFactory(mFactory);
docRegistry.addWidgetFactory(wFactory);
let notebookPath = PageConfig.getOption('notebookPath');
let nbWidget = docManager.open(notebookPath) as NotebookPanel;
let palette = new CommandPalette({ commands });
const editor =
nbWidget.content.activeCell && nbWidget.content.activeCell.editor;
const model = new CompleterModel();
const completer = new Completer({ editor, model });
const connector = new KernelConnector({ session: nbWidget.session });
const handler = new CompletionHandler({ completer, connector });
// Set the handler's editor.
handler.editor = editor;
// Listen for active cell changes.
nbWidget.content.activeCellChanged.connect((sender, cell) => {
handler.editor = cell && cell.editor;
});
// Hide the widget when it first loads.
completer.hide();
let panel = new SplitPanel();
panel.id = 'main';
fileExtensions: ['.ipynb'],
defaultFor: ['.ipynb'],
preferKernel: true,
canStartKernel: true,
rendermime, contentFactory,
mimeTypeService: editorServices.mimeTypeService
});
docRegistry.addModelFactory(mFactory);
docRegistry.addWidgetFactory(wFactory);
let nbWidget = docManager.open(NOTEBOOK) as NotebookPanel;
let palette = new CommandPalette({ commands });
const editor = nbWidget.notebook.activeCell && nbWidget.notebook.activeCell.editor;
const model = new CompleterModel();
const completer = new Completer({ editor, model });
const handler = new CompletionHandler({ completer, session: nbWidget.session });
// Set the handler's editor.
handler.editor = editor;
// Listen for active cell changes.
nbWidget.notebook.activeCellChanged.connect((sender, cell) => {
handler.editor = cell && cell.editor;
});
// Hide the widget when it first loads.
completer.hide();
let panel = new SplitPanel();
panel.id = 'main';
panel.orientation = 'horizontal';
it('should be settable', () => {
let widget = new Completer({ editor: null });
expect(widget.model).to.be.null;
widget.model = new CompleterModel();
expect(widget.model).to.be.an.instanceof(CompleterModel);
});
it('should create a completer widget', () => {
let widget = new Completer({ editor: null });
expect(widget).to.be.an.instanceof(Completer);
expect(Array.from(widget.node.classList)).to.contain('jp-Completer');
});
it('should accept options with a model', () => {
let options: Completer.IOptions = {
editor: null,
model: new CompleterModel()
};
let widget = new Completer(options);
expect(widget).to.be.an.instanceof(Completer);
expect(widget.model).to.equal(options.model);
});
it('should create a completer widget', () => {
let widget = new Completer({ editor: null });
expect(widget).to.be.an.instanceof(Completer);
expect(Array.from(widget.node.classList)).to.contain('jp-Completer');
});
editor.setCursorPosition(position);
let request: Completer.ITextState = {
column: position.column,
lineHeight: editor.lineHeight,
charWidth: editor.charWidth,
line: position.line,
text: 'a'
};
model.original = request;
model.cursor = { start: 0, end: 1 };
model.setOptions(['abc', 'abd', 'abe', 'abi']);
let widget = new Completer({ model, editor: code.editor });
widget.hide();
expect(called).to.equal(false);
widget.visibilityChanged.connect(() => {
called = true;
});
Widget.attach(widget, document.body);
MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
await framePromise();
expect(called).to.equal(true);
widget.dispose();
code.dispose();
panel.dispose();
});
});
editor.setCursorPosition(position);
let request: Completer.ITextState = {
column: position.column,
lineHeight: editor.lineHeight,
charWidth: editor.charWidth,
line: position.line,
text: 'a'
};
model.original = request;
model.cursor = { start: 0, end: 1 };
model.setOptions(['abc', 'abd', 'abe', 'abi']);
let widget = new Completer({ model, editor: code.editor });
widget.hide();
expect(called).to.equal(false);
widget.visibilityChanged.connect(() => {
called = true;
});
Widget.attach(widget, document.body);
MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
await framePromise();
expect(called).to.equal(true);
widget.dispose();
code.dispose();
panel.dispose();
});
});