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 emit when an instance has been added', async () => {
const instance = new ObservableDisposable();
const promise = signalToPromise(pool.added);
await pool.add(instance);
const [sender, args] = await promise;
expect(sender).to.equal(pool);
expect(args).to.equal(instance);
instance.dispose();
});
});
it('should trigger a save', () => {
let promise = signalToPromise(context.fileChanged);
context.model.fromString('bar');
expect(handler.isActive).to.equal(false);
handler.saveInterval = 1;
handler.start();
return promise;
});
it('should emit when the current widget has been updated', async () => {
const widget = createWidget();
let promise = signalToPromise(tracker.currentChanged);
Widget.attach(widget, document.body);
focus(widget);
void tracker.add(widget);
await promise;
widget.dispose();
});
});
it('should save when clicked', async () => {
const button = ToolbarItems.createSaveButton(panel);
Widget.attach(button, document.body);
let promise = signalToPromise(context.fileChanged);
await framePromise();
simulate(button.node.firstChild as HTMLElement, 'mousedown');
await promise;
button.dispose();
});
it('should switch to the grandparent directory', async () => {
Widget.attach(crumbs, document.body);
MessageLoop.sendMessage(crumbs, Widget.Msg.UpdateRequest);
let items = crumbs.node.querySelectorAll(ITEM_QUERY);
const promise = signalToPromise(model.pathChanged);
simulate(items[1], 'click');
await promise;
MessageLoop.sendMessage(crumbs, Widget.Msg.UpdateRequest);
items = crumbs.node.querySelectorAll(ITEM_QUERY);
expect(items.length).to.equal(2);
expect(model.path).to.equal(first);
});
it('should emit when a plugin changes', async () => {
const id = 'alpha';
const schema: ISettingRegistry.ISchema = { type: 'object' };
connector.schemas[id] = schema;
settings = (await registry.load(id)) as Settings;
let promise = signalToPromise(settings.changed);
await settings.set('foo', 'bar');
await promise;
});
});
it('should add a new default cell when cells are cleared', async () => {
const model = widget.model;
widget.notebookConfig = {
...widget.notebookConfig,
defaultCell: 'raw'
};
let promise = signalToPromise(model.cells.changed);
model.cells.clear();
await promise;
expect(model.cells.length).to.equal(0);
await signalToPromise(model.cells.changed);
expect(model.cells.length).to.equal(1);
expect(model.cells.get(0)).to.be.an.instanceof(RawCellModel);
});
});
it('should be called upon an editor edge request', async () => {
const history = new TestHistory({ session });
expect(history.methods).to.not.contain('onEdgeRequest');
const host = document.createElement('div');
const model = new CodeEditor.Model();
const editor = new CodeMirrorEditor({ model, host });
history.editor = editor;
history.push('foo');
const promise = signalToPromise(editor.model.value.changed);
editor.edgeRequested.emit('top');
expect(history.methods).to.contain('onEdgeRequest');
await promise;
expect(editor.model.value.text).to.equal('foo');
});
});
it('should save when clicked', async () => {
const button = ToolbarItems.createSaveButton(panel);
Widget.attach(button, document.body);
let promise = signalToPromise(context.fileChanged);
await framePromise();
simulate(button.node.firstChild as HTMLElement, 'mousedown');
await promise;
button.dispose();
});
it('should add a new default cell when cells are cleared', async () => {
const model = widget.model!;
widget.notebookConfig = {
...widget.notebookConfig,
defaultCell: 'raw'
};
let promise = signalToPromise(model.cells.changed);
model.cells.clear();
await promise;
expect(model.cells.length).to.equal(0);
await signalToPromise(model.cells.changed);
expect(model.cells.length).to.equal(1);
expect(model.cells.get(0)).to.be.an.instanceof(RawCellModel);
});
});