Use main-window menus, cache maps, and handle settled sweep events
This commit is contained in:
@@ -117,6 +117,82 @@ class AccountGuiTests(unittest.TestCase):
|
||||
window.result("connected", (client, Snapshot(role_snapshot(window.catalog, role_id))))
|
||||
return client
|
||||
|
||||
def test_main_menu_routes_strategy_actions_to_selected_account_and_saves_immediately(self):
|
||||
with workspace_temp() as folder:
|
||||
hub = AccountsWindow(folder)
|
||||
hub.add_profile()
|
||||
windows = list(hub.windows.values())
|
||||
for window in windows:
|
||||
window.timer.stop()
|
||||
try:
|
||||
self.wait(windows)
|
||||
first, second = windows
|
||||
first.keep_money.setValue(1234)
|
||||
second.keep_money.setValue(5678)
|
||||
for window in windows:
|
||||
window.auto_save_timer.stop()
|
||||
for selected, other, expected in ((first, second, 1234), (second, first, 5678)):
|
||||
hub.tabs.setCurrentWidget(selected)
|
||||
with patch.object(selected, "import_policies") as imported, patch.object(other, "import_policies") as other_imported:
|
||||
hub.import_policy_action.trigger()
|
||||
imported.assert_called_once_with()
|
||||
other_imported.assert_not_called()
|
||||
with patch.object(selected, "export_policies") as exported, patch.object(other, "export_policies") as other_exported:
|
||||
hub.export_policy_action.trigger()
|
||||
exported.assert_called_once_with()
|
||||
other_exported.assert_not_called()
|
||||
with patch.object(other, "persist_settings") as other_saved:
|
||||
hub.save_policy_action.trigger()
|
||||
other_saved.assert_not_called()
|
||||
saved = json.loads((selected.state / "settings.json").read_text(encoding="utf-8"))
|
||||
self.assertEqual(saved["policy"]["keep_money"], expected)
|
||||
self.assertEqual(selected.engine.policy.keep_money, expected)
|
||||
self.assertFalse(selected.execute.isChecked())
|
||||
finally:
|
||||
hub.close()
|
||||
|
||||
def test_only_main_window_has_menus_and_about_shows_versions(self):
|
||||
with workspace_temp() as folder:
|
||||
hub = AccountsWindow(folder)
|
||||
windows = list(hub.windows.values())
|
||||
for window in windows:
|
||||
window.timer.stop()
|
||||
try:
|
||||
self.wait(windows)
|
||||
self.assertEqual([action.text().split("(")[0] for action in hub.menuBar().actions()],
|
||||
["账号", "监控", "策略配置", "帮助"])
|
||||
for window in windows:
|
||||
self.assertIsNone(window.findChild(W.QMenuBar))
|
||||
labels = {button.text() for button in hub.findChildren(W.QPushButton)}
|
||||
for label in ("新增账号页签", "打开已保存账号", "恢复各页签的保存会话", "全部开始监控", "全部停止"):
|
||||
self.assertNotIn(label, labels)
|
||||
with patch.object(W.QMessageBox, "about") as about:
|
||||
hub.about_action.trigger()
|
||||
self.assertIn(gui.APP_VERSION, about.call_args.args[2])
|
||||
self.assertIn(gui.GAME_VERSION, about.call_args.args[2])
|
||||
finally:
|
||||
hub.close()
|
||||
|
||||
def test_strategy_menu_disables_when_no_account_is_open(self):
|
||||
with workspace_temp() as folder:
|
||||
hub = AccountsWindow(folder)
|
||||
windows = list(hub.windows.values())
|
||||
for window in windows:
|
||||
window.timer.stop()
|
||||
try:
|
||||
self.wait(windows)
|
||||
hub.close_profile(0)
|
||||
self.assertEqual(hub.tabs.count(), 0)
|
||||
self.assertTrue(all(not action.isEnabled() for action in hub.policy_actions))
|
||||
hub.add_profile()
|
||||
windows = list(hub.windows.values())
|
||||
for window in windows:
|
||||
window.timer.stop()
|
||||
self.wait(windows)
|
||||
self.assertTrue(all(action.isEnabled() for action in hub.policy_actions))
|
||||
finally:
|
||||
hub.close()
|
||||
|
||||
def test_closed_fresh_tab_does_not_start_queued_refresh_and_can_reopen(self):
|
||||
with workspace_temp() as folder:
|
||||
hub = AccountsWindow(folder)
|
||||
|
||||
Reference in New Issue
Block a user