Skip to content

Commit

Permalink
ui file
Browse files Browse the repository at this point in the history
  • Loading branch information
Nour-Cheour10 committed Jun 28, 2024
1 parent a15ce7b commit ac5a0ab
Showing 1 changed file with 115 additions and 144 deletions.
259 changes: 115 additions & 144 deletions ui-tests/tests/ipyopenlayers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,166 +5,137 @@ import { expect, IJupyterLabPageFixture, test } from '@jupyterlab/galata';
import * as path from 'path';
const klaw = require('klaw-sync');

async function waitForLayerRendering(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));

const filterUpdateNotebooks = item => {
const basename = path.basename(item.path);
return basename.includes('_update');
}

const filterUpdateNotebooks = (item) => {
const basename = path.basename(item.path);
return basename.includes('_update');
};
const testCellOutputs = async (page: IJupyterLabPageFixture, tmpPath: string, theme: 'JupyterLab Light' | 'JupyterLab Dark') => {
const paths = klaw(path.resolve(__dirname, './notebooks'), {filter: item => !filterUpdateNotebooks(item), nodir: true});
const notebooks = paths.map(item => path.basename(item.path));

const testCellOutputs = async (
page: IJupyterLabPageFixture,
tmpPath: string,
theme: 'JupyterLab Light' | 'JupyterLab Dark',
) => {
const paths = klaw(path.resolve(__dirname, './notebooks'), {
filter: (item) => !filterUpdateNotebooks(item),
nodir: true,
});
const notebooks = paths.map((item) => path.basename(item.path));
const contextPrefix = theme == 'JupyterLab Dark' ? 'light' : 'dark';
if (theme == 'JupyterLab Dark') {
page.theme.setTheme(theme);
}

const contextPrefix = theme == 'JupyterLab Dark' ? 'light' : 'dark';
if (theme == 'JupyterLab Dark') {
page.theme.setTheme(theme);
}
for (const notebook of notebooks) {
let results = [];

for (const notebook of notebooks) {
let results = [];

await page.notebook.openByPath(`${tmpPath}/${notebook}`);
await page.notebook.activate(notebook);

let numCellImages = 0;

const getCaptureImageName = (
contextPrefix: string,
notebook: string,
id: number,
): string => {
return `${contextPrefix}-${notebook}-cell-${id}.png`;
};

await page.notebook.runCellByCell({
onAfterCellRun: async (cellIndex: number) => {
const cell = await page.notebook.getCellOutput(cellIndex);
if (cell) {
results.push(await cell.screenshot());
numCellImages++;
}
},
});

await page.notebook.save();

for (let c = 0; c < numCellImages; ++c) {
expect(results[c]).toMatchSnapshot(
getCaptureImageName(contextPrefix, notebook, c),
{ threshold: 0.3 },
);
}
await page.notebook.openByPath(`${tmpPath}/${notebook}`);
await page.notebook.activate(notebook);

await page.notebook.close(true);
}
};
let numCellImages = 0;

const getCaptureImageName = (contextPrefix: string, notebook: string, id: number): string => {
return `${contextPrefix}-${notebook}-cell-${id}.png`;
};

const testPlotUpdates = async (
page: IJupyterLabPageFixture,
tmpPath: string,
theme: 'JupyterLab Light' | 'JupyterLab Dark',
) => {
const paths = klaw(path.resolve(__dirname, './notebooks'), {
filter: (item) => filterUpdateNotebooks(item),
nodir: true,
await page.notebook.runCellByCell({
onAfterCellRun: async (cellIndex: number) => {
const cell = await page.notebook.getCellOutput(cellIndex);
if (cell) {
const map = await cell.$("div.ol-container");

if (map) {
await new Promise((_) => setTimeout(_, 1000));
}
results.push(await cell.screenshot());
numCellImages++;
}
}
});
const notebooks = paths.map((item) => path.basename(item.path));

const contextPrefix = theme == 'JupyterLab Light' ? 'light' : 'dark';
if (theme == 'JupyterLab Dark') {
page.theme.setTheme(theme);
await page.notebook.save();

for (let c = 0; c < numCellImages; ++c) {
expect(results[c]).toMatchSnapshot(getCaptureImageName(contextPrefix, notebook, c), {threshold: 0.3});
}

for (const notebook of notebooks) {
let results = [];

await page.notebook.openByPath(`${tmpPath}/${notebook}`);
await page.notebook.activate(notebook);

const getCaptureImageName = (
contextPrefix: string,
notebook: string,
id: number,
): string => {
return `${contextPrefix}-${notebook}-cell-${id}.png`;
};

let cellCount = 0;
await page.notebook.runCellByCell({
onAfterCellRun: async (cellIndex: number) => {

const cell = await page.notebook.getCellOutput(0);
if (cell) {
results.push(await cell.screenshot());
cellCount++;
}
},
});

// Adding a delay to wait for layer rendering after actions
await waitForLayerRendering(2000); // Adjust time as needed (2 seconds here)

await page.notebook.save();

for (let i = 0; i < cellCount; i++) {
expect(results[i]).toMatchSnapshot(
getCaptureImageName(contextPrefix, notebook, i),
{ threshold: 0.3 },
);
await page.notebook.close(true);
}
}

const testPlotUpdates = async (page: IJupyterLabPageFixture, tmpPath: string, theme: 'JupyterLab Light' | 'JupyterLab Dark') => {
const paths = klaw(path.resolve(__dirname, './notebooks'), {filter: item => filterUpdateNotebooks(item), nodir: true});
const notebooks = paths.map(item => path.basename(item.path));

const contextPrefix = theme == 'JupyterLab Light' ? 'light' : 'dark';
if (theme == 'JupyterLab Dark') {
page.theme.setTheme(theme);
}

for (const notebook of notebooks) {
let results = [];

await page.notebook.openByPath(`${tmpPath}/${notebook}`);
await page.notebook.activate(notebook);

const getCaptureImageName = (contextPrefix: string, notebook: string, id: number): string => {
return `${contextPrefix}-${notebook}-cell-${id}.png`;
};

let cellCount = 0;
await page.notebook.runCellByCell({
onAfterCellRun: async (cellIndex: number) => {
// Always get first cell output which must contain the plot
const cell = await page.notebook.getCellOutput(0);
if (cell) {
results.push(await cell.screenshot());
cellCount++;
}
}
});

await page.notebook.save();

await page.notebook.close(true);
for (let i = 0; i < cellCount; i++) {
expect(results[i]).toMatchSnapshot(getCaptureImageName(contextPrefix, notebook, i), {threshold: 0.3});

Check failure on line 94 in ui-tests/tests/ipyopenlayers.test.ts

View workflow job for this annotation

GitHub Actions / visual-regression-tests

tests/ipyopenlayers.test.ts:128:7 › ipyopenlayers Visual Regression › Light theme: Check ipyopenlayers update plot properties

1) tests/ipyopenlayers.test.ts:128:7 › ipyopenlayers Visual Regression › Light theme: Check ipyopenlayers update plot properties Error: Screenshot comparison failed: 62 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts-snapshots/light-map-update-ipynb-cell-1-linux.png Received: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/test-results/tests-ipyopenlayers-ipyopenlayers-Visual-Regre-a3197-heme-Check-ipyopenlayers-update-plot-properties/light-map-update-ipynb-cell-1-actual.png Diff: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/test-results/tests-ipyopenlayers-ipyopenlayers-Visual-Regre-a3197-heme-Check-ipyopenlayers-update-plot-properties/light-map-update-ipynb-cell-1-diff.png 92 | 93 | for (let i = 0; i < cellCount; i++) { > 94 | expect(results[i]).toMatchSnapshot(getCaptureImageName(contextPrefix, notebook, i), {threshold: 0.3}); | ^ 95 | } 96 | 97 | await page.notebook.close(true); at testPlotUpdates (/home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts:94:26) at /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts:132:5

Check failure on line 94 in ui-tests/tests/ipyopenlayers.test.ts

View workflow job for this annotation

GitHub Actions / visual-regression-tests

tests/ipyopenlayers.test.ts:128:7 › ipyopenlayers Visual Regression › Light theme: Check ipyopenlayers update plot properties

1) tests/ipyopenlayers.test.ts:128:7 › ipyopenlayers Visual Regression › Light theme: Check ipyopenlayers update plot properties Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 62 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts-snapshots/light-map-update-ipynb-cell-1-linux.png Received: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/test-results/tests-ipyopenlayers-ipyopenlayers-Visual-Regre-a3197-heme-Check-ipyopenlayers-update-plot-properties-retry1/light-map-update-ipynb-cell-1-actual.png Diff: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/test-results/tests-ipyopenlayers-ipyopenlayers-Visual-Regre-a3197-heme-Check-ipyopenlayers-update-plot-properties-retry1/light-map-update-ipynb-cell-1-diff.png 92 | 93 | for (let i = 0; i < cellCount; i++) { > 94 | expect(results[i]).toMatchSnapshot(getCaptureImageName(contextPrefix, notebook, i), {threshold: 0.3}); | ^ 95 | } 96 | 97 | await page.notebook.close(true); at testPlotUpdates (/home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts:94:26) at /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts:132:5

Check failure on line 94 in ui-tests/tests/ipyopenlayers.test.ts

View workflow job for this annotation

GitHub Actions / visual-regression-tests

tests/ipyopenlayers.test.ts:128:7 › ipyopenlayers Visual Regression › Light theme: Check ipyopenlayers update plot properties

1) tests/ipyopenlayers.test.ts:128:7 › ipyopenlayers Visual Regression › Light theme: Check ipyopenlayers update plot properties Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 62 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts-snapshots/light-map-update-ipynb-cell-1-linux.png Received: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/test-results/tests-ipyopenlayers-ipyopenlayers-Visual-Regre-a3197-heme-Check-ipyopenlayers-update-plot-properties-retry2/light-map-update-ipynb-cell-1-actual.png Diff: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/test-results/tests-ipyopenlayers-ipyopenlayers-Visual-Regre-a3197-heme-Check-ipyopenlayers-update-plot-properties-retry2/light-map-update-ipynb-cell-1-diff.png 92 | 93 | for (let i = 0; i < cellCount; i++) { > 94 | expect(results[i]).toMatchSnapshot(getCaptureImageName(contextPrefix, notebook, i), {threshold: 0.3}); | ^ 95 | } 96 | 97 | await page.notebook.close(true); at testPlotUpdates (/home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts:94:26) at /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts:132:5

Check failure on line 94 in ui-tests/tests/ipyopenlayers.test.ts

View workflow job for this annotation

GitHub Actions / visual-regression-tests

tests/ipyopenlayers.test.ts:128:7 › ipyopenlayers Visual Regression › Light theme: Check ipyopenlayers update plot properties

1) tests/ipyopenlayers.test.ts:128:7 › ipyopenlayers Visual Regression › Light theme: Check ipyopenlayers update plot properties Retry #3 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 62 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts-snapshots/light-map-update-ipynb-cell-1-linux.png Received: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/test-results/tests-ipyopenlayers-ipyopenlayers-Visual-Regre-a3197-heme-Check-ipyopenlayers-update-plot-properties-retry3/light-map-update-ipynb-cell-1-actual.png Diff: /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/test-results/tests-ipyopenlayers-ipyopenlayers-Visual-Regre-a3197-heme-Check-ipyopenlayers-update-plot-properties-retry3/light-map-update-ipynb-cell-1-diff.png 92 | 93 | for (let i = 0; i < cellCount; i++) { > 94 | expect(results[i]).toMatchSnapshot(getCaptureImageName(contextPrefix, notebook, i), {threshold: 0.3}); | ^ 95 | } 96 | 97 | await page.notebook.close(true); at testPlotUpdates (/home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts:94:26) at /home/runner/work/ipyopenlayers/ipyopenlayers/ui-tests/tests/ipyopenlayers.test.ts:132:5
}

await page.notebook.close(true);
}
};

test.describe('ipyopenlayers Visual Regression', () => {
test.beforeEach(async ({ page, tmpPath }) => {
page.on('console', (message) => {
console.log('CONSOLE MSG ---', message.text());
});

await page.contents.uploadDirectory(
path.resolve(__dirname, './notebooks'),
tmpPath,
);
await page.filebrowser.openDirectory(tmpPath);
});

test('Light theme: Check ipyopenlayers first renders', async ({
page,
tmpPath,
}) => {
await testCellOutputs(page, tmpPath, 'JupyterLab Light');
});

// test('Dark theme: Check ipyopenlayers first renders', async ({
// page,
// tmpPath,
// }) => {
// await testCellOutputs(page, tmpPath, 'JupyterLab Dark');
// });

test('Light theme: Check ipyopenlayers update plot properties', async ({
page,
tmpPath,
}) => {
await testPlotUpdates(page, tmpPath, 'JupyterLab Light');
test.beforeEach(async ({ page, tmpPath }) => {
page.on("console", (message) => {
console.log('CONSOLE MSG ---', message.text());
});

// test('Dark theme: Check ipyopenlayers update plot properties', async ({
// page,
// tmpPath,
// }) => {
// await testPlotUpdates(page, tmpPath, 'JupyterLab Dark');
// });
});
await page.contents.uploadDirectory(
path.resolve(__dirname, './notebooks'),
tmpPath
);
await page.filebrowser.openDirectory(tmpPath);
});

test('Light theme: Check ipyopenlayers first renders', async ({
page,
tmpPath,
}) => {
await testCellOutputs(page, tmpPath, 'JupyterLab Light');
});

// test('Dark theme: Check ipyopenlayers first renders', async ({
// page,
// tmpPath,
// }) => {
// await testCellOutputs(page, tmpPath, 'JupyterLab Dark');
// });

test('Light theme: Check ipyopenlayers update plot properties', async ({
page,
tmpPath,
}) => {
await testPlotUpdates(page, tmpPath, 'JupyterLab Light');
});

// test('Dark theme: Check ipyopenlayers update plot properties', async ({
// page,
// tmpPath,
// }) => {
// await testPlotUpdates(page, tmpPath, 'JupyterLab Dark');
// });
});

0 comments on commit ac5a0ab

Please sign in to comment.