Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed May 10, 2024
1 parent 85e1ad6 commit 50db0da
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,6 @@ dmypy.json
# Yarn cache
.yarn/
.jupyter_ystore.db

**/ui-tests/test-results/
**/ui-tests/playwright-report/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@
"node_modules",
"dist",
"coverage",
"**/*.d.ts"
"**/*.d.ts",
"ui-tests"
],
"eslintConfig": {
"extends": [
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
tracker.add(widget);
app.shell.activateById('jupytercad::leftControlPanel');
});
console.log('jupytercad_openvsp:plugin is activated!');
}
};

Expand Down
4 changes: 4 additions & 0 deletions ui-tests/jupyter_server_test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from jupyterlab.galata import configure_jupyter_server

configure_jupyter_server(c) # noqa F821
c.LabApp.collaborative = True # noqa F821
81 changes: 81 additions & 0 deletions ui-tests/tests/ui.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { expect, test, galata } from '@jupyterlab/galata';

Check failure on line 1 in ui-tests/tests/ui.spec.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/ui.spec.ts:52:11 › UI Test › File rendering test › Should be able to render A320.vsp3 without error

1) tests/ui.spec.ts:52:11 › UI Test › File rendering test › Should be able to render A320.vsp3 without error Test timeout of 60000ms exceeded.

Check failure on line 1 in ui-tests/tests/ui.spec.ts

View workflow job for this annotation

GitHub Actions / Integration tests

tests/ui.spec.ts:52:11 › UI Test › File rendering test › Should be able to render A320.vsp3 without error

1) tests/ui.spec.ts:52:11 › UI Test › File rendering test › Should be able to render A320.vsp3 without error Error: locator.count: Target page, context or browser has been closed at /home/runner/work/jupytercad-openvsp/jupytercad-openvsp/ui-tests/node_modules/@jupyterlab/galata/src/helpers/filebrowser.ts:236:58 at Timeout.check (/home/runner/work/jupytercad-openvsp/jupytercad-openvsp/ui-tests/node_modules/@jupyterlab/galata/src/utils.ts:183:33)
import path from 'path';

test.use({ autoGoto: false });

test.describe('UI Test', () => {
const fileList = ['A320.vsp3'];

test.describe('Extension activation test', () => {
test('should emit an activation console message', async ({
page,
request
}) => {
const logs: string[] = [];

page.on('console', message => {
logs.push(message.text());
});

await page.goto();

expect(
logs.filter(s => s === 'jupytercad_openvsp:plugin is activated!')
).toHaveLength(1);
});
});

test.describe('File rendering test', () => {
test.beforeAll(async ({ request }) => {
const content = galata.newContentsHelper(request);
await content.deleteDirectory('/examples');
await content.uploadDirectory(
path.resolve(__dirname, '../../examples'),
'/examples'
);
});
let errors = 0;
test.beforeEach(async ({ page }) => {
page.setViewportSize({ width: 1920, height: 1080 });
page.on('console', message => {
if (message.type() === 'error') {
errors += 1;
}
});
});

test.afterEach(async ({ page }) => {
errors = 0;
});

for (const file of fileList) {
test(`Should be able to render ${file} without error`, async ({
page
}) => {
await page.goto();
const fullPath = `examples/${file}`;
await page.notebook.openByPath(fullPath);
await page.notebook.activate(fullPath);
await page.locator('div.jpcad-Spinner').waitFor({ state: 'hidden' });

await page
.getByRole('tablist', { name: 'main sidebar' })
.getByRole('tab', { name: 'JupyterCad Control Panel' })
.click();
await page
.getByRole('tablist', { name: 'alternate sidebar' })
.getByRole('tab', { name: 'JupyterCad Control Panel' })
.click();
await page.waitForTimeout(1000);
const main = await page.$('#jp-main-split-panel');
expect(errors).toBe(0);
if (main) {
expect(await main.screenshot()).toMatchSnapshot({
name: `Render-${file}.png`,
maxDiffPixelRatio: 0.01
});
}
});
}
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 50db0da

Please sign in to comment.