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 remove event listeners', () => {
Widget.attach(crumbs, document.body);
Widget.detach(crumbs);
simulate(crumbs.node, 'click');
expect(crumbs.events).to.not.contain('click');
});
});
it('should focus the terminal element', () => {
Widget.detach(widget);
Widget.attach(widget, document.body);
expect(widget.node.contains(document.activeElement)).to.equal(false);
MessageLoop.sendMessage(widget, Widget.Msg.ActivateRequest);
expect(widget.methods).to.contain('onActivateRequest');
expect(widget.node.contains(document.activeElement)).to.equal(true);
});
});
it('should return focus to the original focused element', () => {
const input = document.createElement('input');
document.body.appendChild(input);
input.focus();
Widget.attach(dialog, document.body);
Widget.detach(dialog);
expect(document.activeElement).toBe(input);
document.body.removeChild(input);
});
});
it('should remove event listeners', async () => {
const widget = createActiveWidget();
widget.model!.fromJSON(NBTestUtils.DEFAULT_CONTENT);
Widget.attach(widget, document.body);
const child = widget.widgets[0];
await framePromise();
Widget.detach(widget);
expect(widget.methods).to.contain('onBeforeDetach');
widget.events = [];
simulate(widget.node, 'mousedown');
expect(widget.events).to.not.contain('mousedown');
simulate(widget.node, 'dblclick');
expect(widget.events).to.not.contain('dblclick');
simulate(child.node, 'focusin');
expect(widget.events).to.not.contain('focusin');
widget.dispose();
});
});
it('should remove event listeners', async () => {
Widget.attach(widget, document.body);
await framePromise();
Widget.detach(widget);
expect(widget.methods).to.contain('onBeforeDetach');
widget.events = [];
simulate(widget.node, 'mousedown');
expect(widget.events).to.not.contain('mousedown');
});
});
it('should remove event listeners', () => {
Widget.attach(editor, document.body);
Widget.detach(editor);
expect(editor.methods).to.contain('onBeforeDetach');
editor.editor.focus();
simulate(editor.editorHostNode, 'blur');
simulate(editor.revertButtonNode, 'click');
simulate(editor.commitButtonNode, 'click');
expect(editor.events).to.eql([]);
});
});
const two = createWidget();
let total = 0;
let promise = testEmission(tracker.currentChanged, {
find: () => {
return total === 1;
}
});
tracker.widgetAdded.connect(() => {
total++;
});
void tracker.add(one);
void tracker.inject(two);
Widget.attach(two, document.body);
focus(two);
Widget.detach(two);
await promise;
one.dispose();
two.dispose();
});
});
const source = require('../../../examples/filebrowser/sample.md')
.default as string;
const f = markdownRendererFactory;
const mimeType = 'text/markdown';
const model = createModel(mimeType, source);
const w = f.createRenderer({ mimeType, ...defaultOptions });
await w.renderModel(model);
Widget.attach(w, document.body);
const node = document.getElementById('Title-third-level')!;
expect(node.localName).to.equal('h3');
const anchor = node.firstChild!.nextSibling as HTMLAnchorElement;
expect(anchor.href).to.contain('#Title-third-level');
expect(anchor.target).to.equal('_self');
expect(anchor.className).to.contain('jp-InternalAnchorLink');
expect(anchor.textContent).to.equal('¶');
Widget.detach(w);
});