diff --git a/tests/test_handlers.py b/tests/test_handlers.py index 87a8de8..d34f824 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -119,6 +119,37 @@ class TestSwipeHandler: assert int(getattr(a, "room_pos", 0) or 0) == 5 assert bool(getattr(a, "_record_title_before_swipe_up", False)) is False + def test_reset_to_top_keep_mapping_does_not_clear_map(self): + """回顶后应保留运行时映射表。""" + from douyin.handlers.douyin_swipe_handler import SwipeHandler + + class _A: + pass + + a = _A() + a._resetting_after_swipes = False + a.room_pos = 3 + a._swipe_times = 9 + a._just_switched_room = False + a._room_pos_to_title_map = { + 0: {"title": "A", "title_raw": "A"}, + 1: {"title": "B", "title_raw": "B"}, + 2: {"title": "C", "title_raw": "C"}, + } + a._log_kv = MagicMock(return_value=None) + a.operation = MagicMock() + a.operation.delay = MagicMock(return_value=None) + + with patch("douyin.handlers.douyin_swipe_ops.swipe_down_back_live") as mock_down: + ok = SwipeHandler.reset_to_top_keep_mapping(a, reason="ut", min_back_times=1) + + assert ok is True + assert mock_down.call_count >= 1 + assert int(getattr(a, "room_pos", -1)) == 0 + assert isinstance(a._room_pos_to_title_map, dict) + assert len(a._room_pos_to_title_map) == 3 + assert 0 in a._room_pos_to_title_map and 2 in a._room_pos_to_title_map + class TestSwipeOps: """douyin_swipe_ops 模块测试。"""