T-585 Chrome 路径自动检测
This commit is contained in:
@@ -889,6 +889,11 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
)
|
||||
self.assertEqual("选择...", tab.chrome_path_browse_button.text())
|
||||
self.assertEqual("chromePathBrowseButton", tab.chrome_path_browse_button.objectName())
|
||||
self.assertEqual("自动检测", tab.chrome_path_detect_button.text())
|
||||
self.assertEqual(
|
||||
"chromePathAutoDetectButton",
|
||||
tab.chrome_path_detect_button.objectName(),
|
||||
)
|
||||
self.assertIs(
|
||||
tab.chrome_path_widget.layout().itemAt(0).widget(),
|
||||
tab.chrome_path_edit,
|
||||
@@ -897,6 +902,10 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
tab.chrome_path_widget.layout().itemAt(1).widget(),
|
||||
tab.chrome_path_browse_button,
|
||||
)
|
||||
self.assertIs(
|
||||
tab.chrome_path_widget.layout().itemAt(2).widget(),
|
||||
tab.chrome_path_detect_button,
|
||||
)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
@@ -942,6 +951,53 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_settings_tab_auto_detects_chrome_without_saving(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
statuses = []
|
||||
tab = SettingsTab(config=cfg, status_callback=statuses.append)
|
||||
self.addCleanup(tab.close)
|
||||
detected = os.path.join(temp_dir, "Chrome", "chrome.exe")
|
||||
|
||||
with mock.patch(
|
||||
"app.gui.tabs.settings.chrome.detect_chrome_path",
|
||||
return_value=detected,
|
||||
):
|
||||
tab.chrome_path_detect_button.click()
|
||||
|
||||
self.assertEqual(detected, tab.chrome_path_edit.text())
|
||||
self.assertTrue(tab.is_dirty())
|
||||
self.assertFalse(os.path.exists(cfg["config_path"]))
|
||||
self.assertIn("已自动定位 Chrome", statuses[-1])
|
||||
|
||||
tab._set_dirty(False)
|
||||
previous = tab.chrome_path_edit.text()
|
||||
with mock.patch(
|
||||
"app.gui.tabs.settings.chrome.detect_chrome_path",
|
||||
return_value="",
|
||||
):
|
||||
tab.chrome_path_detect_button.click()
|
||||
|
||||
self.assertEqual(previous, tab.chrome_path_edit.text())
|
||||
self.assertFalse(tab.is_dirty())
|
||||
self.assertIn("未找到 Chrome", statuses[-1])
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_main_window_keeps_startup_chrome_detection_status(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
message = "已自动定位 Chrome:C:\\Chrome\\chrome.exe"
|
||||
window = MainWindow(
|
||||
config=self.make_config(temp_dir),
|
||||
startup_status=message,
|
||||
)
|
||||
self.addCleanup(window.close)
|
||||
|
||||
self.assertEqual(message, window.statusBar().currentMessage())
|
||||
self.assertIn(gui.COLOR_SUCCESS, window.statusBar().styleSheet())
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_settings_tab_adds_saves_and_deletes_model(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
|
||||
Reference in New Issue
Block a user