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 unrender a markdown cell when switching to edit mode', () => {
const widget = createActiveWidget();
Widget.attach(widget, document.body);
MessageLoop.sendMessage(widget, Widget.Msg.ActivateRequest);
const cell = widget.model!.contentFactory.createMarkdownCell({});
cell.value.text = '# Hello'; // Should be rendered with content.
widget.model!.cells.push(cell);
const child = widget.widgets[widget.widgets.length - 1] as MarkdownCell;
expect(child.rendered).to.equal(true);
widget.activeCellIndex = widget.widgets.length - 1;
widget.mode = 'edit';
expect(child.rendered).to.equal(false);
});
});
createBody(value: Body): Widget {
let body: Widget;
if (typeof value === 'string') {
body = new Widget({ node: document.createElement('span') });
body.node.textContent = value;
} else if (value instanceof Widget) {
body = value;
} else {
body = ReactWidget.create(value);
// Immediately update the body even though it has not yet attached in
// order to trigger a render of the DOM nodes from the React element.
MessageLoop.sendMessage(body, Widget.Msg.UpdateRequest);
}
body.addClass('jp-Dialog-body');
Styling.styleNode(body.node);
return body;
}
it('should give the focus to the console prompt', () => {
expect(panel.methods).to.not.contain('onActivateRequest');
Widget.attach(panel, document.body);
MessageLoop.sendMessage(panel, Widget.Msg.ActivateRequest);
expect(panel.methods).to.contain('onActivateRequest');
expect(panel.console.promptCell.editor.hasFocus()).to.equal(true);
return dismissDialog();
});
});
it('should focus the prompt editor', () => {
expect(widget.promptCell).to.not.be.ok;
expect(widget.methods).to.not.contain('onActivateRequest');
Widget.attach(widget, document.body);
MessageLoop.sendMessage(widget, Widget.Msg.ActivateRequest);
expect(widget.methods).to.contain('onActivateRequest');
expect(widget.promptCell.editor.hasFocus()).to.equal(true);
});
});
it('should focus the node after an update', async () => {
Widget.attach(widget, document.body);
MessageLoop.sendMessage(widget, Widget.Msg.ActivateRequest);
expect(widget.methods).to.contain('onActivateRequest');
await framePromise();
expect(widget.editor.hasFocus()).to.equal(true);
});
});
it('should set the content after the context is ready', async () => {
await context.ready;
MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
const img = widget.node.querySelector('img') as HTMLImageElement;
expect(img.src).to.contain(IMAGE.content);
});
it('should focus the editor', () => {
Widget.attach(widget, document.body);
MessageLoop.sendMessage(widget, Widget.Msg.ActivateRequest);
expect(widget.methods).to.contain('onActivateRequest');
expect(widget.editor.hasFocus()).to.be.true;
});
});
it('should accept options with a renderer', () => {
let options: Completer.IOptions = {
editor: null,
model: new CompleterModel(),
renderer: new CustomRenderer()
};
options.model!.setOptions(['foo', 'bar']);
let widget = new Completer(options);
expect(widget).to.be.an.instanceof(Completer);
MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
let items = widget.node.querySelectorAll(`.${ITEM_CLASS}`);
expect(items).to.have.length(2);
expect(Array.from(items[0].classList)).to.contain(TEST_ITEM_CLASS);
});
});
it('should handle fit requests', () => {
widget.processMessage(Widget.Msg.FitRequest);
expect(widget.methods).to.contain('onFitRequest');
});
});
it('should update the widget', () => {
const widget = new LogCodeCell().initializeState();
expect(widget.methods).not.toContain('onUpdateRequest');
MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
expect(widget.methods).toContain('onUpdateRequest');
});
});