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

tests: add more ui tests #101

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 83 additions & 38 deletions js/ui-tests/examples.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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(
// "<SkyCoord (ICRS): (ra, dec) in deg\n" +
// " (266.41681663, -29.00782497)>",
// );

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);
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading