Skip to content

Commit

Permalink
✅ Add basic playwright tests for Aladin Lite UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jul 22, 2024
1 parent 7c4fdb8 commit 58f65f6
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 53 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Playwright Tests
on:
push:
branches:
- develop
pull_request:
branches:
- develop
workflow_dispatch:
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm install
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rust-src
- name: Install wasm-pack
run: cargo install wasm-pack --version ~0.12
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
39 changes: 0 additions & 39 deletions .github/workflows/test.yml

This file was deleted.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@
"serve:dbg": "npm run dev:dbg",
"preview": "vite preview",
"test:build": "cd src/core && cargo test --release --features webgl2",
"test:unit": "vitest run",
"test:playwright": "npx playwright test",
"test:update-snapshots": "npx playwright test --update-snapshots",
"doc": "jsdoc -c jsdoc.json src/js src/js/shapes && cp aladin-logo.png docs/",
"doc:dev": "npm run doc && open docs/index.html"
},
"devDependencies": {
"@playwright/test": "^1.45.2",
"@types/node": "^20.14.11",
"happy-dom": "^10.11.0",
"jsdoc": "^4.0.2",
"vite": "^4.3.8",
Expand Down
66 changes: 66 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
fullyParallel: true,
retries: 0,
workers: 10,
reporter: 'html',
use: {
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'npm run dev',
url: 'http://localhost:5173/examples/index.html',
reuseExistingServer: true,
timeout: 120000,
},
});
41 changes: 41 additions & 0 deletions tests/al-ui-off.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, height=device-height, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
</head>
<body>
<div id="aladin-lite-div" style="width: 500px; height: 500px"></div>

<script type="text/javascript" src="./../dist/aladin.umd.cjs" charset="utf-8"></script>
<script type="text/javascript">
var aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div',
{
fullScreen: true,
cooFrame: "ICRSd",
survey: "P/DSS2/color",
fov: 180,
showSimbadPointerControl: false,
showShareControl: false,
showContextMenu: false,
showCatalog: false,
showFov: false,
showCooGrid: false,
showFrame: false,
showCooGridControl: false,
showCooLocation: false,
showFullscreenControl: false,
showLayersControl: false,
showProjectionControl: false,
showReticle: false,
showSettingsControl: false,
showStatusBar: false,
showZoomControl: false,
}
);
});
</script>

</body>
</html>
41 changes: 41 additions & 0 deletions tests/al-ui-on.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, height=device-height, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
</head>
<body>
<div id="aladin-lite-div" style="width: 500px; height: 500px"></div>

<script type="text/javascript" src="./../dist/aladin.umd.cjs" charset="utf-8"></script>
<script type="text/javascript">
var aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div',
{
fullScreen: true,
cooFrame: "ICRSd",
survey: "P/DSS2/color",
fov: 180,
showSimbadPointerControl: true,
showShareControl: true,
showContextMenu: true,
showCatalog: true,
showFov: true,
showCooGrid: true,
showFrame: true,
showCooGridControl: true,
showCooLocation: true,
showFullscreenControl: true,
showLayersControl: true,
showProjectionControl: true,
showReticle: true,
showSettingsControl: true,
showStatusBar: true,
showZoomControl: true,
}
);
});
</script>

</body>
</html>
27 changes: 27 additions & 0 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {test, expect, LocatorScreenshotOptions} from '@playwright/test';

async function open(page, exampleName) {
await page.goto(`http://localhost:5173/tests/${exampleName}.html`);
}

const screenshotOptions: LocatorScreenshotOptions = {
type: "png"
};

const toMatchOptions = {
maxDiffPixels: 10
};

const pageTimeout = 2000;

test("al-ui-on", async ({ page }) => {
await open(page, "al-ui-on");
await page.waitForTimeout(pageTimeout);
expect(await page.locator('canvas').nth(1).screenshot(screenshotOptions)).toMatchSnapshot(toMatchOptions);
});

test("al-ui-off", async ({ page }) => {
await open(page, "al-ui-off");
await page.waitForTimeout(pageTimeout);
expect(await page.locator('canvas').nth(1).screenshot(screenshotOptions)).toMatchSnapshot(toMatchOptions);
});
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.
13 changes: 0 additions & 13 deletions tests/unit/Utils.spec.js

This file was deleted.

0 comments on commit 58f65f6

Please sign in to comment.