Add simulated challenges to selected uncleared maps

This commit is contained in:
AttilaNet
2026-11-09 08:11:57 +08:00
parent df0259febf
commit f9631c3363
11 changed files with 628 additions and 47 deletions
+81 -1
View File
@@ -5,7 +5,7 @@ import unittest
from unittest.mock import patch
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
from PySide6 import QtWidgets as W
from PySide6 import QtCore as C, QtWidgets as W
from PySide6.QtTest import QTest
from ranch_assistant.engine import Engine
@@ -60,6 +60,86 @@ class MapCacheGuiTests(unittest.TestCase):
return
self.fail("Qt worker did not finish")
def test_map_request_error_keeps_read_only_background_reconciliation(self):
with workspace_temp() as folder:
window = Window(folder)
window.timer.stop()
try:
self.wait(lambda: not window.busy and window.engine.snapshot is not None)
catalog, snapshot = scenario()
client = FakeClient(snapshot)
client.session = Session("http://127.0.0.1/", "synthetic-test-token")
client.persist_session = lambda: None
client.close = lambda: None
window.engine = Engine(catalog, client, folder / "purchase.json")
window.engine.snapshot = snapshot
with patch.object(window.engine.battle_journal, "pending", return_value={"kind": "map_battle"}):
window.error("挑战结算回包尚未确认")
self.assertTrue(window.monitoring)
self.assertFalse(window.engine.auto)
self.assertFalse(window.strategy_toggle.isChecked())
with patch.object(window.engine, "pending_recovery_due", return_value=True), patch.object(window, "refresh") as refresh:
window.schedule()
refresh.assert_called_once_with(automated=True)
self.assertFalse(client.calls)
finally:
window.close()
def test_unlocked_uncleared_difficulty_and_cached_challenge_status(self):
with workspace_temp() as folder:
window = Window(folder)
window.timer.stop()
try:
self.wait(lambda: not window.busy and window.engine.snapshot is not None)
catalog, snapshot = scenario()
snapshot.raw["history"]["unlockStage"]["0102"] = ["1", "2"]
client = FakeClient(snapshot)
window.catalog = catalog
window.engine = Engine(catalog, client, folder / "purchase.json")
window.engine.snapshot = snapshot
window.map_rules = {"0102": {"enabled": False, "level": "1", "limit": 3}}
original = window.engine.stage_cache.get(snapshot)
statuses = {"bd00": "特殊关卡暂不支持自动挑战"}
def reason(current, stage, policy, *, team_ids=None):
self.assertIs(current, snapshot)
self.assertTrue(policy.allow_challenge)
self.assertEqual(team_ids, [900])
return statuses.get(stage.stage_id, "")
with patch.object(window.engine, "map_stage_reason", side_effect=reason) as cached_reason, \
patch.object(window.engine.sweeper, "reason", side_effect=AssertionError("UI used sweep-only reason")), \
patch.object(window.engine.battles, "inspect", side_effect=AssertionError("UI inspected runtime")), \
patch.object(window.engine.battles, "run", side_effect=AssertionError("UI ran a battle")), \
patch("ranch_assistant.stage_cache.stages", side_effect=AssertionError("UI rebuilt cached maps")):
window.tabs.setCurrentWidget(window.map_page)
self.wait(lambda: not window.map_render_timer.running)
self.assertEqual(window._map_items["0101"].text(5), "可扫荡")
item = window._map_items["0102"]
difficulty = window.maps_tree.itemWidget(item, 3)
self.assertTrue(difficulty.model().item(difficulty.findData("2")).isEnabled())
self.assertFalse(difficulty.model().item(difficulty.findData("3")).isEnabled())
self.assertNotIn("已通关", difficulty.itemText(difficulty.findData("2")))
item.setCheckState(0, C.Qt.CheckState.Checked)
difficulty.setCurrentIndex(difficulty.findData("2"))
self.app.processEvents()
self.wait(lambda: not window.map_render_timer.running)
self.assertEqual(window.map_rules["0102"], {"enabled": True, "level": "2", "limit": 3})
self.assertEqual(item.text(5), "将模拟挑战")
self.assertTrue(any(call.args[1].stage_id == "0102" and call.args[1].level == "2"
and call.args[2].rules["0102"]["enabled"] for call in cached_reason.call_args_list))
for status in ("打不过;调整战队或提升魔物属性后自动重试", "暂不支持的战斗机制:召唤"):
with self.subTest(status=status):
statuses["0102"] = status
window.render_maps()
self.wait(lambda: not window.map_render_timer.running)
self.assertEqual(item.text(5), status)
self.assertEqual(item.toolTip(5), status)
self.assertEqual(window._map_items["bd00"].text(5), statuses["bd00"])
self.assertIs(window.engine.stage_cache.rows, original)
self.assertEqual(client.calls, [])
finally:
window.engine.client = None
window.close()
def test_collapsed_maps_remain_cached_on_page_switch_and_poll_manual_refresh_updates(self):
with workspace_temp() as folder:
window = Window(folder)