From 8c77d41d117583a42cde8eb9842af83b213a28b0 Mon Sep 17 00:00:00 2001 From: Frederic COLLONVAL Date: Wed, 1 Nov 2023 17:13:20 +0100 Subject: [PATCH] Add integration test --- src/index.ts | 40 +++++++++++-------- .../lckr_jupyterlab_variableinspector.spec.ts | 28 ++++++------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/index.ts b/src/index.ts index 30b5560..558a732 100644 --- a/src/index.ts +++ b/src/index.ts @@ -184,15 +184,12 @@ const consoles: JupyterFrontEndPlugin = { }); }); } + + setSource(labShell); }); - /** - * If focus window changes, checks whether new focus widget is a console. - * In that case, retrieves the handler associated to the console after it has been - * initialized and updates the manager with it. - */ - labShell.currentChanged.connect((sender, args) => { - const widget = args.newValue; + const setSource = (sender: ILabShell, args?: ILabShell.IChangedArgs) => { + const widget = args?.newValue ?? sender.currentWidget; if (!widget || !consoles.has(widget)) { return; } @@ -203,7 +200,14 @@ const consoles: JupyterFrontEndPlugin = { manager.source.performInspection(); } }); - }); + }; + /** + * If focus window changes, checks whether new focus widget is a console. + * In that case, retrieves the handler associated to the console after it has been + * initialized and updates the manager with it. + */ + setSource(labShell); + labShell.currentChanged.connect(setSource); app.contextMenu.addItem({ command: CommandIDs.open, @@ -279,15 +283,12 @@ const notebooks: JupyterFrontEndPlugin = { reject(result); }); }); + + setSource(labShell); }); - /** - * If focus window changes, checks whether new focus widget is a notebook. - * In that case, retrieves the handler associated to the notebook after it has been - * initialized and updates the manager with it. - */ - labShell.currentChanged.connect((sender, args) => { - const widget = args.newValue; + const setSource = (sender: ILabShell, args?: ILabShell.IChangedArgs) => { + const widget = args?.newValue ?? sender.currentWidget; if (!widget || !notebooks.has(widget) || widget.isDisposed) { return; } @@ -298,7 +299,14 @@ const notebooks: JupyterFrontEndPlugin = { manager.source.performInspection(); } }); - }); + }; + /** + * If focus window changes, checks whether new focus widget is a notebook. + * In that case, retrieves the handler associated to the notebook after it has been + * initialized and updates the manager with it. + */ + setSource(labShell); + labShell.currentChanged.connect(setSource); app.contextMenu.addItem({ command: CommandIDs.open, diff --git a/ui-tests/tests/lckr_jupyterlab_variableinspector.spec.ts b/ui-tests/tests/lckr_jupyterlab_variableinspector.spec.ts index 6b27dd6..159d163 100644 --- a/ui-tests/tests/lckr_jupyterlab_variableinspector.spec.ts +++ b/ui-tests/tests/lckr_jupyterlab_variableinspector.spec.ts @@ -1,21 +1,19 @@ import { expect, test } from '@jupyterlab/galata'; -/** - * Don't load JupyterLab webpage before running the tests. - * This is required to ensure we capture all log messages. - */ -test.use({ autoGoto: false }); -test('should emit an activation console message', async ({ page }) => { - const logs: string[] = []; +test('test', async ({ page }) => { + await page.getByText('Python 3 (ipykernel)').first().click(); + await page.getByText('Python 3 (ipykernel) | Idle').waitFor(); + await page.getByLabel('notebook content').getByRole('textbox').fill('a = 1'); + await page.keyboard.press('Shift+Enter'); + await page.getByRole('textbox').nth(2).fill('b = "hello"'); + await page.keyboard.press('Control+Enter'); - page.on('console', message => { - logs.push(message.text()); + await page.getByRole('tabpanel').click({ + button: 'right' }); + await page.getByRole('menu').getByText('Open Variable Inspector').click(); - await page.goto(); - - expect( - logs.filter(s => s === 'JupyterLab extension @lckr/jupyterlab_variableinspector is activated!') - ).toHaveLength(1); -}); + await expect(page.getByRole('row').nth(1)).toHaveText(/aint281$/) + await expect(page.getByRole('row').last()).toHaveText(/bstr46hello$/) +}); \ No newline at end of file