Files
Forge-Engine/tests/test_animations.py
T
williamandClaude Sonnet 5 5d6747770c Auto-héberge les polices Google Fonts et animate.css (fin des CDN)
Étape 1 de la fonctionnalité "Publier un jeu en exécutable autonome" :
un jeu exporté devra fonctionner sans AUCUNE connexion internet, ce qui
suppose d'abord que l'app elle-même n'ait plus aucune dépendance CDN —
Bulma l'était déjà (refonte design system), il ne restait que Google
Fonts et animate.css, chargés par templates/play.html ET
templates/screen_edit.html (aperçu du canevas dans l'éditeur).

GOOGLE_FONTS_LINK (screens/widgets/font_options.py) était une constante
FIXE (4 polices, 2 graisses chacune, jamais dépendante du jeu en cours) :
téléchargées une fois pour toutes (45 fichiers woff2, ~1.1 Mo au total
avec la couverture cyrillique/vietnamienne incluse) dans
static/vendor/fonts/, avec un fonts.css régénéré à partir du CSS
officiel de Google Fonts mais pointant vers les fichiers locaux. Même
chose pour animate.min.css 4.1.1 (static/vendor/animate.min.css).

routes/play/game_play.py et routes/screens/screen_edit.py ne passent
plus google_fonts_link aux templates (devenu inutile, les deux pages
chargent directement les fichiers locaux) ; GOOGLE_FONTS_LINK est retiré
de screens/widgets/font_options.py et screens/__init__.py (plus aucun
appelant).

tests/test_animations.py : les deux tests qui vérifiaient la présence
du lien CDN vérifient maintenant la présence du fichier local
(animate.min.css) — renommés en conséquence.

199 tests toujours verts. Reste à faire pour la fonctionnalité complète :
empaquetage Python portable + serveur minimal + bouton "Publier".

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-29 09:29:51 +02:00

116 lines
4.7 KiB
Python

"""Tests de la timeline d'animation : clips Animate.css ou personnalisés
(images-clés), posés sur la piste d'un élément, avec un instant de départ
et une durée sur l'axe du temps (secondes depuis l'affichage de l'écran)."""
import json
import re
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_element(client, slug, screen_id, widget):
resp = client.post(f"/game/{slug}/screens/{screen_id}/elements/add", data={"widget": widget}, follow_redirects=False)
return int(re.search(r"selected=(\d+)", resp.headers["Location"]).group(1))
def test_animate_css_clip_persists(client, game):
screen_id = _create_screen(client, game)
el_id = _add_element(client, game, screen_id, "titre")
resp = client.post(
f"/game/{game}/screens/{screen_id}/animations/clips/add",
data=json.dumps({
"element_id": el_id, "kind": "animate_css", "animate_name": "bounce",
"start_time": "1.5", "duration": "2", "delay": "0", "easing": "ease", "iteration_count": "1",
}),
content_type="application/json",
)
assert resp.status_code == 200
clip = resp.get_json()
assert clip["kind"] == "animate_css"
assert clip["animate_name"] == "bounce"
assert clip["start_time"] == 1.5
assert clip["duration"] == 2.0
assert clip["element_id"] == el_id
def test_custom_keyframes_clip_persists(client, game):
screen_id = _create_screen(client, game)
el_id = _add_element(client, game, screen_id, "conteneur")
keyframes = [{"percent": 0, "props": {"opacity": "0"}}, {"percent": 100, "props": {"opacity": "1"}}]
resp = client.post(
f"/game/{game}/screens/{screen_id}/animations/clips/add",
data=json.dumps({
"element_id": el_id, "kind": "custom", "custom_keyframes": keyframes,
"start_time": "0", "duration": "3",
}),
content_type="application/json",
)
assert resp.status_code == 200
clip = resp.get_json()
assert clip["kind"] == "custom"
assert json.loads(clip["custom_keyframes"]) == keyframes
def test_clip_update_changes_timing(client, game):
screen_id = _create_screen(client, game)
el_id = _add_element(client, game, screen_id, "bouton")
clip = client.post(
f"/game/{game}/screens/{screen_id}/animations/clips/add",
data=json.dumps({"element_id": el_id, "kind": "animate_css", "animate_name": "fadeIn"}),
content_type="application/json",
).get_json()
resp = client.post(
f"/game/{game}/animations/clips/{clip['id']}/update",
data=json.dumps({"start_time": "4", "duration": "0.5"}),
content_type="application/json",
)
assert resp.status_code == 200
updated = resp.get_json()
assert updated["start_time"] == 4.0
assert updated["duration"] == 0.5
def test_clip_delete_removes_it(client, game):
screen_id = _create_screen(client, game)
el_id = _add_element(client, game, screen_id, "bouton")
clip = client.post(
f"/game/{game}/screens/{screen_id}/animations/clips/add",
data=json.dumps({"element_id": el_id, "kind": "animate_css", "animate_name": "tada"}),
content_type="application/json",
).get_json()
resp = client.post(f"/game/{game}/animations/clips/{clip['id']}/delete")
assert resp.status_code == 200
html = client.get(f"/game/{game}/screens/{screen_id}/edit").data.decode()
assert f'"id": {clip["id"]}' not in html
def test_screen_edit_exposes_timeline_panel_and_animate_css(client, game):
screen_id = _create_screen(client, game)
html = client.get(f"/game/{game}/screens/{screen_id}/edit").data.decode()
assert "animTabPanel" in html
assert "Timeline d'animation" in html
assert "animate.min.css" in html
def test_play_page_exposes_animation_runtime_and_animate_css(client, game):
resp = client.get(f"/game/{game}/play")
html = resp.data.decode()
assert "animate.min.css" in html
assert "runAnimationTimeline" in html
assert "injectCustomKeyframes" in html
def test_play_page_payload_includes_clip(client, game):
screen_id = _create_screen(client, game)
el_id = _add_element(client, game, screen_id, "titre")
client.post(
f"/game/{game}/screens/{screen_id}/animations/clips/add",
data=json.dumps({"element_id": el_id, "kind": "animate_css", "animate_name": "pulse", "start_time": "2"}),
content_type="application/json",
)
html = client.get(f"/game/{game}/play").data.decode()
assert '"animate_name": "pulse"' in html
assert '"start_time": 2.0' in html