diff --git a/.gitignore b/.gitignore index 6dac8f6..07a5533 100644 --- a/.gitignore +++ b/.gitignore @@ -120,3 +120,6 @@ dmypy.json # Yarn cache .yarn/ .jupyter_ystore.db + +**/ui-tests/test-results/ +**/ui-tests/playwright-report/ diff --git a/package.json b/package.json index 74727a2..09a2c76 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,8 @@ "node_modules", "dist", "coverage", - "**/*.d.ts" + "**/*.d.ts", + "ui-tests" ], "eslintConfig": { "extends": [ diff --git a/src/index.ts b/src/index.ts index 8fae8d0..927a163 100644 --- a/src/index.ts +++ b/src/index.ts @@ -87,6 +87,7 @@ const plugin: JupyterFrontEndPlugin = { tracker.add(widget); app.shell.activateById('jupytercad::leftControlPanel'); }); + console.log('jupytercad_openvsp:plugin is activated!'); } }; diff --git a/ui-tests/jupyter_server_test_config.py b/ui-tests/jupyter_server_test_config.py new file mode 100644 index 0000000..f51a13b --- /dev/null +++ b/ui-tests/jupyter_server_test_config.py @@ -0,0 +1,4 @@ +from jupyterlab.galata import configure_jupyter_server + +configure_jupyter_server(c) # noqa F821 +c.LabApp.collaborative = True # noqa F821 diff --git a/ui-tests/tests/ui.spec.ts b/ui-tests/tests/ui.spec.ts new file mode 100644 index 0000000..37a0e70 --- /dev/null +++ b/ui-tests/tests/ui.spec.ts @@ -0,0 +1,81 @@ +import { expect, test, galata } from '@jupyterlab/galata'; +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 + }); + } + }); + } + }); +}); diff --git a/ui-tests/tests/ui.spec.ts-snapshots/Render-A320-vsp3-linux.png b/ui-tests/tests/ui.spec.ts-snapshots/Render-A320-vsp3-linux.png new file mode 100644 index 0000000..88a8b15 Binary files /dev/null and b/ui-tests/tests/ui.spec.ts-snapshots/Render-A320-vsp3-linux.png differ