From 08f94a017a609f5bd8e1e2f2e0073ec7818c70b1 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Wed, 13 Jan 2021 09:53:23 +0100 Subject: [PATCH] app.shell throws if invalid area --- packages/application/src/shell.ts | 15 +++++++++------ packages/application/test/shell.spec.ts | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/application/src/shell.ts b/packages/application/src/shell.ts index c164ee089..a7b7adbad 100644 --- a/packages/application/src/shell.ts +++ b/packages/application/src/shell.ts @@ -169,13 +169,16 @@ export class ClassicShell extends Widget implements JupyterFrontEnd.IShell { * @param area The area */ widgets(area: Shell.Area): IIterator { - 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; diff --git a/packages/application/test/shell.spec.ts b/packages/application/test/shell.spec.ts index f8cd68b1c..17f7b70ab 100644 --- a/packages/application/test/shell.spec.ts +++ b/packages/application/test/shell.spec.ts @@ -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'); + }); + }); });