mirror of
https://github.com/cds-astro/aladin-lite.git
synced 2025-12-12 07:40:26 -08:00
✅ Add basic playwright tests for Aladin Lite UI
This commit is contained in:
committed by
Matthieu Baumann
parent
fcefe89f17
commit
c89156211b
39
.github/workflows/playwright.yml
vendored
Normal file
39
.github/workflows/playwright.yml
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
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 the rust compiler
|
||||
run: |
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
source "$HOME/.cargo/env"
|
||||
rustup default nightly
|
||||
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
|
||||
- name: Install wasm-pack
|
||||
run: |
|
||||
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -y
|
||||
- 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
|
||||
1
.github/workflows/test.yml
vendored
1
.github/workflows/test.yml
vendored
@@ -36,4 +36,3 @@ jobs:
|
||||
- name: "Run some tests"
|
||||
run: |
|
||||
npm run test:build
|
||||
npm run test:unit
|
||||
@@ -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",
|
||||
|
||||
66
playwright.config.ts
Normal file
66
playwright.config.ts
Normal file
@@ -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: 1,
|
||||
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,
|
||||
},
|
||||
});
|
||||
42
tests/al-ui-off.html
Normal file
42
tests/al-ui-off.html
Normal file
@@ -0,0 +1,42 @@
|
||||
<!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: "../examples/hips/CDS_P_DSS2_color",
|
||||
target: "05 40 59.12 -02 27 04.1",
|
||||
fov: 2,
|
||||
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>
|
||||
42
tests/al-ui-on.html
Normal file
42
tests/al-ui-on.html
Normal file
@@ -0,0 +1,42 @@
|
||||
<!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: "../examples/hips/CDS_P_DSS2_color",
|
||||
target: "05 40 59.12 -02 27 04.1",
|
||||
fov: 2,
|
||||
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>
|
||||
28
tests/example.spec.ts
Normal file
28
tests/example.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import {test, expect, LocatorScreenshotOptions} from '@playwright/test';
|
||||
|
||||
async function open(page, exampleName) {
|
||||
await page.goto(`http://localhost:5173/tests/${exampleName}.html`);
|
||||
await page.setViewportSize({height: 600, width: 800});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
BIN
tests/example.spec.ts-snapshots/al-ui-off-1-chromium-linux.png
Normal file
BIN
tests/example.spec.ts-snapshots/al-ui-off-1-chromium-linux.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 478 KiB |
BIN
tests/example.spec.ts-snapshots/al-ui-off-1-firefox-linux.png
Normal file
BIN
tests/example.spec.ts-snapshots/al-ui-off-1-firefox-linux.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 575 KiB |
BIN
tests/example.spec.ts-snapshots/al-ui-off-1-webkit-linux.png
Normal file
BIN
tests/example.spec.ts-snapshots/al-ui-off-1-webkit-linux.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
BIN
tests/example.spec.ts-snapshots/al-ui-on-1-chromium-linux.png
Normal file
BIN
tests/example.spec.ts-snapshots/al-ui-on-1-chromium-linux.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 527 KiB |
BIN
tests/example.spec.ts-snapshots/al-ui-on-1-firefox-linux.png
Normal file
BIN
tests/example.spec.ts-snapshots/al-ui-on-1-firefox-linux.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 612 KiB |
BIN
tests/example.spec.ts-snapshots/al-ui-on-1-webkit-linux.png
Normal file
BIN
tests/example.spec.ts-snapshots/al-ui-on-1-webkit-linux.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
@@ -1,13 +0,0 @@
|
||||
import {Utils} from '@/js/Utils.ts';
|
||||
|
||||
describe('Utils.ts', () => {
|
||||
beforeEach(() => {
|
||||
//delete window.location;
|
||||
window.location = {href: {}, search: ''};
|
||||
});
|
||||
|
||||
it('correctly parse a location parameter', () => {
|
||||
window.location.search = '?survey=DSS';
|
||||
expect(Utils.urlParam('survey')).toEqual('DSS');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user