diff --git a/js/ui-tests/examples.spec.js b/js/ui-tests/examples.spec.js index 3e088427..d00182e4 100644 --- a/js/ui-tests/examples.spec.js +++ b/js/ui-tests/examples.spec.js @@ -5,11 +5,9 @@ import { expect, test, galata } from "@jupyterlab/galata"; import * as path from "path"; -// request and tmpPath are Playwright fixtures -test("01_Getting_Started", async ({ page, request, tmpPath }) => { - // Import notebook 1 +async function openNotebook(page, request, tmpPath, notebookName) { const content = galata.newContentsHelper(request); - const filename = "01_Getting_Started.ipynb"; + const filename = notebookName; await content.uploadFile( path.resolve(__dirname, `../../examples/${filename}`), `${tmpPath}/${filename}`, @@ -21,48 +19,95 @@ test("01_Getting_Started", async ({ page, request, tmpPath }) => { await page.waitForSelector( "#jp-main-statusbar >> text=Python 3 (ipykernel) | Idle", ); + await page + .getByRole("button", { name: "Toggle virtual scrollbar (" }) + .click(); +} + +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}`, + ); +} + +async function gotoCell(page, cellNumber) { + // await page.getByLabel('notebook content').getByText(`${cellNumber}`, {exact: true}).click(); + // await page.getElementsByClassName("jp-WindowedPanel-scrollbar-item").item(cellNumber).click(); + const elements = await page.$$(".jp-WindowedPanel-scrollbar-item"); + if (elements.length > cellNumber) { + await elements[cellNumber].click(); + } else { + console.log(`L'index ${cellNumber} est hors des limites.`); + } +} + +async function matchAladinCell(aladinCell) { + expect(await aladinCell.screenshot()).toMatchSnapshot(); +} + +test("01_Getting_Started", async ({ page, request, tmpPath }) => { + // Import notebook 1 + await openNotebook(page, request, tmpPath, "01_Getting_Started.ipynb"); // Execute all cells - await page.notebook.runCell(1); - await page.notebook.runCell(2); - await page.notebook.addCell("code", ""); - await page.notebook.runCell(3); + await page.notebook.runCellByCell(); // Wait for Aladin to pop - await page.waitForTimeout(3000); // 3s + await page.waitForTimeout(3000); // Scroll to the top of the notebook - await page.getByLabel("Cells").getByRole("textbox").nth(4).press("ArrowUp"); - await page.getByLabel("Cells").getByRole("textbox").nth(3).press("ArrowUp"); - // Save - await page.notebook.save(); + const aladinCell = await page.locator("canvas").nth(1); + + await gotoCell(page, 1); // And check snapshot (maybe we should clip to div jp-main-dock-panel) - expect(await page.screenshot()).toMatchSnapshot(); + await matchAladinCell(aladinCell); }); -test("11_Extracting_information_from_the_view", async ({ - page, - request, - tmpPath, -}) => { - // Import notebook 4 - const content = galata.newContentsHelper(request); - const filename = "11_Extracting_information_from_the_view.ipynb"; - await content.uploadFile( - path.resolve(__dirname, `../../examples/${filename}`), - `${tmpPath}/${filename}`, - ); - // Activate notebook - await page.notebook.openByPath(`${tmpPath}/${filename}`); - await page.notebook.activate(filename); - // Wait until kernel is ready - await page.waitForSelector( - "#jp-main-statusbar >> text=Python 3 (ipykernel) | Idle", +test("02_Base_Commands", async ({ page, request, tmpPath }) => { + await uploadFitsFile( + page, + request, + tmpPath + "/images/", + "../../examples/images/m31.fits", ); + await openNotebook(page, request, tmpPath, "02_Base_Commands.ipynb"); - let wcsCellIdx = 4; + const aladinCell = await page.locator("canvas").nth(1); - for (let i = 0; i <= wcsCellIdx; i++) await page.notebook.runCell(i); - await page.waitForTimeout(3000); + 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(); + await gotoCell(page, 5); + await matchAladinCell(aladinCell); + + for (let i = 18; i < 21; i++) await page.notebook.runCell(i); + + // Check second snapshot + // await aladinCell.press("ArrowUp"); + await gotoCell(page, 5); + await matchAladinCell(aladinCell); + + // add_fits check + await page.notebook.runCell(22); - let wcsCell = await page.notebook.getCellTextOutput(wcsCellIdx); - expect(wcsCell[0]).toContain("CTYPE : 'RA---SIN'"); - expect(wcsCell[0]).toContain("NAXIS : 592 600"); + // Check third snapshot + // await aladinCell.press("ArrowUp"); + await gotoCell(page, 5); + await matchAladinCell(aladinCell); }); diff --git a/js/ui-tests/examples.spec.js-snapshots/01-Getting-Started-1-linux.png b/js/ui-tests/examples.spec.js-snapshots/01-Getting-Started-1-linux.png index a4f42ac3..52b08c8c 100644 Binary files a/js/ui-tests/examples.spec.js-snapshots/01-Getting-Started-1-linux.png and b/js/ui-tests/examples.spec.js-snapshots/01-Getting-Started-1-linux.png differ diff --git a/js/ui-tests/examples.spec.js-snapshots/02-Base-Commands-1-linux.png b/js/ui-tests/examples.spec.js-snapshots/02-Base-Commands-1-linux.png new file mode 100644 index 00000000..6e61bfc3 Binary files /dev/null and b/js/ui-tests/examples.spec.js-snapshots/02-Base-Commands-1-linux.png differ diff --git a/js/ui-tests/examples.spec.js-snapshots/02-Base-Commands-2-linux.png b/js/ui-tests/examples.spec.js-snapshots/02-Base-Commands-2-linux.png new file mode 100644 index 00000000..66884c7a Binary files /dev/null and b/js/ui-tests/examples.spec.js-snapshots/02-Base-Commands-2-linux.png differ diff --git a/js/ui-tests/examples.spec.js-snapshots/02-Base-Commands-3-linux.png b/js/ui-tests/examples.spec.js-snapshots/02-Base-Commands-3-linux.png new file mode 100644 index 00000000..4073463a Binary files /dev/null and b/js/ui-tests/examples.spec.js-snapshots/02-Base-Commands-3-linux.png differ