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 return undefined if original request or cursor are null', () => {
let model = new CompleterModel();
expect(model.createPatch('foo')).to.be.undefined;
});
it('should reset model if change is shorter than original', () => {
let model = new CompleterModel();
let currentValue = 'foo';
let newValue = 'fo';
let cursor: Completer.ICursorSpan = { start: 0, end: 0 };
let request = makeState(currentValue);
let change = makeState(newValue);
model.original = request;
model.cursor = cursor;
model.current = change;
expect(model.current).to.be.null;
expect(model.original).to.be.null;
expect(model.options().next()).to.be.undefined;
});
});
it('should be safe to reset', () => {
let model = new CompleterModel();
let widget = new Completer({
editor: null,
model: new CompleterModel()
});
expect(widget.model).not.to.equal(model);
widget.model = model;
expect(widget.model).to.equal(model);
});
});
it('should trigger a selected signal on mouse down', () => {
let anchor = createEditorWidget();
let model = new CompleterModel();
let options: Completer.IOptions = {
editor: anchor.editor,
model
};
let value = '';
let listener = (sender: any, selected: string) => {
value = selected;
};
model.setOptions(['foo', 'bar', 'baz'], {
foo: 'instance',
bar: 'function'
});
model.query = 'b';
Widget.attach(anchor, document.body);
let widget = new Completer(options);
it('should emit a signal when an item is selected', () => {
let anchor = createEditorWidget();
let options: Completer.IOptions = {
editor: anchor.editor,
model: new CompleterModel()
};
let value = '';
let listener = (sender: any, selected: string) => {
value = selected;
};
options.model.setOptions(['foo', 'bar']);
Widget.attach(anchor, document.body);
let widget = new Completer(options);
widget.selected.connect(listener);
Widget.attach(widget, document.body);
MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
expect(value).to.equal('');
widget.selectActive();
expect(value).to.equal('foo');
it('should be true if model has been disposed', () => {
let model = new CompleterModel();
expect(model.isDisposed).to.equal(false);
model.dispose();
expect(model.isDisposed).to.equal(true);
});
});
it('should not signal when options have not changed', () => {
let model = new CompleterModel();
let called = 0;
let listener = (sender: any, args: void) => {
called++;
};
model.stateChanged.connect(listener);
expect(called).to.equal(0);
model.setOptions(['foo']);
model.setOptions(['foo']);
expect(called).to.equal(1);
model.setOptions(['foo'], { foo: 'instance' });
model.setOptions(['foo'], { foo: 'instance' });
expect(called).to.equal(2);
model.setOptions([], {});
model.setOptions([], {});
expect(called).to.equal(3);
});
it('should set current change value', () => {
let model = new CompleterModel();
let currentValue = 'foo';
let newValue = 'foob';
let cursor: Completer.ICursorSpan = { start: 0, end: 0 };
let request = makeState(currentValue);
let change = makeState(newValue);
(change as any).column = 4;
model.original = request;
model.cursor = cursor;
expect(model.current).to.equal(request);
model.handleTextChange(change);
expect(model.current).to.equal(change);
});
it('should default to null', () => {
let model = new CompleterModel();
expect(model.cursor).to.be.null;
});
it('should be safe to reset', () => {
let model = new CompleterModel();
let widget = new Completer({
editor: null,
model: new CompleterModel()
});
expect(widget.model).not.to.equal(model);
widget.model = model;
expect(widget.model).to.equal(model);
});
});