diff --git a/js/ui-tests/examples.spec.js b/js/ui-tests/examples.spec.js index 3df82f2d..0a2a6c23 100644 --- a/js/ui-tests/examples.spec.js +++ b/js/ui-tests/examples.spec.js @@ -6,11 +6,9 @@ import { expect, test, galata } from "@jupyterlab/galata"; import { setTimeout } from "timers/promises"; import * as path from "path"; -// request and tmpPath are Playwright fixtures -test("1-Getting-Started", async ({ page, request, tmpPath }) => { - // Import notebook 1 +async function openNotebook(page, request, tmpPath, notebookName) { const content = galata.newContentsHelper(request); - const filename = "1_Getting_Started.ipynb"; + const filename = notebookName; await content.uploadFile( path.resolve(__dirname, `../../examples/${filename}`), `${tmpPath}/${filename}`, @@ -22,15 +20,75 @@ test("1-Getting-Started", async ({ page, request, tmpPath }) => { await page.waitForSelector( "#jp-main-statusbar >> text=Python 3 (ipykernel) | Idle", ); +} + +async function uploadFitsFile(page, request, tmpPath, filePath) { + const content = galata.newContentsHelper(request); + const fitsFileName = path.basename(filePath); + await content.uploadFile( + path.resolve(__dirname, filePath), + `${tmpPath}/${fitsFileName}`, + ); +} + +// request and tmpPath are Playwright fixtures +test("1_Getting_Started", async ({ page, request, tmpPath }) => { + // Import notebook 1 + await openNotebook(page, request, tmpPath, "1_Getting_Started.ipynb"); // Execute all cells await page.notebook.runCellByCell(); // Wait for Aladin to pop await setTimeout(3000); // 3s // Scroll to the top of the notebook - page.notebook.getCellLocator(2); - page.mouse.wheel(0, -2000); + const aladinCell = await page.locator("canvas").nth(1); // Save await page.notebook.save(); // And check snapshot (maybe we should clip to div jp-main-dock-panel) - expect(await page.screenshot()).toMatchSnapshot(); + expect(await aladinCell.screenshot()).toMatchSnapshot(); +}); + +test("2_Base_Commands", async ({ page, request, tmpPath }) => { + await uploadFitsFile( + page, + request, + tmpPath + "/images/", + "../../examples/images/m31.fits", + ); + await openNotebook(page, request, tmpPath, "2_Base_Commands.ipynb"); + + const aladinCell = await page.locator("canvas").nth(1); + + for (let i = 1; i < 7; i++) await page.notebook.runCell(i); + await page.waitForTimeout(1000); // 1s + for (let i = 7; i < 17; i++) await page.notebook.runCell(i); + + const targetLocator = await page.notebook.getCellLocator(8); + // expect(await targetLocator.textContent()).toContain( + // "", + // ); + + const fovLocator = await page.notebook.getCellLocator(11); + expect(await fovLocator.textContent()).toContain("2∘00′00′′"); + + const cooFrameLocator = await page.notebook.getCellLocator(16); + expect(await cooFrameLocator.textContent()).toContain("'ICRSd'"); + + // Check first snapshot + // await aladinCell.press("ArrowUp"); + // await page.notebook.save(); + expect(await aladinCell.screenshot({ timeout: 10000 })).toMatchSnapshot(); + + for (let i = 18; i < 21; i++) await page.notebook.runCell(i); + + // Check second snapshot + // await aladinCell.press("ArrowUp"); + expect(await aladinCell.screenshot({ timeout: 10000 })).toMatchSnapshot(); + + // add_fits check + await page.notebook.runCell(22); + + // Check third snapshot + // await aladinCell.press("ArrowUp"); + expect(await aladinCell.screenshot({ timeout: 10000 })).toMatchSnapshot(); }); diff --git a/js/ui-tests/examples.spec.js-snapshots/1-Getting-Started-1-linux.png b/js/ui-tests/examples.spec.js-snapshots/1-Getting-Started-1-linux.png index e654b182..21ebf38a 100644 Binary files a/js/ui-tests/examples.spec.js-snapshots/1-Getting-Started-1-linux.png and b/js/ui-tests/examples.spec.js-snapshots/1-Getting-Started-1-linux.png differ diff --git a/js/ui-tests/examples.spec.js-snapshots/2-Base-Commands-1-linux.png b/js/ui-tests/examples.spec.js-snapshots/2-Base-Commands-1-linux.png new file mode 100644 index 00000000..cbea8add Binary files /dev/null and b/js/ui-tests/examples.spec.js-snapshots/2-Base-Commands-1-linux.png differ diff --git a/js/ui-tests/examples.spec.js-snapshots/2-Base-Commands-2-linux.png b/js/ui-tests/examples.spec.js-snapshots/2-Base-Commands-2-linux.png new file mode 100644 index 00000000..76bb1a08 Binary files /dev/null and b/js/ui-tests/examples.spec.js-snapshots/2-Base-Commands-2-linux.png differ diff --git a/js/ui-tests/examples.spec.js-snapshots/2-Base-Commands-3-linux.png b/js/ui-tests/examples.spec.js-snapshots/2-Base-Commands-3-linux.png new file mode 100644 index 00000000..990d5530 Binary files /dev/null and b/js/ui-tests/examples.spec.js-snapshots/2-Base-Commands-3-linux.png differ diff --git a/playwright.config.js b/playwright.config.js index 1db38573..770d3f66 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -6,6 +6,8 @@ const baseConfig = require("@jupyterlab/galata/lib/playwright-config"); module.exports = { ...baseConfig, testDir: "./js/ui-tests", + fullyParallel: true, + workers: 6, webServer: { command: "npm run start-test-server", url: "http://localhost:8888/lab",