创建新工程

This commit is contained in:
moyin
2025-12-05 19:00:14 +08:00
commit ff4fa5fffd
227 changed files with 32804 additions and 0 deletions

View File

@@ -0,0 +1,107 @@
extends Node
## 错误提示显示属性测试
## Feature: godot-ai-town-game, Property 21: 错误提示显示
const TEST_ITERATIONS = 30
# 测试结果统计
var test_results = {
"passed": 0,
"failed": 0,
"errors": []
}
func _ready():
print("\n=== Property Test: Error Display ===")
await test_property_error_display()
print_results()
print("=== Property Test Completed ===\n")
## Feature: godot-ai-town-game, Property 21: 错误提示显示
func test_property_error_display():
"""
属性测试:错误提示显示
对于任意操作失败的情况,系统应该显示明确的错误提示信息,告知用户失败原因
验证需求: 10.5
"""
print("\n[Property Test] Testing error display...")
print("Running ", TEST_ITERATIONS, " iterations...")
# 测试不同类型的错误
var error_types = [
{"type": "network", "message": "网络连接失败"},
{"type": "operation", "message": "操作失败"},
{"type": "validation", "message": "输入验证失败"},
{"type": "timeout", "message": "请求超时"}
]
for i in range(TEST_ITERATIONS):
# 随机选择错误类型
var error_info = error_types[randi() % error_types.size()]
# 加载错误通知场景(而不是直接创建脚本)
var error_scene = load("res://scenes/ErrorNotification.tscn")
if not error_scene:
test_results["failed"] += 1
test_results["errors"].append({
"iteration": i + 1,
"error": "Failed to load ErrorNotification scene"
})
continue
var error_notification = error_scene.instantiate()
add_child(error_notification)
await get_tree().process_frame
# 显示错误
error_notification.show_error(error_info["message"], false, 0.0)
await get_tree().process_frame
# 验证错误是否正确显示
var is_visible = error_notification.visible
var has_message = error_notification.message_label != null
var message_correct = false
if has_message and error_notification.message_label:
message_correct = error_notification.message_label.text == error_info["message"]
if is_visible and has_message and message_correct:
test_results["passed"] += 1
else:
test_results["failed"] += 1
test_results["errors"].append({
"iteration": i + 1,
"error_type": error_info["type"],
"visible": is_visible,
"has_message": has_message,
"message_correct": message_correct,
"actual_text": error_notification.message_label.text if has_message else "N/A"
})
# 清理
error_notification.queue_free()
await get_tree().process_frame
func get_test_results() -> Dictionary:
"""返回测试结果供外部使用"""
return test_results
func print_results():
"""打印测试结果"""
print("\n=== Test Results ===")
print("Total iterations: ", TEST_ITERATIONS)
print("Passed: ", test_results["passed"])
print("Failed: ", test_results["failed"])
if test_results["failed"] > 0:
print("\n❌ FAILED: Some iterations failed")
print("First 5 errors:")
for i in range(min(5, test_results["errors"].size())):
var error = test_results["errors"][i]
print(" Error ", i + 1, ": ", error)
else:
print("\n✅ PASSED: All error displays work correctly")
print("Property 21 validated: Error messages are properly displayed to users")