Core regression / Python core, intervention UI and release configuration (push) Successful in 4m6s
Core regression / JavaScript syntax (push) Successful in 8s
Core regression / Python core, intervention UI and release configuration (pull_request) Successful in 4m2s
Core regression / JavaScript syntax (pull_request) Successful in 7s
243 lines
10 KiB
Python
243 lines
10 KiB
Python
"""Keyboard commands, screen-reader names and navigation selection agree with the UI."""
|
|
from PySide6.QtCore import Qt
|
|
from PySide6.QtGui import QAccessible
|
|
from PySide6.QtWidgets import QDialog, QHBoxLayout, QLabel, QLineEdit, QTableWidget, QTableWidgetItem, QToolButton, QWidget
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def navigation(qtbot):
|
|
from dx_productivity.trial_task_center.models import TaskRecord, TaskStatus
|
|
from dx_productivity.trial_task_center.ui.task_list import TaskList
|
|
panel = TaskList(lambda _: None)
|
|
qtbot.addWidget(panel)
|
|
now = datetime.now(timezone.utc)
|
|
tasks = tuple(TaskRecord(str(index), name, '', Path('F:/Projects'), TaskStatus.DRAFT,
|
|
now, now, group_id='batch', group_position=index) for index, name in enumerate(('Board-A', 'Board-B')))
|
|
panel.populate(tasks, selected_task_id='0')
|
|
panel.show()
|
|
return panel, tasks
|
|
|
|
|
|
def accessible_name(widget):
|
|
return QAccessible.queryAccessibleInterface(widget).text(QAccessible.Text.Name)
|
|
|
|
|
|
@pytest.fixture
|
|
def panels(qtbot):
|
|
from dx_productivity.trial_task_center.ui.task_list import TaskList
|
|
from dx_productivity.trial_task_center.ui.project_plan import ProjectPlanPanel
|
|
from dx_productivity.trial_task_center.ui.dsh_status import DshStatusIndicator
|
|
owner = QWidget()
|
|
qtbot.addWidget(owner)
|
|
owner.task_list = TaskList(lambda _: None)
|
|
owner.plan_panel = ProjectPlanPanel(owner)
|
|
owner.ai_status_indicator = DshStatusIndicator(owner)
|
|
layout = QHBoxLayout(owner)
|
|
layout.addWidget(owner.task_list)
|
|
layout.addWidget(owner.plan_panel)
|
|
from dx_productivity.trial_task_center.ui.accessibility import apply_accessible_names
|
|
apply_accessible_names(owner)
|
|
owner.show()
|
|
return owner
|
|
|
|
|
|
def test_task_sort_keeps_selected_rows_and_the_visible_count(navigation):
|
|
panel, tasks = navigation
|
|
panel.select_all_button.click()
|
|
selected = set(panel.selected_task_ids())
|
|
assert len(selected) == 2
|
|
panel.sort.setCurrentIndex(panel.sort.findData('name_desc'))
|
|
assert set(panel.selected_task_ids()) == selected
|
|
assert panel.count.text().endswith('已选 2')
|
|
panel.search.setText(tasks[0].name)
|
|
assert panel.selected_task_ids() == (tasks[0].task_id,)
|
|
assert panel.count.text().endswith('已选 1')
|
|
panel.clear_selection_button.click()
|
|
assert not panel.selected_task_ids()
|
|
assert '已选' not in panel.count.text()
|
|
panel.search.clear()
|
|
assert not panel.selected_task_ids()
|
|
assert '已选' not in panel.count.text()
|
|
|
|
|
|
def test_f2_edits_only_from_task_navigation_and_respects_button_gate(qtbot):
|
|
from dx_productivity.trial_task_center.ui.task_list import TaskList
|
|
owner = QWidget()
|
|
qtbot.addWidget(owner)
|
|
navigation = TaskList(lambda _: None)
|
|
table = QTableWidget(1, 1)
|
|
table.setItem(0, 0, QTableWidgetItem('OLD'))
|
|
layout = QHBoxLayout(owner)
|
|
layout.addWidget(navigation)
|
|
layout.addWidget(table)
|
|
owner.show()
|
|
owner.activateWindow()
|
|
qtbot.waitUntil(owner.isActiveWindow)
|
|
clicked = []
|
|
navigation.edit_button.clicked.connect(lambda: clicked.append(True))
|
|
navigation.search.setFocus()
|
|
qtbot.keyClick(navigation.search, Qt.Key.Key_F2)
|
|
assert clicked == [True]
|
|
navigation.edit_button.setEnabled(False)
|
|
qtbot.keyClick(navigation.search, Qt.Key.Key_F2)
|
|
assert clicked == [True]
|
|
navigation.edit_button.setEnabled(True)
|
|
table.setCurrentCell(0, 0)
|
|
table.setFocus()
|
|
qtbot.keyClick(table, Qt.Key.Key_F2)
|
|
assert table.findChild(QLineEdit) is not None
|
|
assert clicked == [True]
|
|
|
|
|
|
def test_core_inputs_and_sort_icon_have_user_facing_accessible_names(panels):
|
|
window = panels
|
|
assert accessible_name(window.task_list.search) == '搜索工程任务'
|
|
assert accessible_name(window.plan_panel.find_text) == '搜索位号计划'
|
|
assert accessible_name(window.plan_panel.bulk_part) == '批量目标料号'
|
|
assert accessible_name(window.findChild(QToolButton, 'taskSortMenu')) == '任务显示排序'
|
|
assert window.ai_status_indicator.accessibleName()
|
|
|
|
|
|
def test_inline_search_icons_describe_clear_and_find_next(panels):
|
|
panel = panels.plan_panel
|
|
panel.find_text.setText('R1')
|
|
buttons = panel.find_text.findChildren(QToolButton)
|
|
names = [accessible_name(button) for button in buttons]
|
|
assert '清除搜索位号计划' in names
|
|
assert '下一条匹配位号' in names
|
|
|
|
|
|
def test_f5_uses_refresh_button_gate_and_shortcut_help_is_discoverable(panels, qtbot):
|
|
from dx_productivity.trial_task_center.ui.run_panel import RunPanel
|
|
from dx_productivity.trial_task_center.ui.project_summary import ProjectSummary
|
|
from dx_productivity.trial_task_center.ui.shortcuts import install_window_shortcuts
|
|
panels.project_summary = ProjectSummary(panels)
|
|
panels.run_panel = RunPanel()
|
|
panels.layout().addWidget(panels.run_panel)
|
|
install_window_shortcuts(panels)
|
|
clicks = []
|
|
refresh = panels.project_summary.refresh_button
|
|
refresh.clicked.connect(lambda: clicks.append(True))
|
|
panels.activateWindow()
|
|
qtbot.waitUntil(panels.isActiveWindow)
|
|
panels.plan_panel.find_text.setFocus()
|
|
qtbot.keyClick(panels.plan_panel.find_text, Qt.Key.Key_F5)
|
|
assert clicks == [True]
|
|
refresh.setEnabled(False)
|
|
qtbot.keyClick(panels.plan_panel.find_text, Qt.Key.Key_F5)
|
|
assert clicks == [True]
|
|
refresh.setEnabled(True)
|
|
refresh.hide()
|
|
qtbot.keyClick(panels.plan_panel.find_text, Qt.Key.Key_F5)
|
|
assert clicks == [True]
|
|
panels.run_panel.more_menu.sync()
|
|
help_action = next(action for action in panels.run_panel.more_menu.actions() if '快捷键' in action.text())
|
|
assert help_action.isVisible() and help_action.isEnabled()
|
|
help_action.trigger()
|
|
dialog = panels.run_panel.findChild(QDialog, 'shortcutHelpDialog')
|
|
assert dialog is not None and dialog.isVisible()
|
|
text = '\n'.join(label.text() for label in dialog.findChildren(QLabel))
|
|
assert 'F2' in text and 'F5' in text and 'Ctrl+F' in text
|
|
assert '任务导航' in text and '位号计划' in text
|
|
dialog.close()
|
|
|
|
|
|
def test_task_menu_displays_f2_without_installing_a_second_shortcut(navigation):
|
|
from PySide6.QtGui import QAction
|
|
panel, _ = navigation
|
|
panel.manage_menu.sync()
|
|
assert any(action.text().endswith('\tF2') for action in panel.manage_menu.actions())
|
|
assert sum(action.shortcut().toString() == 'F2' for action in panel.findChildren(QAction)) == 1
|
|
|
|
|
|
def test_select_all_after_clear_selects_every_visible_task(navigation):
|
|
panel, _ = navigation
|
|
panel.clear_selection_button.click()
|
|
panel.select_all_button.click()
|
|
assert set(panel.selected_task_ids()) == {'0', '1'}
|
|
assert panel.count.text().endswith('已选 2')
|
|
|
|
|
|
def test_sort_keeps_visible_selection_when_current_task_is_filtered_out(navigation):
|
|
panel, _ = navigation
|
|
panel.select_all_button.click()
|
|
panel.search.setText('Board-B')
|
|
assert panel.current_task_id() is None
|
|
assert panel.selected_task_ids() == ('1',)
|
|
panel.sort.setCurrentIndex(panel.sort.findData('name_desc'))
|
|
assert panel.selected_task_ids() == ('1',)
|
|
assert panel.count.text().endswith('已选 1')
|
|
|
|
|
|
def test_ctrl_click_empty_selection_survives_sort_filter_and_refresh(navigation, qtbot):
|
|
panel, tasks = navigation
|
|
assert panel.current_task_id() == '0'
|
|
assert panel.selected_task_ids() == ('0',)
|
|
position = panel.list.visualItemRect(panel.list.currentItem()).center()
|
|
qtbot.mouseClick(panel.list.viewport(), Qt.MouseButton.LeftButton,
|
|
Qt.KeyboardModifier.ControlModifier, position)
|
|
assert panel.current_task_id() == '0'
|
|
assert panel.selected_task_ids() == ()
|
|
panel.sort.setCurrentIndex(panel.sort.findData('name_desc'))
|
|
assert panel.selected_task_ids() == ()
|
|
assert '已选' not in panel.count.text()
|
|
panel.search.setText('Board-B')
|
|
panel.populate(tasks, selected_task_id='0')
|
|
panel.search.clear()
|
|
assert panel.current_task_id() == '0'
|
|
assert panel.selected_task_ids() == ()
|
|
assert '已选' not in panel.count.text()
|
|
panel.select_task('1')
|
|
assert panel.selected_task_ids() == ('1',)
|
|
|
|
|
|
def test_dialog_form_labels_are_effective_names_and_dynamic_ai_name_survives(panels, qtbot):
|
|
from dx_productivity.trial_task_center.ui.accessibility import apply_accessible_names
|
|
from dx_productivity.trial_task_center.ui.dialogs import _MappingDialog
|
|
dialog = _MappingDialog(panels)
|
|
qtbot.addWidget(dialog)
|
|
apply_accessible_names(dialog)
|
|
assert accessible_name(dialog.old_edit) == '旧物料编码'
|
|
assert accessible_name(dialog.new_edit) == '新物料编码'
|
|
assert accessible_name(dialog.custom_value_edit) == 'Value 内容'
|
|
panels.ai_status_indicator.set_state('working', '执行中', '正在运行')
|
|
apply_accessible_names(panels)
|
|
assert accessible_name(panels.ai_status_indicator) == 'AI 自动介入:执行中'
|
|
|
|
|
|
def test_window_shortcuts_use_live_task_gates_and_keep_project_bindings(ui, qtbot):
|
|
from threading import Event
|
|
from PySide6.QtGui import QAction
|
|
window = ui.window
|
|
assert accessible_name(window.plan_panel.bulk_part) == '批量目标料号'
|
|
shortcuts = [action.shortcut().toString() for action in window.findChildren(QAction)]
|
|
assert shortcuts.count('Ctrl+Shift+D') == 1
|
|
assert shortcuts.count('F5') == 1
|
|
refresh = window.project_summary.refresh_button
|
|
clicked = []
|
|
refresh.clicked.connect(lambda: clicked.append(True))
|
|
window.activateWindow()
|
|
qtbot.waitUntil(window.isActiveWindow)
|
|
window.plan_panel.find_text.setFocus()
|
|
qtbot.keyClick(window.plan_panel.find_text, Qt.Key.Key_F5)
|
|
ui.settle()
|
|
assert clicked == [True]
|
|
release_worker = Event()
|
|
window._run_async(lambda: release_worker.wait(5), lambda _: None)
|
|
try:
|
|
assert not refresh.isEnabled()
|
|
qtbot.keyClick(window.plan_panel.find_text, Qt.Key.Key_F5)
|
|
assert clicked == [True]
|
|
finally:
|
|
release_worker.set()
|
|
ui.settle()
|
|
window.task_list.clear_selection_button.click()
|
|
ui.settle()
|
|
assert not refresh.isEnabled()
|
|
qtbot.keyClick(window.task_list.search, Qt.Key.Key_F5)
|
|
assert clicked == [True]
|
|
assert all(project.selected for task in ui.tasks for project in ui.store.list_projects(task.task_id))
|