Files
LoreMind/web/e2e/tests/game-system/game-system-templates.spec.ts
IETM_FIXE\ietm6 f24ef0891e
All checks were successful
Build & Push Images / build (brain) (push) Successful in 1m36s
Build & Push Images / build (core) (push) Successful in 2m53s
Build & Push Images / build (web) (push) Successful in 2m36s
Ajout de tests playwright et correction de tests non passant (pour les tests ajoutés : partie game system ).
Correction de plusieurs anomalies : problème de switch entre 2 templates (par exemple si on était sur un template 1 et qu'on voulait passer directement au 2, ce dernier ne chargeait pas) ;
correction du soucis d'apparition de la sidebar à gauche qui disparaissait sans explication ; problème de redirection : lorsqu'on terminait de créer un PJ / PNJ ; on arrivait sur l'accueil de la campagne au lieu de voir le résultat de la création.
Problème de redirection également lors du clique sur un PNJ / PJ sur le coté : on arrivait sur l'édition au lieu de la présentation. Correction de la première lettre stylisée : tout est au même style comme ça plus de probleme de lecture.

Nouveautées : stylisation des modales (notamment suppression, warning.....) avec en prime l'ajout d'un warning lors du changement de système pour avertir que les fiches persos ne sont pas conservées.
Ajout d'une option pour créer un game system directement à la création d'une campagne afin de faciliter la mise en place de cette dernière.
Ajout d'un bouton pour créer un nouveau template directement lorsqu'on créer une page : ça permet de créer un template et de revenir sur la page qu'on était en train de créer sans perdre le titre.

Passage en bêta 0.8.4
2026-05-19 13:37:22 +02:00

152 lines
6.3 KiB
TypeScript

import { test, expect, Page } from '@playwright/test';
import {
seedGameSystem,
deleteGameSystem,
type SeededGameSystem,
} from '../../fixtures/api';
/**
* Tests du composant <app-template-fields-editor> dans le contexte GameSystem.
*
* Le composant est instancie DEUX fois sur la page d'edition d'un GameSystem
* (une fois pour PJ "characterTemplate", une fois pour PNJ "npcTemplate"), donc
* les selecteurs doivent etre scopes a l'instance ciblee. On utilise un helper
* `tfe(label)` qui renvoie le locator de l'editeur correspondant au titre.
*/
test.describe('GameSystem template fields editor (PJ / PNJ)', () => {
let gs: SeededGameSystem;
test.beforeEach(async ({ request }) => {
gs = await seedGameSystem(request);
});
test.afterEach(async ({ request }) => {
if (gs?.id) await deleteGameSystem(request, gs.id);
});
/** Helper : retourne le locator de l'editeur de templates par son label. */
const tfe = (page: Page, label: 'PJ' | 'PNJ') =>
page.locator('.tfe').filter({ hasText: `Champs de la fiche ${label}` });
test('adds a suggested field to the PJ template and persists it', async ({ page, request }) => {
await page.goto(`/game-systems/${gs.id}/edit`);
await expect(page.getByLabel(/^Nom/i)).toHaveValue(gs.name);
const pjEditor = tfe(page, 'PJ');
await expect(pjEditor).toBeVisible();
// Ajout de "Histoire" via la chip suggeree.
await pjEditor.locator('.tfe-add .chip', { hasText: 'Histoire' }).click();
// Une row apparait avec le nom prerempli.
const row = pjEditor.locator('.tfe-item').first();
await expect(row).toBeVisible();
await expect(row.locator('.tfe-name')).toHaveValue('Histoire');
// Save → retour a la liste.
await page.getByRole('button', { name: /^Enregistrer$/i }).click();
await expect(page).toHaveURL(/\/game-systems$/);
// Verification API : le champ est bien dans characterTemplate.
const persisted = await request.get(`/api/game-systems/${gs.id}`).then((r) => r.json());
expect(persisted.characterTemplate).toEqual(
expect.arrayContaining([expect.objectContaining({ name: 'Histoire' })]),
);
// npcTemplate non touche (toujours vide).
expect(persisted.npcTemplate ?? []).toHaveLength(0);
});
test('adds a custom NUMBER field via "Nombre" chip', async ({ page }) => {
await page.goto(`/game-systems/${gs.id}/edit`);
await expect(page.getByLabel(/^Nom/i)).toHaveValue(gs.name);
const pjEditor = tfe(page, 'PJ');
await pjEditor.locator('.tfe-add .chip-custom', { hasText: 'Nombre' }).click();
const row = pjEditor.locator('.tfe-item').first();
await expect(row).toBeVisible();
// Champ vide, nom a remplir, type "NUMBER" pre-selectionne dans le select.
await expect(row.locator('.tfe-name')).toHaveValue('');
await expect(row.locator('.tfe-type')).toHaveValue('NUMBER');
await row.locator('.tfe-name').fill('Points de vie');
await expect(row.locator('.tfe-name')).toHaveValue('Points de vie');
});
test('PJ and PNJ editors are independent (adding to one does not affect the other)', async ({
page,
request,
}) => {
await page.goto(`/game-systems/${gs.id}/edit`);
await expect(page.getByLabel(/^Nom/i)).toHaveValue(gs.name);
await tfe(page, 'PJ').locator('.tfe-add .chip', { hasText: 'Histoire' }).click();
await tfe(page, 'PNJ').locator('.tfe-add .chip', { hasText: 'Motivation' }).click();
await expect(tfe(page, 'PJ').locator('.tfe-item')).toHaveCount(1);
await expect(tfe(page, 'PNJ').locator('.tfe-item')).toHaveCount(1);
await expect(tfe(page, 'PJ').locator('.tfe-item').first().locator('.tfe-name')).toHaveValue('Histoire');
await expect(tfe(page, 'PNJ').locator('.tfe-item').first().locator('.tfe-name')).toHaveValue('Motivation');
await page.getByRole('button', { name: /^Enregistrer$/i }).click();
await expect(page).toHaveURL(/\/game-systems$/);
const persisted = await request.get(`/api/game-systems/${gs.id}`).then((r) => r.json());
expect(persisted.characterTemplate).toEqual(
expect.arrayContaining([expect.objectContaining({ name: 'Histoire' })]),
);
expect(persisted.npcTemplate).toEqual(
expect.arrayContaining([expect.objectContaining({ name: 'Motivation' })]),
);
});
test('removes a field from the template', async ({ page }) => {
await page.goto(`/game-systems/${gs.id}/edit`);
await expect(page.getByLabel(/^Nom/i)).toHaveValue(gs.name);
const pjEditor = tfe(page, 'PJ');
await pjEditor.locator('.tfe-add .chip', { hasText: 'Histoire' }).click();
await pjEditor.locator('.tfe-add .chip', { hasText: 'Apparence' }).click();
await expect(pjEditor.locator('.tfe-item')).toHaveCount(2);
// Supprime le premier champ (Histoire) via son btn-remove.
await pjEditor.locator('.tfe-item').first().locator('.btn-remove').click();
await expect(pjEditor.locator('.tfe-item')).toHaveCount(1);
await expect(pjEditor.locator('.tfe-item').first().locator('.tfe-name')).toHaveValue('Apparence');
});
test('reorders fields with the up arrow button', async ({ page }) => {
await page.goto(`/game-systems/${gs.id}/edit`);
await expect(page.getByLabel(/^Nom/i)).toHaveValue(gs.name);
const pjEditor = tfe(page, 'PJ');
await pjEditor.locator('.tfe-add .chip', { hasText: 'Histoire' }).click();
await pjEditor.locator('.tfe-add .chip', { hasText: 'Apparence' }).click();
// Ordre initial : Histoire, Apparence.
let rows = pjEditor.locator('.tfe-item');
await expect(rows.nth(0).locator('.tfe-name')).toHaveValue('Histoire');
await expect(rows.nth(1).locator('.tfe-name')).toHaveValue('Apparence');
// Monte Apparence d'un cran.
await rows.nth(1).locator('.btn-arrow').first().click();
rows = pjEditor.locator('.tfe-item');
await expect(rows.nth(0).locator('.tfe-name')).toHaveValue('Apparence');
await expect(rows.nth(1).locator('.tfe-name')).toHaveValue('Histoire');
});
test('disables a suggested chip after the field has been added', async ({ page }) => {
await page.goto(`/game-systems/${gs.id}/edit`);
await expect(page.getByLabel(/^Nom/i)).toHaveValue(gs.name);
const pjEditor = tfe(page, 'PJ');
const histoireChip = pjEditor.locator('.tfe-add .chip', { hasText: 'Histoire' });
await expect(histoireChip).toBeEnabled();
await histoireChip.click();
await expect(histoireChip).toBeDisabled();
});
});