Replace leaf entry with persistent horizontal toolbar and shared panel state
This commit is contained in:
1 parent
d2501d0112
commit
19361fd1cc
18 files changed
+1010
-454
No files matched your search
@@ -0,0 +1,16 @@
|
||||
"""Explicit application shutdown: closing the feature panel only hides it."""
|
||||
import pytest
|
||||
from PySide6.QtWidgets import QApplication
|
||||
|
||||
from dx_productivity.ui.main_window import MainWindow
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def shutdown_productivity_windows(qtbot):
|
||||
yield
|
||||
for window in QApplication.topLevelWidgets():
|
||||
if isinstance(window, MainWindow):
|
||||
startup = getattr(window, 'startup_controller', None)
|
||||
if startup is not None and startup.is_running():
|
||||
qtbot.waitUntil(lambda: not startup.is_running(), timeout=10000)
|
||||
window.request_exit()
|
||||
@@ -1,106 +1,145 @@
|
||||
from PySide6.QtCore import QCoreApplication, QEvent, QPoint, QPointF, QTimer, Qt
|
||||
from PySide6.QtGui import QMouseEvent
|
||||
from PySide6.QtWidgets import QAbstractButton
|
||||
|
||||
from dx_productivity.ui.app import FEATURE_PAGE_INDEX, create_main_window
|
||||
from dx_productivity.ui.floating_toolbar import PRIMARY_PAGES
|
||||
from dx_productivity.ui.pdf_export_page import PdfExportPage
|
||||
from dx_productivity.ui.settings_page import SettingsPage
|
||||
|
||||
|
||||
def make_window(qtbot, monkeypatch, tmp_path):
|
||||
monkeypatch.setenv("LOCALAPPDATA", str(tmp_path))
|
||||
monkeypatch.setenv('LOCALAPPDATA', str(tmp_path))
|
||||
window = create_main_window()
|
||||
qtbot.addWidget(window)
|
||||
window.show()
|
||||
qtbot.waitExposed(window)
|
||||
window.show_toolbar()
|
||||
return window
|
||||
|
||||
|
||||
def test_pdf_is_above_settings_with_matching_page_routing(qtbot, monkeypatch, tmp_path):
|
||||
def test_pdf_is_primary_before_settings_and_all_routes_are_accessible(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
assert window.navigation_items()[-2:] == ["PDF 导出", "设置"]
|
||||
for feature, page_type in (("pdf-export", PdfExportPage), ("settings", SettingsPage)):
|
||||
window.set_active_page(FEATURE_PAGE_INDEX[feature])
|
||||
assert isinstance(window.pages.currentWidget(), page_type)
|
||||
|
||||
|
||||
def test_all_pages_fit_compact_default_window(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
assert window.width() <= 1000
|
||||
assert window.height() <= 640
|
||||
assert tuple(window.toolbar.page_buttons) == PRIMARY_PAGES
|
||||
for index in range(window.pages.count()):
|
||||
window.set_active_page(index)
|
||||
qtbot.wait(5)
|
||||
assert window.width() <= 1000 and window.height() <= 640
|
||||
for button in (window.start_button, window.collapse_button, window.apply_button):
|
||||
assert window.rect().contains(button.mapTo(window, button.rect().bottomRight()))
|
||||
window.toolbar.page_requested.emit(index)
|
||||
assert window.isVisible() and window.pages.currentIndex() == index
|
||||
for feature, page_type in (('pdf-export', PdfExportPage), ('settings', SettingsPage)):
|
||||
window.show_panel(FEATURE_PAGE_INDEX[feature])
|
||||
assert isinstance(window.pages.currentWidget(), page_type)
|
||||
|
||||
|
||||
def test_floating_restore_retains_page_form_and_background_work(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
window.set_active_page(FEATURE_PAGE_INDEX["pdf-export"])
|
||||
window.show_panel(FEATURE_PAGE_INDEX['pdf-export'])
|
||||
page = window.pages.currentWidget()
|
||||
page.output_input.setText("pending-user-folder")
|
||||
page.output_input.setText('pending-user-folder')
|
||||
ticks = []
|
||||
timer = QTimer(window)
|
||||
timer.setInterval(10)
|
||||
timer.timeout.connect(lambda: ticks.append(1))
|
||||
timer.start()
|
||||
|
||||
qtbot.mouseClick(window.collapse_button, Qt.MouseButton.LeftButton)
|
||||
|
||||
assert not window.isVisible()
|
||||
assert window.floating_button.isVisible()
|
||||
assert window.floating_button.windowFlags() & Qt.WindowType.WindowStaysOnTopHint
|
||||
assert not window.isVisible() and window.toolbar.isVisible()
|
||||
assert window.toolbar.windowFlags() & Qt.WindowType.WindowStaysOnTopHint
|
||||
qtbot.waitUntil(lambda: len(ticks) >= 2)
|
||||
qtbot.mouseClick(window.floating_button, Qt.MouseButton.LeftButton)
|
||||
assert window.isVisible()
|
||||
assert not window.floating_button.isVisible()
|
||||
qtbot.mouseClick(window.toolbar.toggle_button, Qt.MouseButton.LeftButton)
|
||||
assert window.isVisible() and window.toolbar.isVisible()
|
||||
assert window.pages.currentWidget() is page
|
||||
assert page.output_input.text() == "pending-user-folder"
|
||||
assert page.output_input.text() == 'pending-user-folder'
|
||||
|
||||
|
||||
def test_minimum_size_keeps_all_page_action_buttons_accessible(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
window.resize(860, 540)
|
||||
for index in range(window.pages.count()):
|
||||
window.set_active_page(index)
|
||||
qtbot.wait(5)
|
||||
assert window.width() == 860 and window.height() == 540
|
||||
for button in window.findChildren(QAbstractButton):
|
||||
if button.isVisibleTo(window):
|
||||
assert window.rect().contains(button.mapTo(window, button.rect().bottomRight())), (index, button.text())
|
||||
|
||||
|
||||
def test_native_minimize_becomes_floating_and_can_repeat(qtbot, monkeypatch, tmp_path):
|
||||
def test_native_minimize_becomes_toolbar_and_can_repeat(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
window.show_panel(0)
|
||||
for _ in range(2):
|
||||
window.showMinimized()
|
||||
qtbot.waitUntil(lambda: window.floating_button.isVisible() and not window.isVisible())
|
||||
qtbot.mouseClick(window.floating_button, Qt.MouseButton.LeftButton)
|
||||
qtbot.waitUntil(lambda: window.toolbar.isVisible() and not window.isVisible())
|
||||
qtbot.mouseClick(window.toolbar.toggle_button, Qt.MouseButton.LeftButton)
|
||||
assert window.isVisible() and not window.isMinimized()
|
||||
|
||||
|
||||
def test_drag_moves_floating_entry_without_opening_main_window(qtbot, monkeypatch, tmp_path):
|
||||
def test_drag_only_handle_moves_toolbar_and_panel_without_switching(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
window.collapse_to_floating()
|
||||
floating = window.floating_button
|
||||
floating.move(40, 40)
|
||||
start = QPointF(floating.mapToGlobal(QPoint(20, 20)))
|
||||
window.show_panel(0)
|
||||
floating = window.toolbar
|
||||
floating.move_within_screen(QPoint(10, 40))
|
||||
panel_position = window.pos()
|
||||
handle = floating.drag_handle
|
||||
start = QPointF(handle.mapToGlobal(QPoint(10, 10)))
|
||||
for kind, local, global_pos, button, buttons in (
|
||||
(QEvent.Type.MouseButtonPress, QPointF(20, 20), start, Qt.MouseButton.LeftButton, Qt.MouseButton.LeftButton),
|
||||
(QEvent.Type.MouseMove, QPointF(60, 40), start + QPointF(40, 20), Qt.MouseButton.NoButton, Qt.MouseButton.LeftButton),
|
||||
(QEvent.Type.MouseButtonRelease, QPointF(20, 20), start + QPointF(40, 20), Qt.MouseButton.LeftButton, Qt.MouseButton.NoButton),
|
||||
(QEvent.Type.MouseButtonPress, QPointF(10, 10), start, Qt.MouseButton.LeftButton, Qt.MouseButton.LeftButton),
|
||||
(QEvent.Type.MouseMove, QPointF(20, 30), start + QPointF(10, 20), Qt.MouseButton.NoButton, Qt.MouseButton.LeftButton),
|
||||
(QEvent.Type.MouseButtonRelease, QPointF(10, 10), start + QPointF(10, 20), Qt.MouseButton.LeftButton, Qt.MouseButton.NoButton),
|
||||
):
|
||||
event = QMouseEvent(kind, local, global_pos, button, buttons, Qt.KeyboardModifier.NoModifier)
|
||||
QCoreApplication.sendEvent(floating, event)
|
||||
assert floating.pos() == QPoint(80, 60)
|
||||
assert not window.isVisible() and floating.isVisible()
|
||||
QCoreApplication.sendEvent(handle, event)
|
||||
assert floating.pos() == QPoint(20, 60)
|
||||
assert window.pos().y() == panel_position.y() + 20
|
||||
assert window.pages.currentIndex() == 0
|
||||
|
||||
|
||||
def test_close_while_collapsed_closes_floating_entry(qtbot, monkeypatch, tmp_path):
|
||||
def test_close_hides_but_explicit_exit_closes_toolbar_and_stops_timers(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
window.collapse_to_floating()
|
||||
timer = QTimer(window)
|
||||
timer.start(100)
|
||||
window.show_panel(0)
|
||||
window.close()
|
||||
assert not window.isVisible() and window.toolbar.isVisible() and timer.isActive()
|
||||
with qtbot.waitSignal(window.window_closed):
|
||||
window.close()
|
||||
assert not window.floating_button.isVisible()
|
||||
window.request_exit()
|
||||
assert not window.toolbar.isVisible() and not timer.isActive()
|
||||
|
||||
|
||||
def test_narrow_screen_keeps_priority_buttons_and_overflow_routes(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
toolbar = window.toolbar
|
||||
toolbar.fit_available_width(520)
|
||||
assert toolbar.width() <= 520
|
||||
assert toolbar.height() == 44
|
||||
for index in (0, 1, 7):
|
||||
assert toolbar.page_buttons[index].isVisible()
|
||||
for index in (2, 3, 4, 5):
|
||||
if not toolbar.page_buttons[index].isVisible():
|
||||
assert toolbar.page_actions[index].isVisible()
|
||||
toolbar.page_actions[index].trigger()
|
||||
assert window.pages.currentIndex() == index
|
||||
|
||||
|
||||
def test_page_size_and_toolbar_position_restore_without_overwriting_settings(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
window.show_panel(0)
|
||||
window.resize(750, 470)
|
||||
window.show_panel(7)
|
||||
window.resize(700, 410)
|
||||
window.show_panel(0)
|
||||
assert window.size().width() == 750 and window.size().height() == 470
|
||||
window.toolbar.move_within_screen(QPoint(20, 50))
|
||||
path = window.layout_preferences.path
|
||||
window.request_exit()
|
||||
from dx_productivity.ui.main_window import MainWindow
|
||||
restored = MainWindow(layout_path=path)
|
||||
qtbot.addWidget(restored)
|
||||
restored.show_panel(7)
|
||||
assert restored.size().width() == 700 and restored.size().height() == 410
|
||||
assert restored.toolbar.pos() == QPoint(20, 50)
|
||||
|
||||
|
||||
def test_menu_registration_blocks_exit_but_not_panel_hide(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
from types import SimpleNamespace
|
||||
window.startup_controller = SimpleNamespace(is_running=lambda: True)
|
||||
window.show_panel(0)
|
||||
window.close()
|
||||
assert not window.isVisible() and window.toolbar.isVisible()
|
||||
assert not window.request_exit()
|
||||
assert not window._closing
|
||||
window.startup_controller = None
|
||||
|
||||
|
||||
def test_saved_offscreen_position_and_bottom_anchor_are_clamped(qtbot, monkeypatch, tmp_path):
|
||||
window = make_window(qtbot, monkeypatch, tmp_path)
|
||||
screen = window.toolbar.screen()
|
||||
bounds = screen.availableGeometry()
|
||||
window.toolbar.move_within_screen(QPoint(99999, 99999), screen)
|
||||
assert bounds.contains(window.toolbar.frameGeometry())
|
||||
window.show_panel(0)
|
||||
assert bounds.contains(window.frameGeometry())
|
||||
assert window.frameGeometry().bottom() < window.toolbar.frameGeometry().top()
|
||||
@@ -0,0 +1,82 @@
|
||||
from PySide6.QtCore import Qt
|
||||
|
||||
from dx_productivity.ui.main_window import MainWindow
|
||||
|
||||
|
||||
def test_toolbar_routes_toggle_and_explicit_exit(qtbot, tmp_path, monkeypatch):
|
||||
monkeypatch.setenv('LOCALAPPDATA', str(tmp_path))
|
||||
window = MainWindow()
|
||||
qtbot.addWidget(window)
|
||||
window.show_toolbar()
|
||||
assert window.toolbar.isVisible() and not window.isVisible()
|
||||
assert window.toolbar.windowTitle() == '一叶知秋悬浮工具栏'
|
||||
for index, button in window.toolbar.page_buttons.items():
|
||||
qtbot.mouseClick(button, Qt.MouseButton.LeftButton)
|
||||
assert window.isVisible() and window.pages.currentIndex() == index
|
||||
assert button.isChecked()
|
||||
qtbot.mouseClick(button, Qt.MouseButton.LeftButton)
|
||||
assert not window.isVisible() and window.toolbar.isVisible()
|
||||
window.show_panel(0)
|
||||
window.close()
|
||||
assert not window.isVisible() and window.toolbar.isVisible()
|
||||
with qtbot.waitSignal(window.window_closed):
|
||||
assert window.request_exit()
|
||||
assert not window.toolbar.isVisible()
|
||||
|
||||
|
||||
def test_status_setters_update_hidden_toolbar_without_showing_panel(qtbot, tmp_path, monkeypatch):
|
||||
monkeypatch.setenv('LOCALAPPDATA', str(tmp_path))
|
||||
window = MainWindow()
|
||||
qtbot.addWidget(window)
|
||||
window.show_toolbar()
|
||||
window.set_project_status('design.prj', 'C:/design.prj')
|
||||
window.set_bridge_status('桥接已连接')
|
||||
window.set_selection_status('已选 C18', '当前页:ROOT / 1\n选中器件:C18')
|
||||
assert 'C18' in window.toolbar.status_label.text()
|
||||
assert 'ROOT / 1' in window.toolbar.status_label.toolTip()
|
||||
window.set_operation_status('PDF 导出中')
|
||||
assert 'PDF 导出中' in window.toolbar.status_label.text()
|
||||
assert 'C18' in window.toolbar.status_label.toolTip()
|
||||
assert not window.isVisible()
|
||||
|
||||
|
||||
def test_passive_status_keeps_host_focus_and_tracks_background_task(qtbot, qapp, tmp_path, monkeypatch):
|
||||
from types import SimpleNamespace
|
||||
from PySide6.QtWidgets import QWidget
|
||||
monkeypatch.setenv('LOCALAPPDATA', str(tmp_path))
|
||||
window = MainWindow()
|
||||
qtbot.addWidget(window)
|
||||
window.show_toolbar()
|
||||
host = QWidget()
|
||||
qtbot.addWidget(host)
|
||||
host.show()
|
||||
host.activateWindow()
|
||||
qapp.processEvents()
|
||||
active = qapp.activeWindow()
|
||||
window.set_bridge_status('桥接已连接')
|
||||
window.set_selection_status('已选 C1', '选中器件:C1')
|
||||
window.refdes_controller = SimpleNamespace(_apply_in_flight=True)
|
||||
window._sync_status()
|
||||
assert window.operation_status.text() == '位号应用中'
|
||||
assert '位号应用中' in window.toolbar.status_label.text()
|
||||
assert 'C1' in window.toolbar.status_label.toolTip()
|
||||
assert qapp.activeWindow() is active and not window.isVisible()
|
||||
window.refdes_controller._apply_in_flight = False
|
||||
window.set_operation_status('位号已应用')
|
||||
assert 'C1' in window.toolbar.status_label.text()
|
||||
window.set_bridge_status('桥接已断开')
|
||||
assert 'C1' not in window.toolbar.status_label.text()
|
||||
assert 'C1' not in window.selection_status.text()
|
||||
|
||||
|
||||
def test_toolbar_clamps_negative_monitor_coordinates(qtbot, tmp_path, monkeypatch):
|
||||
from PySide6.QtCore import QPoint, QRect
|
||||
from types import SimpleNamespace
|
||||
monkeypatch.setenv('LOCALAPPDATA', str(tmp_path))
|
||||
window = MainWindow()
|
||||
qtbot.addWidget(window)
|
||||
bounds = QRect(-1400, -100, 1400, 900)
|
||||
screen = SimpleNamespace(availableGeometry=lambda: bounds)
|
||||
window.toolbar.move_within_screen(QPoint(-1600, -300), screen)
|
||||
assert window.toolbar.pos() == bounds.topLeft()
|
||||
assert bounds.contains(window.toolbar.frameGeometry())
|
||||
@@ -107,7 +107,7 @@ def test_network_navigation_has_live_list_and_locator(qtbot, tmp_path, fixture_p
|
||||
window = create_main_window(request)
|
||||
qtbot.addWidget(window)
|
||||
|
||||
window.navigation.setCurrentRow(4)
|
||||
window.set_active_page(4)
|
||||
|
||||
page = window.pages.currentWidget()
|
||||
assert isinstance(page, InspectionPage)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import json
|
||||
|
||||
from PySide6.QtCore import QPoint, QSize
|
||||
from dx_productivity.ui.layout_preferences import LayoutPreferences
|
||||
|
||||
|
||||
def test_layout_preferences_validate_types_and_recover_from_corruption(tmp_path):
|
||||
path = tmp_path / 'ui-layout.json'
|
||||
path.write_text('{broken', encoding='utf-8')
|
||||
assert LayoutPreferences(path).position is None
|
||||
path.write_text(json.dumps({'toolbar_position': [True, 40], 'page_sizes': {'0': [720, '420'], '7': [660, 380], '999': [900, 600]}, 'screen': 123}), encoding='utf-8')
|
||||
preferences = LayoutPreferences(path)
|
||||
assert preferences.position is None
|
||||
assert preferences.screen_name == ''
|
||||
assert preferences.page_sizes == {7: QSize(660, 380)}
|
||||
|
||||
|
||||
def test_layout_preferences_round_trip_negative_monitor_position_and_atomic_write(tmp_path):
|
||||
path = tmp_path / 'DxProductivity' / 'ui-layout.json'
|
||||
settings = tmp_path / 'DxProductivity' / 'settings.json'
|
||||
settings.parent.mkdir()
|
||||
settings.write_text('{"channel":"stable"}', encoding='utf-8')
|
||||
preferences = LayoutPreferences(path)
|
||||
preferences.position = QPoint(-1200, 80)
|
||||
preferences.screen_name = 'Second monitor'
|
||||
preferences.page_sizes[0] = QSize(780, 490)
|
||||
preferences.save()
|
||||
fresh = LayoutPreferences(path)
|
||||
assert fresh.position == QPoint(-1200, 80)
|
||||
assert fresh.page_sizes[0] == QSize(780, 490)
|
||||
assert fresh.screen_name == 'Second monitor'
|
||||
assert settings.read_text(encoding='utf-8') == '{"channel":"stable"}'
|
||||
assert not tuple(path.parent.glob('*.tmp'))
|
||||
@@ -86,3 +86,57 @@ def test_selection_switches_current_sheet_without_overwriting_form(qtbot, fixtur
|
||||
window.selection_watcher._check()
|
||||
assert window.pdf_export_controller.snapshot.current_sheet_name == '2'
|
||||
assert not any(c.current_sheet for c in window.bom_controller.snapshot.components)
|
||||
|
||||
|
||||
def test_hidden_toolbar_selection_disconnect_recovery_and_project_switch(qtbot, fixture_path, tmp_path, monkeypatch):
|
||||
import os
|
||||
import time
|
||||
window, data = setup_window(qtbot, fixture_path, tmp_path, monkeypatch)
|
||||
window.show_toolbar()
|
||||
publish(tmp_path, data, ['uid:uid-c-a'])
|
||||
window.selection_watcher._check()
|
||||
assert 'C1' in window.toolbar.status_label.text()
|
||||
assert 'ROOT / 1' in window.toolbar.status_label.toolTip()
|
||||
width = window.toolbar.width()
|
||||
publish(tmp_path, data, ['uid:uid-r-a', 'uid:uid-c-a'])
|
||||
window.selection_watcher._check()
|
||||
assert '2 个' in window.toolbar.status_label.text()
|
||||
assert 'C1' in window.toolbar.status_label.toolTip()
|
||||
assert window.toolbar.width() == width
|
||||
publish(tmp_path, data, [])
|
||||
window.selection_watcher._check()
|
||||
assert '0' in window.toolbar.status_label.text()
|
||||
heartbeat = tmp_path / 'apply-progress.json'
|
||||
heartbeat.write_text('{}', encoding='utf-8')
|
||||
os.utime(heartbeat, (time.time() - 10, time.time() - 10))
|
||||
window.selection_watcher._check()
|
||||
assert '暂停' in window.toolbar.status_label.text()
|
||||
assert 'C1' not in window.toolbar.status_label.text()
|
||||
assert window.bridge_status.text() == '桥接已断开'
|
||||
heartbeat.unlink()
|
||||
publish(tmp_path, data, ['uid:uid-c-a'])
|
||||
window.selection_watcher._check()
|
||||
assert 'C1' in window.toolbar.status_label.text()
|
||||
publish(tmp_path, data, ['uid:uid-c-a'], design_path='C:/other.prj')
|
||||
window.selection_watcher._check()
|
||||
assert '切换' in window.toolbar.status_label.text()
|
||||
assert 'C1' not in window.toolbar.status_label.text()
|
||||
assert not window.isVisible()
|
||||
|
||||
|
||||
def test_repeated_panel_toggle_keeps_single_watcher_and_page_instances(qtbot, fixture_path, tmp_path, monkeypatch):
|
||||
from PySide6.QtCore import QTimer
|
||||
from dx_productivity.ui.selection_watcher import SelectionWatcher
|
||||
window, data = setup_window(qtbot, fixture_path, tmp_path, monkeypatch)
|
||||
pages = tuple(window.pages.widget(i) for i in range(window.pages.count()))
|
||||
timers = tuple(window.selection_watcher.findChildren(QTimer))
|
||||
for index in range(window.pages.count()):
|
||||
window.show_panel(index)
|
||||
window.hide_panel()
|
||||
publish(tmp_path, data, ['uid:uid-c-a'])
|
||||
window.selection_watcher._check()
|
||||
window.show_panel(1)
|
||||
assert tuple(window.pages.widget(i) for i in range(window.pages.count())) == pages
|
||||
assert tuple(window.selection_watcher.findChildren(QTimer)) == timers
|
||||
assert len(window.findChildren(SelectionWatcher)) == 1
|
||||
assert window.property_change_controller.page.model.item(0, 0).text() == 'C1'
|
||||
@@ -1,5 +1,5 @@
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QToolButton
|
||||
from PySide6.QtWidgets import QAbstractButton, QToolButton
|
||||
|
||||
from dx_productivity.ui.main_window import MainWindow
|
||||
from dx_productivity.ui.app import create_application, create_main_window
|
||||
@@ -12,17 +12,18 @@ def test_main_window_has_approved_minimum_and_navigation(qtbot):
|
||||
window = MainWindow()
|
||||
qtbot.addWidget(window)
|
||||
|
||||
assert window.minimumWidth() == 860
|
||||
assert window.minimumHeight() == 540
|
||||
assert window.minimumWidth() == 720
|
||||
assert window.minimumHeight() == 420
|
||||
assert window.navigation_items()[:3] == ["自动位号", "属性批改", "属性显示"]
|
||||
assert window.apply_button.text() == "应用位号"
|
||||
assert not hasattr(window, "navigation")
|
||||
assert window.toolbar.page_buttons[0].accessibleName() == "自动位号"
|
||||
|
||||
|
||||
def test_icon_buttons_have_accessible_names(qtbot):
|
||||
window = MainWindow()
|
||||
qtbot.addWidget(window)
|
||||
|
||||
for button in window.findChildren(QToolButton):
|
||||
for button in window.toolbar.findChildren(QAbstractButton):
|
||||
assert button.accessibleName()
|
||||
assert button.toolTip()
|
||||
|
||||
@@ -38,7 +39,7 @@ def test_theme_toggle_changes_window_theme(qtbot):
|
||||
window = MainWindow(theme=Theme.LIGHT)
|
||||
qtbot.addWidget(window)
|
||||
|
||||
qtbot.mouseClick(window.theme_button, Qt.MouseButton.LeftButton)
|
||||
window.theme_action.trigger()
|
||||
|
||||
assert window.theme is Theme.DARK
|
||||
|
||||
@@ -100,7 +101,7 @@ def test_main_window_uses_yiyezhqiu_brand_and_feature_pages(qtbot):
|
||||
qtbot.addWidget(window)
|
||||
|
||||
assert window.windowTitle() == "一叶知秋_重构版"
|
||||
assert window.brand_label.text() == "一叶知秋_重构版"
|
||||
assert window.toolbar.windowTitle() == "一叶知秋悬浮工具栏"
|
||||
assert isinstance(window.pages.widget(1), PropertyChangePage)
|
||||
assert isinstance(window.pages.widget(2), PropertyVisibilityPage)
|
||||
assert isinstance(window.pages.widget(3), InspectionPage)
|
||||
|
||||
@@ -109,3 +109,31 @@ def test_ui_update_starts_persistent_application_after_successful_smoke(qtbot, t
|
||||
("smoke", (executable, "ui", "--smoke-test-ms", "1000")),
|
||||
("launch", (executable, "ui")),
|
||||
]
|
||||
|
||||
|
||||
def test_update_handoff_exits_both_windows_and_shutdowns_controllers(qtbot, tmp_path, monkeypatch):
|
||||
from types import SimpleNamespace
|
||||
from PySide6.QtCore import QTimer
|
||||
window, controller, manifest, commands = _launch_fixture(qtbot, tmp_path, monkeypatch)
|
||||
current = _portable(tmp_path, 'portable-exit')
|
||||
monkeypatch.setattr(sys, 'executable', str(current / 'DxDesignerTools.exe'))
|
||||
shutdowns = []
|
||||
window.settings_controller = SimpleNamespace(shutdown=lambda: shutdowns.append('settings'))
|
||||
timer = QTimer(window)
|
||||
timer.start(100)
|
||||
window.show_panel(0)
|
||||
with qtbot.waitSignal(window.window_closed):
|
||||
app_module._launch_update(window, controller, manifest)
|
||||
assert commands and shutdowns == ['settings']
|
||||
assert window._closing and not window.isVisible() and not window.toolbar.isVisible()
|
||||
assert not timer.isActive()
|
||||
|
||||
|
||||
def test_update_does_not_spawn_updater_while_menu_registration_is_running(qtbot, tmp_path, monkeypatch):
|
||||
from types import SimpleNamespace
|
||||
window, controller, manifest, commands = _launch_fixture(qtbot, tmp_path, monkeypatch)
|
||||
window.startup_controller = SimpleNamespace(is_running=lambda: True)
|
||||
app_module._launch_update(window, controller, manifest)
|
||||
assert not commands and not window._closing
|
||||
assert '菜单注册' in window.operation_status.text()
|
||||
window.startup_controller = None
|
||||
Reference in new issue
Block a user