Le document de cadrage produit cible des formateurs non techniques créant des serious games/quiz gamifiés — l'éditeur générique "document" (blocs de logique en nœuds, timeline d'animation, définitions d'objets/relations, templates réutilisables) est une complexité hors cible que l'effort d'ingénierie récent avait déjà abandonnée au profit du jeu_2d. - Onboarding : ne garde que le parcours "RPG" (jeu_2d), retire Quiz/Embranchement/Créer mon jeu de A à Z (tous document-only) - Suppression en bloc des modules exclusifs au document : routes/elements, routes/element_types, routes/objects, routes/legacy_actions, screens/elements, screens/element_types, screens/widgets, screens/legacy_actions, le rendu render_element_html.py et son cluster, templates/screen_edit.html, templates/game_dashboard.html, flow-editor.js/tabs-and-blocks.js/animation-timeline.js - Dashboard toujours simplifié (un seul mode possible désormais) - Tests document-only supprimés, tests de logique partagée (flow, événements personnalisés, animations) retargetés sur des écrans jeu_2d - Aucune régression jeu_2d : 299 tests passent Carte d'onboarding retravaillée : argumentaire RH non technique (liste à coche, badge "Compatible LMS"), taille et interaction de retournement ajustées.
90 lines
3.5 KiB
Python
90 lines
3.5 KiB
Python
"""Tests de l'action "Ajouter une ligne" (ajouter_ligne, Phase 4) : crée
|
|
une ligne VIDE, dont l'id devient LAST_INSERTED_ROW_ID pour un nœud
|
|
"Modifier une donnée" enchaîné dans le MÊME flow — verrouille le
|
|
mécanisme complet (route -> DB -> répéteur) plutôt que juste la fonction
|
|
Python isolée."""
|
|
import json
|
|
import re
|
|
|
|
import db
|
|
import screens
|
|
|
|
|
|
def _create_screen(client, slug, name="Accueil"):
|
|
resp = client.post(f"/game/{slug}/screens/new", data={"name": name}, follow_redirects=False)
|
|
return int(re.search(r"/screens/(\d+)/edit", resp.headers["Location"]).group(1))
|
|
|
|
|
|
def _add_flow_node(client, slug, screen_id, **fields):
|
|
resp = client.post(
|
|
f"/game/{slug}/screens/{screen_id}/flow/nodes/add",
|
|
data=json.dumps(fields),
|
|
content_type="application/json",
|
|
)
|
|
assert resp.status_code == 200
|
|
return resp.get_json()["id"]
|
|
|
|
|
|
def _create_inventory_object(client, slug):
|
|
return db.create_definition(slug, "Inventaire", [{"name": "objet", "type": "texte"}])
|
|
|
|
|
|
def test_run_add_row_route_creates_an_empty_row(client, game):
|
|
definition_id = _create_inventory_object(client, game)
|
|
screen_id = _create_screen(client, game)
|
|
node_id = _add_flow_node(
|
|
client, game, screen_id, node_type="action", action_type="ajouter_ligne", target_definition_id=definition_id,
|
|
)
|
|
resp = client.post(f"/game/{game}/flow/nodes/{node_id}/run-add-row")
|
|
assert resp.status_code == 200
|
|
body = resp.get_json()
|
|
assert body["ok"] is True
|
|
assert isinstance(body["row_id"], int)
|
|
|
|
definition = db.get_definition(game, definition_id)
|
|
rows = db.list_rows(game, definition)
|
|
assert len(rows) == 1
|
|
assert rows[0]["id"] == body["row_id"]
|
|
assert rows[0]["objet"] is None
|
|
|
|
|
|
def test_run_add_row_route_rejects_wrong_action_type(client, game):
|
|
screen_id = _create_screen(client, game)
|
|
node_id = _add_flow_node(client, game, screen_id, node_type="action", action_type="attendre", data_value="1")
|
|
resp = client.post(f"/game/{game}/flow/nodes/{node_id}/run-add-row")
|
|
assert resp.status_code == 400
|
|
assert resp.get_json()["ok"] is False
|
|
|
|
|
|
def test_chained_ajouter_ligne_then_modifier_donnee_sets_the_new_row_fields(client, game):
|
|
"""Le scénario réel : "Ajouter une ligne" crée une ligne vide, puis un
|
|
"Modifier une donnée" ciblant LAST_INSERTED_ROW_ID (transmis par le
|
|
client via last_inserted_row_id, voir static/js/play/actions.js) la
|
|
renseigne — exactement comme CLICKED_ROW_ID pour une ligne cliquée."""
|
|
definition_id = _create_inventory_object(client, game)
|
|
screen_id = _create_screen(client, game)
|
|
add_node_id = _add_flow_node(
|
|
client, game, screen_id, node_type="action", action_type="ajouter_ligne", target_definition_id=definition_id,
|
|
)
|
|
set_node_id = _add_flow_node(
|
|
client, game, screen_id, node_type="action", action_type="modifier_donnee",
|
|
target_definition_id=definition_id, target_row_id=screens.LAST_INSERTED_ROW_ID,
|
|
target_field="objet", data_operation="definir_texte", data_value="épée",
|
|
)
|
|
|
|
add_resp = client.post(f"/game/{game}/flow/nodes/{add_node_id}/run-add-row")
|
|
new_row_id = add_resp.get_json()["row_id"]
|
|
|
|
set_resp = client.post(
|
|
f"/game/{game}/flow/nodes/{set_node_id}/run-data",
|
|
data=json.dumps({"last_inserted_row_id": new_row_id}),
|
|
content_type="application/json",
|
|
)
|
|
assert set_resp.get_json()["ok"] is True
|
|
|
|
definition = db.get_definition(game, definition_id)
|
|
row = db.get_row(game, definition, new_row_id)
|
|
assert row["objet"] == "épée"
|
|
|
|
|