|
|
@@ -1,6 +1,7 @@
|
|
|
"""Replay battle return transitions without a running game or screenshot fixtures."""
|
|
|
from copy import deepcopy
|
|
|
from types import SimpleNamespace
|
|
|
+from unittest.mock import patch
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
@@ -28,7 +29,6 @@ class AreaNavigationReplay(ScriptTask):
|
|
|
self.config = SimpleNamespace(area_boss=SimpleNamespace(
|
|
|
boss=SimpleNamespace(reward_floor=AreaBossFloor.DEFAULT)))
|
|
|
self.device = SimpleNamespace(image=frozenset(), click=self.record_click)
|
|
|
- self.open_boss_detail = lambda *args: True
|
|
|
self.start_fight = lambda: win
|
|
|
for name in (
|
|
|
'I_AB_CLOSE_RED', 'I_FIRE', 'I_FILTER', 'I_AB_FILTER_OPENED',
|
|
|
@@ -39,6 +39,10 @@ class AreaNavigationReplay(ScriptTask):
|
|
|
setattr(self, name, asset)
|
|
|
monkeypatch.setattr(timer, 'time', SimpleNamespace(time=lambda: self.now))
|
|
|
|
|
|
+ def finish_first_battle(self):
|
|
|
+ with patch.object(self, 'open_boss_detail', return_value=True):
|
|
|
+ return self.boss_fight(self.I_BATTLE_1, fileter_open=False)
|
|
|
+
|
|
|
def screenshot(self):
|
|
|
self.frames += 1
|
|
|
assert self.frames <= 200, 'Navigation did not finish or respect its timeout'
|
|
|
@@ -52,6 +56,7 @@ class AreaNavigationReplay(ScriptTask):
|
|
|
'map': {'I_FILTER', 'I_UI_BACK_YELLOW'},
|
|
|
'detail': {'I_AB_CLOSE_RED', 'I_FIRE'},
|
|
|
'detail_loading': {'I_AB_CLOSE_RED'},
|
|
|
+ 'detail_with_filter': {'I_AB_CLOSE_RED', 'I_AB_FILTER_OPENED'},
|
|
|
'filter': {'I_AB_FILTER_OPENED'},
|
|
|
'main': {'I_CHECK_MAIN'},
|
|
|
'unknown': set(),
|
|
|
@@ -63,9 +68,12 @@ class AreaNavigationReplay(ScriptTask):
|
|
|
def record_click(self, x, y, control_name):
|
|
|
self.clicks.append((control_name, self.now))
|
|
|
if control_name == self.I_AB_CLOSE_RED.name:
|
|
|
- assert self.screen == 'detail'
|
|
|
+ assert self.screen in ('detail', 'detail_with_filter')
|
|
|
if self.ignored_closes:
|
|
|
self.ignored_closes -= 1
|
|
|
+ elif self.screen == 'detail_with_filter':
|
|
|
+ # The first tap outside the list can dismiss just the list.
|
|
|
+ self.screen = 'detail'
|
|
|
elif self.close_delay:
|
|
|
self.screen = 'unknown'
|
|
|
self.transitions[self.frames + self.close_delay] = 'map'
|
|
|
@@ -79,6 +87,11 @@ class AreaNavigationReplay(ScriptTask):
|
|
|
assert self.screen == 'map', 'Clicked back behind the boss detail'
|
|
|
if not self.rebound:
|
|
|
self.screen = 'main'
|
|
|
+ elif control_name == self.I_BATTLE_2.name:
|
|
|
+ assert self.screen == 'filter', 'Selected a boss while the previous detail was open'
|
|
|
+ # The list can still be folding away as the selected detail appears.
|
|
|
+ self.screen = 'detail_with_filter'
|
|
|
+ self.transitions[self.frames + 3] = 'detail'
|
|
|
else:
|
|
|
pytest.fail(f'Unexpected click: {control_name}')
|
|
|
|
|
|
@@ -97,18 +110,58 @@ def test_battle_return_recovers_detail_reappearing_after_map(
|
|
|
task = AreaNavigationReplay(monkeypatch, rebound=True, win=win,
|
|
|
ignored_closes=3, background_visible=True)
|
|
|
|
|
|
- assert task.boss_fight(task.I_BATTLE_1, fileter_open=False) is win
|
|
|
+ assert task.finish_first_battle() is win
|
|
|
+ assert task.clicked_names == [task.I_AB_CLOSE_RED.name] * 4
|
|
|
getattr(task, navigate)()
|
|
|
|
|
|
assert task.screen == destination
|
|
|
button = getattr(task, navigation_asset).name
|
|
|
- # Stay over the detail long enough for the background button's cooldown
|
|
|
- # to expire, so a failed close attempt cannot fall through to that button.
|
|
|
- assert task.clicked_names == [button] + [task.I_AB_CLOSE_RED.name] * 4 + [button]
|
|
|
+ assert task.clicked_names == [task.I_AB_CLOSE_RED.name] * 4 + [button]
|
|
|
close_times = [at for name, at in task.clicks if name == task.I_AB_CLOSE_RED.name]
|
|
|
assert all(later - earlier >= 1 for earlier, later in zip(close_times, close_times[1:]))
|
|
|
|
|
|
|
|
|
+def test_battle_return_closes_detail_under_filter_before_selecting_second_boss(monkeypatch):
|
|
|
+ task = AreaNavigationReplay(monkeypatch, screen='map', transitions={3: 'detail_with_filter'})
|
|
|
+ close = task.I_AB_CLOSE_RED.name
|
|
|
+
|
|
|
+ assert task.finish_first_battle()
|
|
|
+ assert task.screen == 'map'
|
|
|
+ assert task.clicked_names == [close, close]
|
|
|
+
|
|
|
+ assert task.boss_fight(task.I_BATTLE_2)
|
|
|
+ assert task.clicked_names == [close, close, task.I_FILTER.name, task.I_BATTLE_2.name, close]
|
|
|
+
|
|
|
+
|
|
|
+def test_second_boss_selection_recovers_filter_already_over_detail(monkeypatch):
|
|
|
+ task = AreaNavigationReplay(monkeypatch, screen='detail_with_filter')
|
|
|
+ task.screenshot()
|
|
|
+
|
|
|
+ assert task.boss_fight(task.I_BATTLE_2)
|
|
|
+
|
|
|
+ close = task.I_AB_CLOSE_RED.name
|
|
|
+ assert task.clicked_names == [close, close, task.I_FILTER.name, task.I_BATTLE_2.name, close]
|
|
|
+
|
|
|
+
|
|
|
+def test_reward_boss_fights_already_selected_detail(monkeypatch):
|
|
|
+ task = AreaNavigationReplay(monkeypatch, screen='detail')
|
|
|
+
|
|
|
+ assert task.boss_fight(task.C_AB_BOSS_REWARD_PHOTO_1, fileter_open=False)
|
|
|
+ assert task.clicked_names == [task.I_AB_CLOSE_RED.name]
|
|
|
+
|
|
|
+
|
|
|
+def test_unavailable_boss_retries_only_on_clear_list(monkeypatch):
|
|
|
+ task = AreaNavigationReplay(monkeypatch, screen='filter')
|
|
|
+ def ignore_selection(x, y, control_name):
|
|
|
+ assert task.screen == 'filter'
|
|
|
+ task.clicks.append((control_name, task.now))
|
|
|
+ task.device.click = ignore_selection
|
|
|
+
|
|
|
+ assert not task.boss_fight(task.I_BATTLE_2)
|
|
|
+ assert task.clicked_names == [task.I_BATTLE_2.name] * 3
|
|
|
+ assert all(later - earlier >= 3 for (_, earlier), (_, later) in zip(task.clicks, task.clicks[1:]))
|
|
|
+
|
|
|
+
|
|
|
@pytest.mark.parametrize('navigate, destination', [
|
|
|
('open_filter', 'filter'), ('go_back', 'main'),
|
|
|
])
|
|
|
@@ -117,7 +170,7 @@ def test_battle_return_still_accepts_direct_map_and_normal_detail(
|
|
|
monkeypatch, navigate, destination, screen):
|
|
|
task = AreaNavigationReplay(monkeypatch, screen=screen)
|
|
|
|
|
|
- assert task.boss_fight(task.I_BATTLE_1, fileter_open=False) is True
|
|
|
+ assert task.finish_first_battle() is True
|
|
|
getattr(task, navigate)()
|
|
|
|
|
|
assert task.screen == destination
|
|
|
@@ -155,7 +208,7 @@ def test_battle_return_waits_through_unknown_frames(monkeypatch, screen, win):
|
|
|
task = AreaNavigationReplay(monkeypatch, screen='unknown', win=win,
|
|
|
transitions={3: screen})
|
|
|
|
|
|
- assert task.boss_fight(task.I_BATTLE_1, fileter_open=False) is win
|
|
|
+ assert task.finish_first_battle() is win
|
|
|
|
|
|
assert task.screen == screen
|
|
|
assert task.clicks == []
|
|
|
@@ -164,7 +217,7 @@ def test_battle_return_waits_through_unknown_frames(monkeypatch, screen, win):
|
|
|
def test_battle_return_waits_for_map_after_detail_close_animation(monkeypatch):
|
|
|
task = AreaNavigationReplay(monkeypatch, screen='detail', close_delay=3)
|
|
|
|
|
|
- assert task.boss_fight(task.I_BATTLE_1, fileter_open=False) is True
|
|
|
+ assert task.finish_first_battle() is True
|
|
|
|
|
|
assert task.screen == 'map'
|
|
|
assert task.clicked_names == [task.I_AB_CLOSE_RED.name]
|
|
|
@@ -175,7 +228,7 @@ def test_battle_return_times_out_without_a_confirmed_page(monkeypatch, screen):
|
|
|
task = AreaNavigationReplay(monkeypatch, screen=screen, ignored_closes=100)
|
|
|
|
|
|
with pytest.raises(GameStuckError):
|
|
|
- task.boss_fight(task.I_BATTLE_1, fileter_open=False)
|
|
|
+ task.finish_first_battle()
|
|
|
|
|
|
assert task.now <= 125
|
|
|
assert task.screen == screen
|
|
|
@@ -191,7 +244,7 @@ def test_detail_loading_blocks_background_controls_until_ready(
|
|
|
transitions={5: 'detail'}, background_visible=True)
|
|
|
|
|
|
if navigate == 'boss_fight':
|
|
|
- assert task.boss_fight(task.I_BATTLE_1, fileter_open=False) is True
|
|
|
+ assert task.finish_first_battle() is True
|
|
|
else:
|
|
|
getattr(task, navigate)()
|
|
|
|