app.shell throws if invalid area

Jeremy Tuloup 5 years ago
parent 57d7000390
commit 08f94a017a

@ -169,13 +169,16 @@ export class ClassicShell extends Widget implements JupyterFrontEnd.IShell {
* @param area The area
*/
widgets(area: Shell.Area): IIterator<Widget> {
if (area === 'top') {
return iter(this._topHandler.panel.widgets);
}
if (area === 'menu') {
return iter(this._menuHandler.panel.widgets);
switch (area ?? 'main') {
case 'top':
return iter(this._topHandler.panel.widgets);
case 'menu':
return iter(this._menuHandler.panel.widgets);
case 'main':
return iter(this._main.widgets);
default:
throw new Error(`Invalid area: ${area}`);
}
return iter(this._main.widgets);
}
private _topWrapper: Panel;

@ -3,6 +3,12 @@
import { ClassicShell } from '@jupyterlab-classic/application';
import { JupyterFrontEnd } from '@jupyterlab/application';
import { toArray } from '@lumino/algorithm';
import { Widget } from '@lumino/widgets';
describe('Shell', () => {
describe('#constructor()', () => {
it('should create a LabShell instance', () => {
@ -10,4 +16,22 @@ describe('Shell', () => {
expect(shell).toBeInstanceOf(ClassicShell);
});
});
describe('#widgets()', () => {
it('should add widgets to existing areas', () => {
const shell = new ClassicShell();
const widget = new Widget();
shell.add(widget, 'main');
const widgets = toArray(shell.widgets('main'));
expect(widgets).toEqual([widget]);
});
it('should throw an exception if the area does not exist', () => {
const classicShell = new ClassicShell();
const shell = classicShell as JupyterFrontEnd.IShell;
expect(() => {
shell.widgets('left');
}).toThrow('Invalid area: left');
});
});
});

Loading…
Cancel
Save