"""Liste "🧩 Collision" à jour en AJAX (voir routes/scenes/ scene_collision_rule_objects.py, refreshCollisionRuleObjects() dans static/js/scenes/scene-editor.js) : appelée après ajout/suppression d'un objet de scène ou changement de rôle/nom, pour ne jamais recharger la page alors que cette liste doit refléter le changement (un objet apparaît/ disparaît selon son rôle, ou change de libellé affiché).""" import screens def _create_jeu2d_game(client, tmp_game_slug_cleanup, name="pytest_collision_ajax"): resp = client.post("/games/new", data={"name": name}, follow_redirects=False) slug = tmp_game_slug_cleanup(resp.headers["Location"].rstrip("/").split("/")[-1]) screen_id = screens.create_screen(slug, "Scène 1", kind="jeu_2d") return slug, screen_id def _add_ajax(client, slug, screen_id, **data): return client.post( f"/game/{slug}/screens/{screen_id}/scene-objects/add", data=data, headers={"X-Requested-With": "fetch"}, ).get_json() def _list(client, slug, screen_id): resp = client.get(f"/game/{slug}/screens/{screen_id}/collision-rule-objects") assert resp.status_code == 200 return resp.get_json() def test_freshly_added_personnage_is_pnj_in_the_list(client, tmp_game_slug_cleanup): slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup) obj_id = _add_ajax(client, slug, screen_id, kind="personnage")["id"] entries = _list(client, slug, screen_id) assert len(entries) == 1 assert entries[0]["id"] == obj_id assert entries[0]["role"] == "pnj" def test_role_change_to_joueur_removes_it_from_the_list(client, tmp_game_slug_cleanup): slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup) obj_id = _add_ajax(client, slug, screen_id, kind="personnage")["id"] client.post(f"/game/{slug}/scene-objects/{obj_id}/role", data='{"role": "joueur"}', content_type="application/json") assert _list(client, slug, screen_id) == [] def test_role_change_back_to_pnj_readds_it_to_the_list(client, tmp_game_slug_cleanup): slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup) obj_id = _add_ajax(client, slug, screen_id, kind="personnage")["id"] client.post(f"/game/{slug}/scene-objects/{obj_id}/role", data='{"role": "joueur"}', content_type="application/json") client.post(f"/game/{slug}/scene-objects/{obj_id}/role", data='{"role": "ennemie"}', content_type="application/json") entries = _list(client, slug, screen_id) assert len(entries) == 1 assert entries[0]["role"] == "ennemie" def test_name_change_is_reflected_in_the_list(client, tmp_game_slug_cleanup): slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup) obj_id = _add_ajax(client, slug, screen_id, kind="personnage")["id"] client.post(f"/game/{slug}/scene-objects/{obj_id}/name", data='{"name": "Le Sorcier"}', content_type="application/json") entries = _list(client, slug, screen_id) assert entries[0]["name"] == "Le Sorcier" def test_deleted_object_is_removed_from_the_list(client, tmp_game_slug_cleanup): slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup) obj_id = _add_ajax(client, slug, screen_id, kind="personnage")["id"] client.post(f"/game/{slug}/scene-objects/{obj_id}/delete", headers={"X-Requested-With": "fetch"}) assert _list(client, slug, screen_id) == [] def test_decor_has_no_role(client, tmp_game_slug_cleanup): slug, screen_id = _create_jeu2d_game(client, tmp_game_slug_cleanup) _add_ajax(client, slug, screen_id, kind="decor") entries = _list(client, slug, screen_id) assert entries[0]["role"] is None