Files
aetherbound-guild/runtime/tests/foundation/market_page_controller_test.gd
T

82 lines
3.9 KiB
GDScript

extends SceneTree
const Controller = preload("res://entry/market_page_controller.gd")
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
var controller := Controller.new()
var company := _fixture_company()
var content := controller._content({})
var snapshot: Dictionary = controller.snapshot(company, "recruit", "recruit", "r-001", "zh_CN", content)
expect(snapshot.ok and snapshot.page_id == "market", "snapshot identifies the Market page")
expect(snapshot.category == "recruit" and snapshot.selected_kind == "recruit", "snapshot preserves category and selection kind")
expect(snapshot.selected_offer.source_offer_id == "r-001", "snapshot resolves a stable Recruit offer ID")
expect(snapshot.company.owned_count == 2 and snapshot.company.coin == 38, "snapshot exposes copied Company and Coin facts")
expect(snapshot.categories.size() == 3 and snapshot.categories[1].available_count == 2, "snapshot exposes all Market categories and available counts")
expect(snapshot.review.action == "recruit_review" and snapshot.review.available, "Recruit selection exposes its review boundary")
expect(snapshot.commands.return_contract.enabled and snapshot.commands.return_contract.reason == "ready", "Market exposes an enabled Contract Return command before formation")
var selected: Dictionary = controller.select_offer(company, "equipment", "e-001")
expect(selected.ok and selected.review.action == "equipment_review", "Equipment selection exposes its review boundary")
var route: Dictionary = controller.select_offer(company, "battle", "b-001")
expect(route.ok and not route.review.available and route.review.reason == "battle_inspect_only", "Battle route remains inspect-only")
var missing: Dictionary = controller.select_offer(company, "recruit", "missing")
expect(not missing.ok and missing.code == "MARKET_OFFER_UNAVAILABLE", "unknown offer is rejected without fallback")
var copied: Dictionary = snapshot.offers.recruit[0]
copied.display_name_tokens[0] = "changed"
expect(company.active_contract.market_board.recruit_offers[0].display_name_tokens[0] == "name.ari", "view data is isolated from Company input")
var locked := company.duplicate(true)
locked.active_contract.formation = {"status": "draft"}
var locked_snapshot: Dictionary = controller.snapshot(locked, "recruit", "", "", "zh_CN", content)
expect(not locked_snapshot.commands.return_contract.enabled and locked_snapshot.commands.return_contract.reason == "formation_locked", "Market disables Contract Return when Formation exists")
if failures.is_empty():
print("ABG_M17_MARKET_CONTROLLER_OK snapshot=true categories=3 selection=true missing=true review=recruit,equipment,battle_inspect_only copies=true")
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func _fixture_company() -> Dictionary:
return {
"company_id": "company-001",
"owned_recruits": [{"recruit_id": "owned-001"}, {"recruit_id": "owned-002"}],
"active_contract": {
"status": "market",
"contract_id": "CTR-R1-01",
"run_id": "run-001",
"market_index": 1,
"coin": 38,
"line_capacity": 4,
"market_board": {
"board_hash": "board-001",
"recruit_offers": [{
"source_offer_id": "r-001",
"display_name_tokens": ["name.ari"],
"profession_id": "PF-B01",
"trait_id": "TR-001",
"list_price": 14,
"attribute_rolls": {"vigor": 3, "force": 2, "finesse": 1, "resolve": 2, "focus": 1},
}],
"equipment_offers": [{"offer_id": "e-001", "catalog_id": "EQ-002", "list_price": 12}, {"offer_id": "e-002", "catalog_id": "EQ-012", "list_price": 16}],
"battle_offers": [{"offer_id": "b-001", "risk": 0, "wave_count": 2, "enemy_ids": ["EN-001"]}],
},
"available_recruit_offer_ids": ["r-001"],
"available_equipment_offer_ids": ["e-001", "e-002"],
"available_battle_offer_ids": ["b-001"],
},
}
func expect(condition: bool, message: String) -> void:
if not condition:
failures.append("M17 Market Controller: %s" % message)