Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix visual tests, allow to disable termianal cursor blinking #15524

Merged
merged 15 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ header:
- 'dev_mode/style.js'
- 'examples/federated/example.cert'
- 'galata/test/jupyterlab/notebooks/'
- 'galata/test/*/*-snapshots/*.txt'
- 'galata/test/*/*/*.txt'
- 'jupyterlab.desktop'
- 'jupyterlab/staging'
- 'packages/codemirror/test/foo.grammar'
Expand Down
3 changes: 3 additions & 0 deletions galata/src/galata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export namespace galata {
defaultConfig: {
cursorBlinkRate: 0
}
},
'@jupyterlab/terminal-extension:plugin': {
cursorBlink: false
}
};

Expand Down
18 changes: 17 additions & 1 deletion galata/src/helpers/performance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { Page } from '@playwright/test';
import { CDPSession, Page } from '@playwright/test';
import { UUID } from '@lumino/coreutils';

/**
Expand Down Expand Up @@ -40,6 +40,22 @@ export class PerformanceHelper {
return time;
}

/**
* Throttle network
*/
async throttleNetwork(config: {
downloadThroughput: number;
uploadThroughput: number;
latency: number;
}): Promise<CDPSession> {
const cdpSession = await this.page.context().newCDPSession(this.page);
await cdpSession.send('Network.emulateNetworkConditions', {
offline: false,
...config
});
return cdpSession;
krassowski marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Measure the time to execute a function using web browser performance API.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1999,9 +1999,7 @@
"id": "notebook:toggle-all-cell-line-numbers",
"label": "Show Line Numbers",
"caption": "",
"shortcuts": [
"Shift L"
]
"shortcuts": []
},
{
"id": "notebook:toggle-autoclosing-brackets",
Expand Down
3 changes: 3 additions & 0 deletions galata/test/documentation/customization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ test.use({
viewport: { height: 720, width: 1280 }
});

// Use serial mode to avoid flaky screenshots
test.describe.configure({ mode: 'serial' });

test.describe('Default', () => {
test('should use default layout', async ({ page }) => {
await galata.Mock.freezeContentLastModified(page);
Expand Down
37 changes: 37 additions & 0 deletions galata/test/documentation/data/tree_fixture.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
$ tree . -L 2
.
├── LICENSE
├── README.md
├── data
│   ├── 1024px-Hubble_Interacting_Galaxy_AM_0500-620_(2008-04-24).jpg
│   ├── Dockerfile
│   ├── Museums_in_DC.geojson
│   ├── README.md
│   ├── bar.vl.json
│   ├── iris.csv
│   ├── japan_meterological_agency_201707211555.json
│   └── zika_assembled_genomes.fasta
├── jupyter_notebook_config.py
├── narrative
│   ├── QConAI.md
│   ├── jupyterlab.md
│   ├── markdown_python.md
│   └── scipy2017.md
├── notebooks
│   ├── Cpp.ipynb
│   ├── Data.ipynb
│   ├── Fasta.ipynb
│   ├── Julia.ipynb
│   ├── Lorenz.ipynb
│   ├── R.ipynb
│   ├── audio
│   ├── images
│   └── lorenz.py
├── slides
│   ├── jupyterlab-slides.key
│   ├── jupyterlab-slides.pdf
│   └── jupyterlab-slides_scipy19.pdf
├── talks.yml
└── tasks.py

6 directories, 27 files
110 changes: 11 additions & 99 deletions galata/test/documentation/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Distributed under the terms of the Modified BSD License.

import { expect, galata, test } from '@jupyterlab/galata';
import path from 'path';
import {
generateArrow,
positionMouse,
Expand Down Expand Up @@ -79,13 +80,6 @@ test.describe('General', () => {
expect(await page.screenshot()).toMatchSnapshot('jupyterlab.png');
});

test('Overview', async ({ page }) => {
await galata.Mock.freezeContentLastModified(page);
await openOverview(page);

expect(await page.screenshot()).toMatchSnapshot('interface_jupyterlab.png');
});

test('Left Sidebar', async ({ page }) => {
await galata.Mock.freezeContentLastModified(page);
await page.goto();
Expand All @@ -98,6 +92,8 @@ test.describe('General', () => {
await setSidebarWidth(page);

await page.dblclick('[aria-label="File Browser Section"] >> text=data');
// Wait for the `data` folder to load to have something to blur
await page.waitForSelector('text=1024px');

await page.evaluate(() => {
(document.activeElement as HTMLElement).blur();
Expand Down Expand Up @@ -228,32 +224,6 @@ test.describe('General', () => {
);
});

test('Open tabs', async ({ page }) => {
await openOverview(page);

await page.click('[title="Running Terminals and Kernels"]');

await page
.locator(
'.jp-RunningSessions-item.jp-mod-kernel >> text="Python 3 (ipykernel)"'
)
.waitFor();
expect(
await page.screenshot({ clip: { y: 27, x: 0, width: 283, height: 400 } })
).toMatchSnapshot('interface_tabs.png');
});

test('Tabs menu', async ({ page }) => {
await galata.Mock.freezeContentLastModified(page);
await openOverview(page);

await page.click('text="Tabs"');

expect(
await page.screenshot({ clip: { y: 0, x: 210, width: 700, height: 350 } })
).toMatchSnapshot('interface_tabs_menu.png');
});

test('File menu', async ({ page }) => {
await page.goto();
await page.addStyleTag({
Expand Down Expand Up @@ -532,8 +502,13 @@ test.describe('General', () => {
);
});

test('Terminals', async ({ page }) => {
test('Terminal layout', async ({ page, tmpPath }) => {
await galata.Mock.freezeContentLastModified(page);
const fileName = 'tree_fixture.txt';
await page.contents.uploadFile(
path.resolve(__dirname, `./data/${fileName}`),
`${tmpPath}/${fileName}`
);
await page.goto();
await page.addStyleTag({
content: `.jp-LabShell.jp-mod-devMode {
Expand All @@ -559,7 +534,7 @@ test.describe('General', () => {

await page.keyboard.type('cd $JUPYTERLAB_GALATA_ROOT_DIR');
await page.keyboard.press('Enter');
await page.keyboard.type('tree . -L 2');
await page.keyboard.type(`clear && cat ${tmpPath}/${fileName}`);
await page.keyboard.press('Enter');

// Wait for command answer
Expand Down Expand Up @@ -634,6 +609,7 @@ test.describe('General', () => {

await setSidebarWidth(page);

await page.dblclick('[aria-label="File Browser Section"] >> text=data');
await page.click('text=README.md', {
button: 'right'
});
Expand Down Expand Up @@ -710,67 +686,3 @@ test.describe('General', () => {
});
});
});

async function openOverview(page) {
await page.goto();
await page.addStyleTag({
content: `.jp-LabShell.jp-mod-devMode {
border-top: none;
}`
});

await setSidebarWidth(page);

// Open Data.ipynb
await page.dblclick('[aria-label="File Browser Section"] >> text=notebooks');
await page.dblclick('text=Data.ipynb');

// Back home
await page.click('.jp-BreadCrumbs-home svg');

// Open jupyterlab.md
await page.dblclick('[aria-label="File Browser Section"] >> text=narrative');
await page.click('text=jupyterlab.md', {
button: 'right'
});
await page.click('text=Open With');
await page.click('text=Markdown Preview');

// Back home
await page.click('.jp-BreadCrumbs-home svg');

// Open bar.vl.json
await page.dblclick('[aria-label="File Browser Section"] >> text=data');
await page.dblclick('text=bar.vl.json');
await page.dblclick(
'text=1024px-Hubble_Interacting_Galaxy_AM_0500-620_(2008-04-24).jpg'
);

// Move notebook panel
const notebookHandle = await page.$('div[role="main"] >> text=Data.ipynb');
await notebookHandle.click();
const notebookBBox = await notebookHandle.boundingBox();

await page.mouse.move(
notebookBBox.x + 0.5 * notebookBBox.width,
notebookBBox.y + 0.5 * notebookBBox.height
);
await page.mouse.down();
await page.mouse.move(notebookBBox.x + 0.5 * notebookBBox.width, 350);
await page.mouse.up();

// Move md panel
const mdHandle = await page.$('div[role="main"] >> text=jupyterlab.md');
await mdHandle.click();
const mdBBox = await mdHandle.boundingBox();
const panelHandle = await page.activity.getPanel();
const panelBBox = await panelHandle.boundingBox();

await page.mouse.move(
mdBBox.x + 0.5 * mdBBox.width,
mdBBox.y + 0.5 * mdBBox.height
);
await page.mouse.down();
await page.mouse.move(panelBBox.x + 0.5 * panelBBox.width, 200);
await page.mouse.up();
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions galata/test/documentation/internationalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ test.describe('Internationalization', () => {
await galata.Mock.freezeContentLastModified(page);
await page.goto();

await page.dblclick('[aria-label="File Browser Section"] >> text=data');

await page.click('text=Settings');
await page.click('.lm-Menu ul[role="menu"] >> text=Language');
await page.click('#jp-mainmenu-settings-language >> text=Chinese');
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 113 additions & 0 deletions galata/test/documentation/overview.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { expect, galata, test } from '@jupyterlab/galata';
import { setSidebarWidth } from './utils';

test.use({
autoGoto: false,
mockState: galata.DEFAULT_DOCUMENTATION_STATE,
viewport: { height: 720, width: 1280 }
});

// Use serial mode to avoid flaky screenshots
test.describe.configure({ mode: 'serial' });

test.describe('Overview', () => {
test('Overview', async ({ page }) => {
await galata.Mock.freezeContentLastModified(page);
await openOverview(page);

expect(await page.screenshot()).toMatchSnapshot('interface_jupyterlab.png');
});

test('Open tabs', async ({ page }) => {
await openOverview(page);

await page.click('[title="Running Terminals and Kernels"]');

await page
.locator(
'.jp-RunningSessions-item.jp-mod-kernel >> text="Python 3 (ipykernel)"'
)
.waitFor();
expect(
await page.screenshot({ clip: { y: 27, x: 0, width: 283, height: 400 } })
).toMatchSnapshot('interface_tabs.png');
});

test('Tabs menu', async ({ page }) => {
await galata.Mock.freezeContentLastModified(page);
await openOverview(page);

await page.click('text="Tabs"');

expect(
await page.screenshot({ clip: { y: 0, x: 210, width: 700, height: 350 } })
).toMatchSnapshot('interface_tabs_menu.png');
});
});

async function openOverview(page) {
await page.goto();
await page.addStyleTag({
content: `.jp-LabShell.jp-mod-devMode {
border-top: none;
}`
});

await setSidebarWidth(page);

// Open Data.ipynb
await page.dblclick('[aria-label="File Browser Section"] >> text=notebooks');
await page.dblclick('text=Data.ipynb');

// Back home
await page.click('.jp-BreadCrumbs-home svg');

// Open jupyterlab.md
await page.dblclick('[aria-label="File Browser Section"] >> text=narrative');
await page.click('text=jupyterlab.md', {
button: 'right'
});
await page.click('text=Open With');
await page.click('text=Markdown Preview');

// Back home
await page.click('.jp-BreadCrumbs-home svg');

// Open bar.vl.json
await page.dblclick('[aria-label="File Browser Section"] >> text=data');
await page.dblclick('text=bar.vl.json');
await page.dblclick(
'text=1024px-Hubble_Interacting_Galaxy_AM_0500-620_(2008-04-24).jpg'
);

// Move notebook panel
const notebookHandle = await page.$('div[role="main"] >> text=Data.ipynb');
await notebookHandle.click();
const notebookBBox = await notebookHandle.boundingBox();

await page.mouse.move(
notebookBBox.x + 0.5 * notebookBBox.width,
notebookBBox.y + 0.5 * notebookBBox.height
);
await page.mouse.down();
await page.mouse.move(notebookBBox.x + 0.5 * notebookBBox.width, 350);
await page.mouse.up();

// Move md panel
const mdHandle = await page.$('div[role="main"] >> text=jupyterlab.md');
await mdHandle.click();
const mdBBox = await mdHandle.boundingBox();
const panelHandle = await page.activity.getPanel();
const panelBBox = await panelHandle.boundingBox();

await page.mouse.move(
mdBBox.x + 0.5 * mdBBox.width,
mdBBox.y + 0.5 * mdBBox.height
);
await page.mouse.down();
await page.mouse.move(panelBBox.x + 0.5 * panelBBox.width, 200);
await page.mouse.up();
}