116 lines
4.7 KiB
Python
116 lines
4.7 KiB
Python
from pathlib import Path
|
|
from threading import Event
|
|
|
|
from PySide6.QtCore import QPoint, Qt
|
|
from PySide6.QtTest import QTest
|
|
from PySide6.QtWidgets import QCheckBox, QToolButton
|
|
|
|
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
|
from dx_productivity.trial_task_center.service import TaskCenterService
|
|
from dx_productivity.trial_task_center.store import TaskStore
|
|
from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow, _MappingDialog
|
|
|
|
|
|
def make_window(qtbot, tmp_path):
|
|
service = TaskCenterService(TaskStore(tmp_path / 'tasks.db'), configure_logging(tmp_path / 'data'))
|
|
first = service.create_task('First')
|
|
second = service.create_task('Second')
|
|
window = TrialTaskCenterWindow(service)
|
|
qtbot.addWidget(window)
|
|
window.show()
|
|
window.open_task(first.task_id)
|
|
return window, service, first, second
|
|
|
|
|
|
def test_value_checkbox_is_task_scoped_and_defaults_off(qtbot, tmp_path):
|
|
window, service, first, second = make_window(qtbot, tmp_path)
|
|
checkbox = window.findChild(QCheckBox, 'copyPartNumberToValue')
|
|
assert checkbox is not None
|
|
assert checkbox.text() == '替换后将 Part Label 写入 Value'
|
|
assert not checkbox.isChecked()
|
|
assert checkbox.isEnabled()
|
|
QTest.mouseClick(checkbox, Qt.MouseButton.LeftButton, pos=QPoint(8, checkbox.height() // 2))
|
|
qtbot.waitUntil(lambda: service.get_task(first.task_id).copy_part_number_to_value)
|
|
qtbot.waitUntil(lambda: not window._workers)
|
|
window.open_task(second.task_id)
|
|
assert not checkbox.isChecked()
|
|
window.open_task(first.task_id)
|
|
assert checkbox.isChecked()
|
|
|
|
|
|
def test_mapping_dialog_exposes_custom_value_and_nc_controls(qtbot):
|
|
dialog = _MappingDialog(None, "OLD", "NEW", True, True, "22uF", False)
|
|
qtbot.addWidget(dialog)
|
|
assert dialog.custom_value_check.isChecked()
|
|
assert dialog.custom_value_edit.isEnabled()
|
|
assert dialog.custom_value_edit.text() == "22uF"
|
|
assert not dialog.sync_nc_check.isChecked()
|
|
assert dialog.values() == ("OLD", "NEW", True, True, "22uF", False)
|
|
|
|
|
|
def test_small_window_has_useful_drag_range_and_collapsible_log(qtbot, tmp_path):
|
|
window, _, _, _ = make_window(qtbot, tmp_path)
|
|
window.resize(900, 600)
|
|
qtbot.wait(20)
|
|
splitter = window.detail_splitter
|
|
lower, upper = splitter.getRange(1)
|
|
assert upper - lower >= 90
|
|
splitter.setSizes((230, 140, 190))
|
|
before = splitter.sizes()[0]
|
|
handle = splitter.handle(1)
|
|
center = handle.rect().center()
|
|
QTest.mousePress(handle, Qt.MouseButton.LeftButton, pos=center)
|
|
QTest.mouseMove(handle, center + QPoint(0, 60), delay=20)
|
|
QTest.mouseRelease(handle, Qt.MouseButton.LeftButton, pos=center + QPoint(0, 60))
|
|
assert splitter.sizes()[0] - before >= 40
|
|
toggle = window.findChild(QToolButton, 'toggleLogButton')
|
|
assert toggle is not None and not window.run_panel.log_view.isVisible()
|
|
QTest.mouseClick(toggle, Qt.MouseButton.LeftButton)
|
|
assert window.run_panel.log_view.isVisible()
|
|
|
|
|
|
def test_splitter_remains_draggable_while_background_work_is_running(qtbot, tmp_path):
|
|
window, service, _, _ = make_window(qtbot, tmp_path)
|
|
started = Event()
|
|
release = Event()
|
|
|
|
def work():
|
|
started.set()
|
|
release.wait(3)
|
|
return None
|
|
|
|
window._run_async(work, lambda _result: None, window.run_panel.quick_run_button)
|
|
qtbot.waitUntil(started.is_set, timeout=1000)
|
|
splitter = window.detail_splitter
|
|
splitter.setSizes((230, 140, 190))
|
|
before = splitter.sizes()[0]
|
|
handle = splitter.handle(1)
|
|
center = handle.rect().center()
|
|
QTest.mousePress(handle, Qt.MouseButton.LeftButton, pos=center)
|
|
QTest.mouseMove(handle, center + QPoint(0, 60), delay=20)
|
|
QTest.mouseRelease(handle, Qt.MouseButton.LeftButton, pos=center + QPoint(0, 60))
|
|
|
|
assert splitter.sizes()[0] - before >= 40
|
|
release.set()
|
|
qtbot.waitUntil(lambda: not window._workers, timeout=3000)
|
|
window.close()
|
|
service._store.close()
|
|
|
|
|
|
def test_layout_and_column_width_survive_window_recreation(qtbot, tmp_path):
|
|
window, service, _, _ = make_window(qtbot, tmp_path)
|
|
window.workspace_splitter.setSizes((320, 740))
|
|
window.detail_splitter.setSizes((380, 190, 160))
|
|
window.project_table.horizontalHeader().resizeSection(2, 240)
|
|
qtbot.wait(20)
|
|
expected = window.detail_splitter.sizes()
|
|
window.close()
|
|
recreated = TrialTaskCenterWindow(service)
|
|
qtbot.addWidget(recreated)
|
|
recreated.show()
|
|
qtbot.wait(20)
|
|
assert abs(recreated.detail_splitter.sizes()[0] - expected[0]) <= 3
|
|
assert recreated.project_table.columnWidth(2) == 240
|
|
assert Path(service.layout_settings_path).is_relative_to(tmp_path)
|
|
assert recreated.findChild(QToolButton, 'resetLayoutButton') is not None
|