✨ docker-compose.yml + gitlab-ci.yml + passage angular 22 + test end2end
This commit is contained in:
1 parent
ddcb101a6c
commit
3bd2688527
14 files changed
+3622
-4331
No files matched your search
@@ -0,0 +1,7 @@
|
||||
.git
|
||||
.angular
|
||||
dist
|
||||
node_modules
|
||||
server/*.db
|
||||
npm-debug.log*
|
||||
.DS_Store
|
||||
@@ -5,3 +5,8 @@ out-tsc/
|
||||
server/*.db
|
||||
npm-debug.log*
|
||||
.DS_Store
|
||||
|
||||
# Playwright e2e
|
||||
e2e/.tmp/
|
||||
test-results/
|
||||
playwright-report/
|
||||
@@ -0,0 +1,56 @@
|
||||
default:
|
||||
tags:
|
||||
- runner
|
||||
|
||||
stages:
|
||||
- build
|
||||
- e2e
|
||||
- image
|
||||
|
||||
variables:
|
||||
IMAGE_TAG: "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA"
|
||||
|
||||
# Build de l'app Angular (vérifie aussi la compilation TypeScript)
|
||||
build:
|
||||
stage: build
|
||||
image: node:22-alpine
|
||||
cache:
|
||||
key: "$CI_COMMIT_REF_SLUG"
|
||||
paths:
|
||||
- node_modules/
|
||||
script:
|
||||
- npm ci
|
||||
- npm run build
|
||||
artifacts:
|
||||
paths:
|
||||
- dist/
|
||||
expire_in: 1 day
|
||||
|
||||
# Tests end-to-end Playwright (l'image officielle contient Chromium)
|
||||
e2e:
|
||||
stage: e2e
|
||||
image: mcr.microsoft.com/playwright:v1.65.0
|
||||
cache:
|
||||
key: "$CI_COMMIT_REF_SLUG"
|
||||
paths:
|
||||
- node_modules/
|
||||
script:
|
||||
- npm ci
|
||||
- npx playwright test --project=chromium
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- e2e/.tmp/
|
||||
expire_in: 1 week
|
||||
|
||||
# Build et push de l'image Docker sur le registre GitLab
|
||||
docker-image:
|
||||
stage: image
|
||||
image: docker:27-cli
|
||||
services:
|
||||
- docker:27-dind
|
||||
script:
|
||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
|
||||
- docker build -t "$IMAGE_TAG" -t "$CI_REGISTRY_IMAGE:latest" .
|
||||
- docker push "$IMAGE_TAG"
|
||||
- docker push "$CI_REGISTRY_IMAGE:latest"
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
# Étape 1 : build du front Angular
|
||||
FROM node:22-alpine AS build
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Étape 2 : image finale (API comptes + fichiers statiques du build)
|
||||
FROM node:22-alpine
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
COPY --from=build /app/dist ./dist
|
||||
COPY --from=build /app/server ./server
|
||||
EXPOSE 8787
|
||||
VOLUME ["/data"]
|
||||
# node:sqlite nécessite encore le flag --experimental-sqlite sur Node 22
|
||||
CMD ["node", "--experimental-sqlite", "server/server.mjs"]
|
||||
@@ -24,6 +24,23 @@ npm start
|
||||
Pour la préproduction : `npm run preview` (build puis service du front ET de l'API
|
||||
sur http://127.0.0.1:8787).
|
||||
|
||||
## Tests e2e (Playwright)
|
||||
|
||||
```bash
|
||||
npx playwright install chromium # une seule fois (navigateur de test)
|
||||
npm run e2e # build + API + suite complète
|
||||
npm run e2e:ui # mode interactif
|
||||
npm run e2e:report # rapport HTML (e2e/.tmp/report)
|
||||
```
|
||||
|
||||
`playwright.config.ts` démarre `npm run preview` sur http://127.0.0.1:8787 avec une
|
||||
base SQLite isolée (`e2e/.tmp/orbit-e2e.db`). Les specs dans `e2e/` couvrent :
|
||||
l'API HTTP (`api.spec.ts`), l'authentification — inscription, connexion, session
|
||||
persistée, migration localStorage (`auth.spec.ts`), les quiz — partie complète,
|
||||
mode carte Leaflet, navigation (`quiz.spec.ts`) — et boutique, boosters, profil
|
||||
(`shop.spec.ts`). En CI, le job `e2e` de `.gitlab-ci.yml` exécute la suite sur le
|
||||
runner tagué `runner`.
|
||||
|
||||
|
||||
## Structure
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
services:
|
||||
orbit:
|
||||
build: .
|
||||
image: orbit:latest
|
||||
container_name: orbit
|
||||
ports:
|
||||
- "8787:8787"
|
||||
environment:
|
||||
PORT: "8787"
|
||||
# Base SQLite persistée hors du conteneur (le serveur lit ORBIT_DB)
|
||||
ORBIT_DB: /data/orbit.db
|
||||
volumes:
|
||||
- orbit-data:/data
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
orbit-data:
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { uniq } from './helpers';
|
||||
|
||||
test.describe('API Orbit (HTTP)', () => {
|
||||
test('GET /api/stats répond un compteur', async ({ request }) => {
|
||||
const r = await request.get('/api/stats');
|
||||
expect(r.ok()).toBeTruthy();
|
||||
const body = await r.json();
|
||||
expect(typeof body.users).toBe('number');
|
||||
});
|
||||
|
||||
test('register : création, doublon et payload invalide', async ({ request }) => {
|
||||
const key = uniq();
|
||||
let r = await request.post('/api/register', {
|
||||
data: { key, name: 'Joueur E2E', salt: '1-2-3', hash: 'AAAA', state: { pts: 5 } },
|
||||
});
|
||||
expect(r.status()).toBe(201);
|
||||
expect(await r.json()).toEqual({ ok: true });
|
||||
|
||||
// même clé → taken
|
||||
r = await request.post('/api/register', {
|
||||
data: { key, name: 'Autre', salt: 's', hash: 'AAAA' },
|
||||
});
|
||||
expect(r.status()).toBe(200);
|
||||
expect((await r.json()).taken).toBe(true);
|
||||
|
||||
// clé invalide → 400
|
||||
r = await request.post('/api/register', {
|
||||
data: { key: '!! invalide !!', name: 'X', salt: 's', hash: 'AAAA' },
|
||||
});
|
||||
expect(r.status()).toBe(400);
|
||||
});
|
||||
|
||||
test('user : lecture, état, compte inconnu', async ({ request }) => {
|
||||
const key = uniq();
|
||||
await request.post('/api/register', {
|
||||
data: { key, name: 'Lecteur', salt: '9-9', hash: 'BBBB', state: { pts: 5 } },
|
||||
});
|
||||
|
||||
let r = await request.get('/api/user/' + key);
|
||||
expect(r.ok()).toBeTruthy();
|
||||
const u = await r.json();
|
||||
expect(u.key).toBe(key);
|
||||
expect(u.name).toBe('Lecteur');
|
||||
expect(u.salt).toBe('9-9');
|
||||
expect(u.state.pts).toBe(5);
|
||||
|
||||
r = await request.get('/api/user/' + uniq());
|
||||
expect((await r.json()).missing).toBe(true);
|
||||
});
|
||||
|
||||
test('state : sauvegarde puis relecture, utilisateur inconnu → 404', async ({ request }) => {
|
||||
const key = uniq();
|
||||
await request.post('/api/register', {
|
||||
data: { key, name: 'Sauveur', salt: 's', hash: 'AAAA', state: {} },
|
||||
});
|
||||
|
||||
let r = await request.put('/api/state/' + key, { data: { state: { pts: 42, lvl: 3 } } });
|
||||
expect(r.ok()).toBeTruthy();
|
||||
expect(await r.json()).toEqual({ ok: true });
|
||||
|
||||
r = await request.get('/api/user/' + key);
|
||||
expect((await r.json()).state).toEqual({ pts: 42, lvl: 3 });
|
||||
|
||||
r = await request.put('/api/state/' + uniq(), { data: { state: {} } });
|
||||
expect(r.status()).toBe(404);
|
||||
});
|
||||
|
||||
test('import : migration de comptes localStorage, doublons ignorés', async ({ request }) => {
|
||||
const k1 = uniq();
|
||||
const k2 = uniq();
|
||||
const r = await request.post('/api/import', {
|
||||
data: {
|
||||
users: {
|
||||
[k1]: { name: 'Importe1', salt: 's', hash: 'AAAA', state: { pts: 1 } },
|
||||
[k2]: { name: 'Importe2', salt: 's', hash: 'AAAA' },
|
||||
'clé invalide': { name: 'X', salt: 's', hash: 'AAAA' },
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(r.ok()).toBeTruthy();
|
||||
expect((await r.json()).imported).toBe(2);
|
||||
|
||||
// re-import → aucun doublon
|
||||
const r2 = await request.post('/api/import', {
|
||||
data: { users: { [k1]: { name: 'Importe1', salt: 's', hash: 'AAAA' } } },
|
||||
});
|
||||
expect((await r2.json()).imported).toBe(0);
|
||||
|
||||
const u = await (await request.get('/api/user/' + k1)).json();
|
||||
expect(u.name).toBe('Importe1');
|
||||
expect(u.state.pts).toBe(1);
|
||||
});
|
||||
|
||||
test('statique : front servi, fallback SPA, 404 API', async ({ request }) => {
|
||||
const home = await request.get('/');
|
||||
expect(home.ok()).toBeTruthy();
|
||||
expect(home.headers()['content-type']).toContain('text/html');
|
||||
expect(await home.text()).toContain('<app-root>');
|
||||
|
||||
const spa = await request.get('/une/route/quelconque');
|
||||
expect(spa.ok()).toBeTruthy();
|
||||
expect(await spa.text()).toContain('<app-root>');
|
||||
|
||||
expect((await request.get('/api/nope')).status()).toBe(404);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,138 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { uniq, registerUI, loginUI, expectLoggedIn, registerAPI } from './helpers';
|
||||
|
||||
/** localStorage stocke du JSON (LS() = JSON.stringify) */
|
||||
const sessionOf = (page: import('@playwright/test').Page) =>
|
||||
page.evaluate(() => JSON.parse(localStorage.getItem('orbit_session') || 'null'));
|
||||
|
||||
test.describe('Authentification (UI)', () => {
|
||||
test('la page d\'accueil affiche le formulaire de connexion', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await expect(page).toHaveTitle(/Orbit/);
|
||||
await expect(page.locator('#af')).toBeVisible();
|
||||
await expect(page.locator('#hd')).toContainText('Orbit');
|
||||
await expect(page.locator('#pn')).toBeVisible();
|
||||
await expect(page.locator('#pw')).toBeVisible();
|
||||
// champ de confirmation absent en mode connexion
|
||||
await expect(page.locator('#pc')).toHaveCount(0);
|
||||
// bascule inscription → champ #pc présent
|
||||
await page.getByRole('button', { name: 'Inscription', exact: true }).click();
|
||||
await expect(page.locator('#pc')).toBeVisible();
|
||||
});
|
||||
|
||||
test('inscription valide → session créée, 100 pts, compte côté serveur', async ({ page, request }) => {
|
||||
const name = uniq('joueur');
|
||||
const key = await registerUI(page, name);
|
||||
|
||||
// header connecté : nav + points de départ (BASE().pts = 100)
|
||||
await expect(page.locator('#hd')).toContainText('🪙 100');
|
||||
await expect(page.locator('#hd nav button[data-t="shop"]')).toBeVisible();
|
||||
await expect(page.locator('#hd nav button[data-t="boost"]')).toBeVisible();
|
||||
await expect(page.locator('#hd nav button[data-t="me"]')).toBeVisible();
|
||||
|
||||
// session persistée en localStorage
|
||||
await expect.poll(() => sessionOf(page)).toBe(key);
|
||||
|
||||
// compte bien enregistré côté API
|
||||
const u = await (await request.get('/api/user/' + key)).json();
|
||||
expect(u.name).toBe(name);
|
||||
expect(u.state.pts).toBe(100);
|
||||
expect(u.state.free).toEqual({ std: 1, pre: 0 });
|
||||
});
|
||||
|
||||
test('validation : pseudo trop court, mot de passe trop court, confirmation différente', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await page.getByRole('button', { name: 'Inscription', exact: true }).click();
|
||||
|
||||
await page.fill('#pn', 'ab');
|
||||
await page.fill('#pw', 'secret123');
|
||||
await page.fill('#pc', 'secret123');
|
||||
await page.getByRole('button', { name: 'Créer mon compte' }).click();
|
||||
await expect(page.locator('#er')).toContainText('3 à 16 caractères');
|
||||
|
||||
await page.fill('#pn', uniq());
|
||||
await page.fill('#pw', '123');
|
||||
await page.fill('#pc', '123');
|
||||
await page.getByRole('button', { name: 'Créer mon compte' }).click();
|
||||
await expect(page.locator('#er')).toContainText('6 caractères minimum');
|
||||
|
||||
await page.fill('#pw', 'secret123');
|
||||
await page.fill('#pc', 'secret456');
|
||||
await page.getByRole('button', { name: 'Créer mon compte' }).click();
|
||||
await expect(page.locator('#er')).toContainText('différents');
|
||||
});
|
||||
|
||||
test('pseudo déjà pris → erreur affichée', async ({ page, request }) => {
|
||||
const name = uniq('pris');
|
||||
await registerAPI(request, name.toLowerCase());
|
||||
|
||||
await page.goto('/');
|
||||
await page.getByRole('button', { name: 'Inscription', exact: true }).click();
|
||||
await page.fill('#pn', name);
|
||||
await page.fill('#pw', 'secret123');
|
||||
await page.fill('#pc', 'secret123');
|
||||
await page.getByRole('button', { name: 'Créer mon compte' }).click();
|
||||
await expect(page.locator('#er')).toContainText('déjà pris');
|
||||
// toujours sur le formulaire
|
||||
await expect(page.locator('#af')).toBeVisible();
|
||||
});
|
||||
|
||||
test('connexion : mauvais mot de passe puis bon, session persistante au rechargement', async ({ page }) => {
|
||||
const name = uniq('membre');
|
||||
await registerUI(page, name);
|
||||
await page.locator('#lo').click();
|
||||
await expect(page.locator('#af')).toBeVisible();
|
||||
|
||||
// mauvais mot de passe
|
||||
await loginUI(page, name, 'mauvais1');
|
||||
await expect(page.locator('#er')).toContainText('incorrect');
|
||||
await expect(page.locator('#af')).toBeVisible();
|
||||
|
||||
// bon mot de passe
|
||||
await loginUI(page, name, 'secret123');
|
||||
await expectLoggedIn(page);
|
||||
|
||||
// rechargement → toujours connecté grâce à orbit_session
|
||||
await page.reload();
|
||||
await expectLoggedIn(page);
|
||||
await expect(page.locator('#af')).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('état synchronisé depuis le serveur au chargement', async ({ page, request }) => {
|
||||
const name = uniq('sync');
|
||||
const key = await registerUI(page, name);
|
||||
|
||||
// modifie l'état côté serveur (comme une autre session)
|
||||
await request.put('/api/state/' + key, { data: { state: { pts: 777, xp: 0, lvl: 2, free: { std: 1, pre: 0 }, own: [], eq: { badge: null, banner: null, title: null }, played: 3, best: 50 } } });
|
||||
|
||||
await page.reload();
|
||||
await expect(page.locator('#hd nav button[data-t="play"]')).toBeVisible();
|
||||
await expect(page.locator('#hd')).toContainText('🪙 777');
|
||||
await expect(page.locator('#hd')).toContainText('Niveau 2');
|
||||
});
|
||||
|
||||
test('déconnexion → retour au formulaire, session supprimée', async ({ page }) => {
|
||||
await registerUI(page, uniq('out'));
|
||||
await page.locator('#lo').click();
|
||||
await expect(page.locator('#af')).toBeVisible();
|
||||
await expect.poll(() => sessionOf(page)).toBe('');
|
||||
});
|
||||
|
||||
test('migration : comptes localStorage importés vers l\'API au chargement', async ({ page, request }) => {
|
||||
const key = uniq('mig');
|
||||
await page.addInitScript((k) => {
|
||||
localStorage.setItem('orbit_users', JSON.stringify({
|
||||
[k]: { name: 'Migration', salt: '5-5', hash: 'CCCC', state: { pts: 33 } },
|
||||
}));
|
||||
}, key);
|
||||
|
||||
await page.goto('/');
|
||||
await expect(page.locator('#af')).toBeVisible();
|
||||
|
||||
// l'import est déclenché au chargement du moteur
|
||||
await expect.poll(async () => {
|
||||
const u = await (await request.get('/api/user/' + key)).json();
|
||||
return u && u.hash ? u.state.pts : null;
|
||||
}, { timeout: 15_000 }).toBe(33);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Page, expect } from '@playwright/test';
|
||||
|
||||
/** Pseudo unique compatible avec la règle serveur ^[a-z0-9_-]{3,16}$ */
|
||||
export const uniq = (prefix = 'e2e') =>
|
||||
(prefix + Date.now().toString(36) + Math.random().toString(36).slice(2, 6))
|
||||
.toLowerCase()
|
||||
.slice(0, 16);
|
||||
|
||||
/** Inscription via l'UI ; retourne la clé de session (pseudo en minuscules). */
|
||||
export async function registerUI(page: Page, name: string, password = 'secret123'): Promise<string> {
|
||||
await page.goto('/');
|
||||
await expect(page.locator('#af')).toBeVisible();
|
||||
await page.getByRole('button', { name: 'Inscription', exact: true }).click();
|
||||
await page.fill('#pn', name);
|
||||
await page.fill('#pw', password);
|
||||
await page.fill('#pc', password);
|
||||
await page.getByRole('button', { name: 'Créer mon compte' }).click();
|
||||
await expect(page.locator('#hd nav button[data-t="play"]')).toBeVisible();
|
||||
return name.toLowerCase();
|
||||
}
|
||||
|
||||
/** Connexion via l'UI (bascule d'abord sur l'onglet Connexion). */
|
||||
export async function loginUI(page: Page, name: string, password = 'secret123'): Promise<void> {
|
||||
await page.goto('/');
|
||||
await expect(page.locator('#af')).toBeVisible();
|
||||
await page.getByRole('button', { name: 'Connexion', exact: true }).click();
|
||||
await page.fill('#pn', name);
|
||||
await page.fill('#pw', password);
|
||||
await page.getByRole('button', { name: 'Se connecter' }).click();
|
||||
}
|
||||
|
||||
/** Attend que l'utilisateur soit connecté (nav du header affichée). */
|
||||
export async function expectLoggedIn(page: Page): Promise<void> {
|
||||
await expect(page.locator('#hd nav button[data-t="play"]')).toBeVisible();
|
||||
}
|
||||
|
||||
/** Inscription via l'API (hash arbitraire : le serveur ne vérifie pas). */
|
||||
export async function registerAPI(request: import('@playwright/test').APIRequestContext, key: string, state: object = { pts: 100 }): Promise<void> {
|
||||
const r = await request.post('/api/register', {
|
||||
data: { key, name: key, salt: '1-2-3', hash: 'AAAA', state },
|
||||
});
|
||||
expect(r.status()).toBe(201);
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import { test, expect, Page } from '@playwright/test';
|
||||
import { uniq, registerUI } from './helpers';
|
||||
|
||||
/** Navigue jusqu'au lancement d'une partie et renvoie le nombre de questions. */
|
||||
async function startGame(page: Page, cat: string, mode: string, diff: string): Promise<number> {
|
||||
await expect(page.locator('#app h2')).toContainText('Choisis une catégorie');
|
||||
await page.locator(`#app button[data-k="${cat}"]`).click();
|
||||
await page.locator(`#app button[data-m="${mode}"]`).click();
|
||||
await page.locator(`#app button[data-d="${diff}"]`).click();
|
||||
await expect(page.locator('#op button').first()).toBeVisible();
|
||||
const bar = await page.locator('#app').textContent();
|
||||
const m = bar!.match(/Question 1 \/ (\d+)/);
|
||||
expect(m).not.toBeNull();
|
||||
return Number(m![1]);
|
||||
}
|
||||
|
||||
/** Répond à la question courante (clic sur la 1re option) puis passe à la suivante. */
|
||||
async function answerAndNext(page: Page): Promise<void> {
|
||||
await page.locator('#op button').first().click();
|
||||
// options désactivées + bonne réponse surlignée
|
||||
await expect(page.locator('#op button').first()).toBeDisabled();
|
||||
await expect(page.locator('#op button.border-ok')).toHaveCount(1);
|
||||
await page.locator('#go').click();
|
||||
}
|
||||
|
||||
test.describe('Quiz (UI)', () => {
|
||||
test('parcours complet : drapeaux facile, 10 questions, écran de fin', async ({ page }) => {
|
||||
await registerUI(page, uniq('quiz'));
|
||||
|
||||
const total = await startGame(page, 'earth', 'flag', '0');
|
||||
expect(total).toBe(10);
|
||||
// facile : 3 choix, pas de chrono
|
||||
await expect(page.locator('#op button')).toHaveCount(3);
|
||||
await expect(page.locator('#tt')).toHaveCount(0);
|
||||
// la question affiche un drapeau et son libellé
|
||||
await expect(page.locator('#qc')).toContainText('Quel est ce pays ?');
|
||||
await expect(page.locator('#qc img')).toBeVisible();
|
||||
|
||||
for (let i = 1; i < total; i++) {
|
||||
await answerAndNext(page);
|
||||
await expect(page.locator('#app')).toContainText(`Question ${i + 1} / ${total}`);
|
||||
}
|
||||
// dernière question → "Voir le résultat"
|
||||
await page.locator('#op button').first().click();
|
||||
await expect(page.locator('#go')).toContainText('Voir le résultat');
|
||||
await page.locator('#go').click();
|
||||
|
||||
// écran de fin
|
||||
await expect(page.locator('#app h2')).toContainText('Partie terminée');
|
||||
await expect(page.locator('#app')).toContainText(/\d+ bonnes réponses sur 10/);
|
||||
await expect(page.locator('#app')).toContainText(/\+\d+ points/);
|
||||
await expect(page.locator('#rp')).toContainText('Rejouer');
|
||||
await expect(page.locator('#mn')).toContainText('Menu');
|
||||
|
||||
// retour au menu : on revient à la liste des modes de la catégorie, puis à l'accueil
|
||||
await page.locator('#mn').click();
|
||||
await expect(page.locator('#app h2')).toContainText('Terre');
|
||||
await page.locator('#bk').click();
|
||||
await expect(page.locator('#app h2')).toContainText('Choisis une catégorie');
|
||||
// la partie est comptabilisée
|
||||
await expect(page.locator('#app')).toContainText('1 parties jouées');
|
||||
});
|
||||
|
||||
test('quiz espace : planètes, options SVG et 4 choix en normal', async ({ page }) => {
|
||||
await registerUI(page, uniq('space'));
|
||||
await startGame(page, 'space', 'planet', '1');
|
||||
// normal : 4 choix et chrono visible
|
||||
await expect(page.locator('#op button')).toHaveCount(4);
|
||||
await expect(page.locator('#tt')).toContainText('⏱');
|
||||
// planète rendue (div role=img avec texture) + libellé de la question
|
||||
await expect(page.locator('#qc [role="img"]')).toBeVisible();
|
||||
await expect(page.locator('#qc')).toContainText('Quel est cet astre ?');
|
||||
await answerAndNext(page);
|
||||
await expect(page.locator('#app')).toContainText('Question 2 /');
|
||||
});
|
||||
|
||||
test('mode Lieux : la carte Leaflet s\'affiche, clic → validation activée', async ({ page }) => {
|
||||
await registerUI(page, uniq('carte'));
|
||||
await expect(page.locator('#app h2')).toContainText('Choisis une catégorie');
|
||||
await page.locator('#app button[data-k="earth"]').click();
|
||||
await page.locator('#app button[data-m="place"]').click();
|
||||
await page.locator('#app button[data-d="0"]').click();
|
||||
|
||||
// la manche charge (photo ou indice emoji), puis la carte apparaît
|
||||
await expect(page.locator('#map')).toBeVisible({ timeout: 30_000 });
|
||||
await expect(page.locator('#val')).toBeDisabled();
|
||||
|
||||
// clic sur la carte → point placé → bouton de validation activé
|
||||
await page.locator('#map').click({ position: { x: 200, y: 180 } });
|
||||
await expect(page.locator('#val')).toBeEnabled();
|
||||
await page.locator('#val').click();
|
||||
|
||||
// feedback puis bouton suivant
|
||||
await expect(page.locator('#go')).toBeVisible();
|
||||
});
|
||||
|
||||
test('navigation retour entre catégories, modes et difficultés', async ({ page }) => {
|
||||
await registerUI(page, uniq('nav'));
|
||||
await page.locator('#app button[data-k="space"]').click();
|
||||
await expect(page.locator('#app h2')).toContainText('Espace');
|
||||
await page.locator('#bk').click();
|
||||
await expect(page.locator('#app h2')).toContainText('Choisis une catégorie');
|
||||
|
||||
await page.locator('#app button[data-k="earth"]').click();
|
||||
await page.locator('#app button[data-m="cap"]').click();
|
||||
await expect(page.locator('#app h2')).toContainText('Capitales');
|
||||
await expect(page.locator('#app button[data-d]')).toHaveCount(4);
|
||||
await page.locator('#bk').click();
|
||||
await expect(page.locator('#app button[data-m]')).toHaveCount(4); // 4 modes Terre
|
||||
});
|
||||
|
||||
test('onglets du header : Jouer / Boutique / Boosters / Profil', async ({ page }) => {
|
||||
await registerUI(page, uniq('tabs'));
|
||||
await page.locator('#hd nav button[data-t="shop"]').click();
|
||||
await expect(page.locator('#app h2')).toContainText('Boutique');
|
||||
await page.locator('#hd nav button[data-t="boost"]').click();
|
||||
await expect(page.locator('#app h2')).toContainText('Boosters');
|
||||
await page.locator('#hd nav button[data-t="me"]').click();
|
||||
await expect(page.locator('#app')).toContainText('Niveau 1');
|
||||
await page.locator('#hd nav button[data-t="play"]').click();
|
||||
await expect(page.locator('#app h2')).toContainText('Choisis une catégorie');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,92 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { uniq, registerUI } from './helpers';
|
||||
|
||||
test.describe('Boutique, boosters et profil (UI)', () => {
|
||||
test('achat d\'un badge : points débités, objet possédé, état sauvé côté serveur', async ({ page, request }) => {
|
||||
const name = uniq('shop');
|
||||
const key = await registerUI(page, name);
|
||||
await expect(page.locator('#hd')).toContainText('🪙 100');
|
||||
|
||||
await page.locator('#hd nav button[data-t="shop"]').click();
|
||||
await expect(page.locator('#app h2')).toContainText('Boutique');
|
||||
|
||||
// badge le moins cher (60 pts) : bouton actif
|
||||
const buy = page.locator('.buy[data-id="b0"]');
|
||||
await expect(buy).toBeEnabled();
|
||||
await expect(buy).toContainText('60');
|
||||
// un objet à 260 pts est désactivé (pas assez de points)
|
||||
await expect(page.locator('.buy[data-id="c0"]')).toBeDisabled();
|
||||
|
||||
await buy.click();
|
||||
await expect(page.locator('#hd')).toContainText('🪙 40');
|
||||
await expect(page.locator('.buy[data-id="b0"]').first()).toHaveCount(0);
|
||||
await expect(page.locator('#app')).toContainText('✓ Possédé');
|
||||
|
||||
// état persisté côté serveur
|
||||
const u = await (await request.get('/api/user/' + key)).json();
|
||||
expect(u.state.pts).toBe(40);
|
||||
expect(u.state.own).toContain('b0');
|
||||
});
|
||||
|
||||
test('filtres de la boutique (rareté)', async ({ page }) => {
|
||||
await registerUI(page, uniq('filtre'));
|
||||
await page.locator('#hd nav button[data-t="shop"]').click();
|
||||
await page.locator('#app button[data-f="rare"]').click();
|
||||
// plus de boutons "commun" à 60 pts dans la vue filtrée
|
||||
await expect(page.locator('.buy[data-id="b0"]')).toHaveCount(0);
|
||||
await expect(page.locator('.buy').first()).toBeVisible();
|
||||
await page.locator('#app button[data-f="all"]').click();
|
||||
await expect(page.locator('.buy[data-id="b0"]')).toBeVisible();
|
||||
});
|
||||
|
||||
test('booster gratuit au niveau 1 : tirage de 3 objets et collection', async ({ page, request }) => {
|
||||
const name = uniq('boost');
|
||||
const key = await registerUI(page, name);
|
||||
|
||||
await page.locator('#hd nav button[data-t="boost"]').click();
|
||||
await expect(page.locator('#app h2')).toContainText('Boosters');
|
||||
// badge "1" sur l'onglet Boosters (free.std = 1)
|
||||
await expect(page.locator('#hd nav button[data-t="boost"]')).toContainText('1');
|
||||
|
||||
const free = page.locator('.opf[data-k="std"]');
|
||||
await expect(free).toBeEnabled();
|
||||
await expect(free).toContainText('Gratuit (1)');
|
||||
await free.click();
|
||||
|
||||
// tirage : 3 cartes (après l'animation shake de 450 ms)
|
||||
await expect(page.locator('.tirage > div')).toHaveCount(3, { timeout: 10_000 });
|
||||
await expect(page.locator('.tirage')).toContainText(/Nouveau !|Doublon · remboursé/);
|
||||
// collection affichée en dessous
|
||||
await expect(page.locator('#col')).toBeVisible();
|
||||
|
||||
// le booster gratuit est consommé
|
||||
const u = await (await request.get('/api/user/' + key)).json();
|
||||
expect(u.state.free.std).toBe(0);
|
||||
expect(u.state.own.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
test('profil : infos du compte et équipement d\'un badge acheté', async ({ page, request }) => {
|
||||
const name = uniq('profil');
|
||||
const key = await registerUI(page, name);
|
||||
|
||||
// achète le badge b0 (60 pts)
|
||||
await page.locator('#hd nav button[data-t="shop"]').click();
|
||||
await page.locator('.buy[data-id="b0"]').click();
|
||||
await expect(page.locator('#hd')).toContainText('🪙 40');
|
||||
|
||||
// profil
|
||||
await page.locator('#hd nav button[data-t="me"]').click();
|
||||
await expect(page.locator('#app')).toContainText(name);
|
||||
await expect(page.locator('#app')).toContainText('Niveau 1');
|
||||
await expect(page.locator('#app')).toContainText('0 parties · record 0 pts');
|
||||
|
||||
// badge possédé → bouton Équiper
|
||||
const eq = page.locator('.eqb[data-id="b0"]');
|
||||
await expect(eq).toContainText('Équiper');
|
||||
await eq.click();
|
||||
await expect(page.locator('.eqb[data-id="b0"]')).toContainText('Retirer');
|
||||
|
||||
const u = await (await request.get('/api/user/' + key)).json();
|
||||
expect(u.state.eq.badge).toBe('b0');
|
||||
});
|
||||
});
|
||||
Generated
+2948
-4322
File diff suppressed because it is too large.
Load diff
+13
-9
@@ -8,21 +8,25 @@
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"preview": "ng build && node server/server.mjs"
|
||||
"preview": "ng build && node server/server.mjs",
|
||||
"e2e": "playwright test",
|
||||
"e2e:ui": "playwright test --ui",
|
||||
"e2e:report": "playwright show-report"
|
||||
},
|
||||
"dependencies": {
|
||||
"@angular/common": "^19.2.0",
|
||||
"@angular/compiler": "^19.2.0",
|
||||
"@angular/core": "^19.2.0",
|
||||
"@angular/platform-browser": "^19.2.0",
|
||||
"@angular/common": "^22.2.5",
|
||||
"@angular/compiler": "^22.2.5",
|
||||
"@angular/core": "^22.2.5",
|
||||
"@angular/platform-browser": "^22.2.5",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.8.0",
|
||||
"zone.js": "~0.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular/build": "^19.2.0",
|
||||
"@angular/cli": "^19.2.0",
|
||||
"@angular/compiler-cli": "^19.2.0",
|
||||
"typescript": "~5.6.3"
|
||||
"@angular/build": "^22.2.6",
|
||||
"@angular/cli": "^22.2.6",
|
||||
"@angular/compiler-cli": "^22.2.5",
|
||||
"@playwright/test": "^1.65.0",
|
||||
"typescript": "~6.0.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
// Base SQLite dédiée aux tests e2e, nettoyée à chaque lancement.
|
||||
const TMP = path.join(__dirname, 'e2e', '.tmp');
|
||||
try { fs.rmSync(TMP, { recursive: true, force: true }); } catch { /* serveur encore verrouillé : ignoré */ }
|
||||
fs.mkdirSync(TMP, { recursive: true });
|
||||
const E2E_DB = path.join(TMP, 'orbit-e2e.db');
|
||||
|
||||
export default defineConfig({
|
||||
testDir: './e2e',
|
||||
outputDir: path.join(TMP, 'results'),
|
||||
fullyParallel: false,
|
||||
workers: 1,
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
timeout: 60_000,
|
||||
reporter: [
|
||||
['list'],
|
||||
['html', { outputFolder: path.join(TMP, 'report'), open: 'never' }],
|
||||
],
|
||||
use: {
|
||||
baseURL: 'http://127.0.0.1:8787',
|
||||
trace: 'on-first-retry',
|
||||
screenshot: 'only-on-failure',
|
||||
},
|
||||
projects: [
|
||||
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
|
||||
],
|
||||
webServer: {
|
||||
// Build de prod + serveur Node (API + statique) sur 8787, base SQLite isolée.
|
||||
command: 'npm run preview',
|
||||
url: 'http://127.0.0.1:8787/api/stats',
|
||||
timeout: 180_000,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
env: { ...process.env, ORBIT_DB: E2E_DB } as Record<string, string>,
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user