Skip to content

Commit

Permalink
Polish the test
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Nov 5, 2023
1 parent 11209d6 commit 3b25fca
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions galata/test/jupyterlab/windowed-notebook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,57 @@ test.beforeEach(async ({ page, tmpPath }) => {
);
});

async function getWindowHeight(panel: ElementHandle<Element>) {
async function getInnerHeight(panel: ElementHandle<Element>) {
return parseInt(
(await panel?.$$eval(
await panel.$eval(
'.jp-WindowedPanel-inner',
nodes => nodes[0].style.height
)) ?? '0',
node => (node as HTMLElement).style.height
),
10
);
}
async function getWindowHeight(panel: ElementHandle<Element>) {
return parseInt(
await panel.$eval(
'.jp-WindowedPanel-window',
node => (node as HTMLElement).style.minHeight
),
10
);
}

test('should update window height on resize', async ({ page, tmpPath }) => {
await page.notebook.openByPath(`${tmpPath}/${fileName}`);
// Note: this needs many small cells so that they get added during resize changing height.
const notebookName = '20_empty_cells.ipynb';
await page.contents.uploadFile(
path.resolve(__dirname, `notebooks/${notebookName}`),
`${tmpPath}/${notebookName}`
);
await page.notebook.openByPath(`${tmpPath}/${notebookName}`);

// Wait to ensure the rendering logic is stable.
await page.waitForTimeout(200);
const notebook = await page.notebook.getNotebookInPanel();

// Measure height when only the notebook is open
const panel = await page.notebook.getNotebookInPanel();
const fullHeight = await getWindowHeight(panel);
// Measure height when the notebook is open but launcher closed
const fullHeight = await getWindowHeight(notebook);

// Add a new launcher below the notebook
await page.evaluate(async () => {
const widget = await window.jupyterapp.commands.execute('launcher:create');
window.jupyterapp.shell.add(widget, 'main', { mode: 'split-bottom' });
});
// Measure height after splitting the dock area
const heightAfterSplit = await getWindowHeight(panel);
const heightAfterSplit = await getWindowHeight(notebook);

expect(heightAfterSplit).toBeLessThan(fullHeight);

// Resize the dock panel, increasing the notebook height/decreasing the launcher height.
const resizeHandle = page.locator(
'.lm-DockPanel-handle[data-orientation="vertical"]'
'.lm-DockPanel-handle[data-orientation="vertical"]:visible'
);
resizeHandle.dragTo(page.locator('#jp-main-statusbar'));
await resizeHandle.dragTo(page.locator('#jp-main-statusbar'));

// Measure height after resizing
const heightAfterResize = await getWindowHeight(panel);
const heightAfterResize = await getWindowHeight(notebook);

expect(heightAfterResize).toBeGreaterThan(heightAfterSplit);
});
Expand All @@ -76,15 +89,15 @@ test('should not update height when hiding', async ({ page, tmpPath }) => {
// Wait to ensure the rendering logic is stable.
await page.waitForTimeout(200);

const panel = await page.notebook.getNotebookInPanel();
const initialHeight = await getWindowHeight(panel);
const notebook = await page.notebook.getNotebookInPanel();
const initialHeight = await getInnerHeight(notebook);

expect(initialHeight).toBeGreaterThan(0);

// Add a new launcher covering the notebook.
await page.menu.clickMenuItem('File>New Launcher');

const innerHeight = await getWindowHeight(panel);
const innerHeight = await getInnerHeight(notebook);

expect(innerHeight).toEqual(initialHeight);
});
Expand Down

0 comments on commit 3b25fca

Please sign in to comment.