fix: remediate issue 45 validation and UI state protection
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

This commit is contained in:
阿白叔 committed 2026-11-30 17:11:51 +08:00
1 parent 8395d7cff2
commit 65f3a9c728
24 files changed
+1258 -54

No files matched your search

+242
View File
@@ -0,0 +1,242 @@
"""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))
+258
View File
@@ -0,0 +1,258 @@
"""Task navigation makes an explicit decision for every unsaved plan."""
from dataclasses import replace
from threading import Event
import pytest
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QLineEdit
from dx_productivity.trial_task_center.target_plan import ComponentTarget, TargetPlanRow
def seed(ui):
task = ui.tasks[0]
project = ui.store.list_projects(task.task_id)[0].path
rows = tuple(TargetPlanRow(ComponentTarget(project, 'MAIN', '1', f'nav-{i}',
f'R{i+1}', 'OLD', '100nF'), False, 'NEW') for i in range(5))
ui.store.record_target_inventory(task.task_id, tuple(row.target for row in rows))
ui.service.replace_target_plan(task.task_id, rows)
rows = ui.service.target_plan(task.task_id)
ui.open(task); ui.settle()
ui.window.mapping_tabs.setCurrentIndex(1)
return ui.window.plan_panel, rows
def edit_cell(panel, text='TYPED'):
index = panel.table.model().index(0, 6)
panel.table.setCurrentIndex(index)
panel.table.setFocus()
panel.table.edit(index)
editor = panel.table.findChild(QLineEdit)
assert editor is not None
editor.setText(text)
assert panel.table.has_pending_editor()
return editor
def test_cancel_task_switch_keeps_five_enabled_rows_and_list_focus(ui):
panel, _ = seed(ui)
panel.table.select_all_targets(True)
choices = []
ui.window._close_plan_confirmer = lambda: choices.append('asked') or 'cancel'
ui.window.task_list.list.setCurrentRow(1)
ui.settle()
assert choices == ['asked']
assert ui.window._task_id == ui.tasks[0].task_id
assert ui.window.task_list.current_task_id() == ui.tasks[0].task_id
assert all(row.enabled for row in panel.table.rows())
assert panel.has_unsaved_plans()
def test_same_task_refresh_preserves_uncommitted_text_without_prompt(ui):
panel, _ = seed(ui)
edit_cell(panel)
ui.window._close_plan_confirmer = lambda: pytest.fail('metadata refresh is not navigation')
ui.open(ui.tasks[0]); ui.settle()
assert panel.table.dirty
assert panel.table.rows()[0].new_part_number == 'TYPED'
ui.window._close_plan_confirmer = lambda: 'cancel'
def test_discard_restores_persisted_rows_before_later_save(ui):
panel, original = seed(ui)
panel.table.select_all_targets(True)
panel.discard_all()
assert panel.table.rows() == original
assert not panel.has_unsaved_plans()
panel.table.model().setData(panel.table.model().index(0, 6), 'LATER')
panel.save(); ui.settle()
assert not any(row.enabled for row in ui.service.target_plan(ui.tasks[0].task_id))
def test_save_switch_waits_for_atomic_save_including_active_editor(ui, qtbot, monkeypatch):
panel, _ = seed(ui)
edit_cell(panel)
started, release = Event(), Event()
original = ui.service.save_plan_drafts
def save(batches, standalone):
started.set()
assert release.wait(5)
return original(batches, standalone)
monkeypatch.setattr(ui.service, 'save_plan_drafts', save)
ui.window._close_plan_confirmer = lambda: 'save'
try:
ui.window.open_task(ui.tasks[1].task_id)
qtbot.waitUntil(started.is_set, timeout=2000)
assert ui.window._task_id == ui.tasks[0].task_id
assert panel.has_unsaved_plans()
finally:
release.set()
ui.settle()
assert ui.window._task_id == ui.tasks[1].task_id
assert ui.service.target_plan(ui.tasks[0].task_id)[0].new_part_number == 'TYPED'
assert not panel.has_unsaved_plans()
@pytest.mark.parametrize('choice', ['cancel', 'discard'])
def test_task_switch_with_active_editor_has_explicit_choice(ui, choice):
panel, original = seed(ui)
edit_cell(panel)
choices = []
ui.window._close_plan_confirmer = lambda: choices.append('asked') or choice
ui.window.open_task(ui.tasks[1].task_id)
ui.settle()
assert choices == ['asked']
assert ui.window._task_id == ui.tasks[0 if choice == 'cancel' else 1].task_id
assert ui.service.target_plan(ui.tasks[0].task_id) == original
if choice == 'cancel':
assert panel.has_unsaved_plans()
assert panel.table.has_pending_editor() or panel.table.rows()[0].new_part_number == 'TYPED'
else:
assert not panel.has_unsaved_plans()
ui.open(ui.tasks[0]); ui.settle()
assert panel.table.rows() == original
def test_failed_save_switch_preserves_current_editor_hidden_drafts_and_batches(ui, monkeypatch):
from dx_productivity.trial_task_center.bom_batch import BomBatchPreview, BomProjectPreview
panel, _ = seed(ui)
edit_cell(panel)
hidden = ui.tasks[1].task_id
panel._drafts[hidden] = ()
project = ui.store.list_projects(hidden)[0].path
batch = BomBatchPreview(hidden, ((hidden, str(project)),),
(BomProjectPreview(hidden, project, (), (), ()),))
panel._bom_batches[(hidden,)] = batch
calls = []
def fail(batches, standalone):
calls.append((batches, standalone))
raise RuntimeError('controlled save failure')
monkeypatch.setattr(ui.service, 'save_plan_drafts', fail)
ui.window._close_plan_confirmer = lambda: 'save'
ui.window.open_task(hidden)
ui.settle()
assert len(calls) == 1
assert calls[0][0][0][0] == batch
assert calls[0][1][ui.tasks[0].task_id][0].new_part_number == 'TYPED'
assert ui.window._task_id == ui.tasks[0].task_id
assert ui.window.task_list.current_task_id() == ui.tasks[0].task_id
assert hidden in panel._drafts
assert panel._bom_batches[(hidden,)] == batch
assert panel.table.rows()[0].new_part_number == 'TYPED'
assert panel.table.dirty
assert not ui.calls
ui.window._close_plan_confirmer = lambda: 'cancel'
def test_hidden_draft_alone_requires_choice_and_discard_releases_all(ui):
panel, _ = seed(ui)
panel._drafts[ui.tasks[1].task_id] = ()
choices = []
ui.window._close_plan_confirmer = lambda: choices.append('asked') or 'discard'
ui.open(ui.tasks[1]); ui.settle()
assert choices == ['asked']
assert not panel.has_unsaved_plans()
def test_save_switch_includes_hidden_draft(ui, monkeypatch):
panel, rows = seed(ui)
hidden = ui.tasks[1].task_id
project = ui.store.list_projects(hidden)[0].path
hidden_rows = tuple(replace(row, target=replace(row.target, project_path=project)) for row in rows)
ui.store.record_target_inventory(hidden, tuple(row.target for row in hidden_rows))
ui.service.replace_target_plan(hidden, hidden_rows)
panel._drafts[hidden] = (replace(hidden_rows[0], new_part_number='HIDDEN'),) + hidden_rows[1:]
original = ui.service.save_plan_drafts
received = []
def save(batches, standalone):
received.append(set(standalone))
return original(batches, standalone)
monkeypatch.setattr(ui.service, 'save_plan_drafts', save)
ui.window._close_plan_confirmer = lambda: 'save'
ui.window.open_task(hidden)
ui.settle()
assert received == [{hidden}]
assert ui.window._task_id == hidden
assert ui.service.target_plan(hidden)[0].new_part_number == 'HIDDEN'
assert not panel.has_unsaved_plans()
def test_newly_created_task_uses_the_same_unsaved_navigation_decision(ui):
panel, _ = seed(ui)
panel.table.select_all_targets(True)
choices = []
ui.window._close_plan_confirmer = lambda: choices.append('asked') or 'cancel'
task = ui.service.create_task('New empty task')
ui.window._project_tasks_created((task,))
ui.settle()
assert choices == ['asked']
assert ui.window._task_id == ui.tasks[0].task_id
assert panel.table.dirty
def test_close_save_commits_active_editor_before_exiting(ui, qtbot):
panel, _ = seed(ui)
edit_cell(panel)
ui.window.archive_on_close_check.setChecked(False)
ui.window._close_plan_confirmer = lambda: 'save'
ui.window.close()
qtbot.waitUntil(lambda: ui.window._closed, timeout=5000)
assert ui.service.target_plan(ui.tasks[0].task_id)[0].new_part_number == 'TYPED'
assert not panel.has_unsaved_plans()
@pytest.mark.parametrize('destination', ['close', 'switch'])
def test_save_during_slow_same_task_refresh_keeps_typed_text(ui, qtbot, monkeypatch, destination):
panel, _ = seed(ui)
edit_cell(panel, 'REFRESH_TYPED')
task = ui.tasks[0]
started, release = Event(), Event()
original = ui.service.task_context
def slow_context(task_id, **kwargs):
if task_id == task.task_id and not started.is_set():
started.set()
assert release.wait(5)
return original(task_id, **kwargs)
monkeypatch.setattr(ui.service, 'task_context', slow_context)
ui.window.archive_on_close_check.setChecked(False)
ui.window._close_plan_confirmer = lambda: 'save'
try:
ui.window.open_task(task.task_id)
qtbot.waitUntil(started.is_set, timeout=2000)
if destination == 'close':
ui.window.close()
qtbot.waitUntil(lambda: ui.window._closed, timeout=3000)
else:
ui.window.open_task(ui.tasks[1].task_id)
qtbot.waitUntil(lambda: not ui.window._workers, timeout=3000)
assert ui.window._task_id == ui.tasks[1].task_id
assert ui.service.target_plan(task.task_id)[0].new_part_number == 'REFRESH_TYPED'
finally:
release.set()
ui.window._close_plan_confirmer = lambda: 'cancel'
@pytest.mark.parametrize('destination', ['close', 'switch', 'save'])
def test_rejected_editor_commit_keeps_text_and_does_not_dispatch_save(ui, monkeypatch, destination):
panel, original = seed(ui)
edit_cell(panel, 'KEEP_TYPED')
panel.table.set_plan_editable(False)
errors, writes = [], []
monkeypatch.setattr(ui.window, '_show_error', lambda error, **_: errors.append(error))
monkeypatch.setattr(ui.service, 'save_plan_drafts', lambda *args: writes.append(args))
ui.window._close_plan_confirmer = lambda: 'save'
try:
if destination == 'close':
ui.window.close()
elif destination == 'switch':
ui.window.open_task(ui.tasks[1].task_id)
else:
panel.save()
assert errors
assert not writes and not ui.window._workers
assert not ui.window._close_saving and not ui.window._closed
assert ui.window._task_id == ui.tasks[0].task_id
assert panel.table.has_pending_editor()
assert ui.service.target_plan(ui.tasks[0].task_id) == original
finally:
ui.window._close_plan_confirmer = lambda: 'cancel'
+106
View File
@@ -0,0 +1,106 @@
"""Invalid Part Number drafts stay editable and identify their offending cell."""
from dataclasses import replace
from pathlib import Path
import pytest
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QLineEdit
from dx_productivity.trial_task_center.errors import TaskCenterError
from dx_productivity.trial_task_center.target_plan import ComponentTarget, TargetPlanRow, compile_target_rules
from dx_productivity.trial_task_center.ui.mapping_table import MappingTable
from dx_productivity.trial_task_center.ui.target_table import TargetTable
def target_row():
return TargetPlanRow(ComponentTarget(Path('board.prj'), 'MAIN', '1', 'uid', 'R1', 'OLD', ''), True, 'NEW')
@pytest.mark.parametrize('bulk', [False, True])
def test_invalid_pn_highlight_and_tooltip_clear_after_correction(qtbot, bulk):
table = TargetTable()
qtbot.addWidget(table)
table.populate((target_row(),))
index = table.model().index(0, 6)
if bulk:
table.selectRow(0)
table.apply_to_selected('BAD PART !!@#')
else:
assert table.model().setData(index, 'BAD PART !!@#')
assert table.rows()[0].new_part_number == 'BAD PART !!@#' and table.dirty
assert index.data(Qt.ItemDataRole.BackgroundRole) is not None
assert '料号' in index.data(Qt.ItemDataRole.ToolTipRole)
assert '空白' in index.data(Qt.ItemDataRole.ToolTipRole)
with pytest.raises(TaskCenterError):
compile_target_rules(table.rows())
assert table.rows()[0].new_part_number == 'BAD PART !!@#'
assert table.model().setData(index, 'NEW-OK')
assert index.data(Qt.ItemDataRole.BackgroundRole) is None
assert compile_target_rules(table.rows())[0].new_part_number == 'NEW-OK'
def test_mapping_pn_error_is_visible_without_flagging_free_value(qtbot):
from types import SimpleNamespace
table = MappingTable()
qtbot.addWidget(table)
table.populate((SimpleNamespace(rule_id='rule', old_part_number='OLD', new_part_number='BAD PART !!@#',
custom_value_enabled=True, custom_value='free !@#', enabled=True, position=0),))
assert table.model().index(0, 1).data(Qt.ItemDataRole.BackgroundRole) is not None
assert '空白' in table.model().index(0, 1).data(Qt.ItemDataRole.ToolTipRole)
assert table.model().index(0, 2).data(Qt.ItemDataRole.BackgroundRole) is None
def test_part_number_editor_has_an_accessible_name(qtbot):
table = TargetTable()
qtbot.addWidget(table)
table.populate((target_row(),))
table.show()
table.edit(table.model().index(0, 6))
editor = table.findChild(QLineEdit)
assert editor is not None and '新料号' in editor.accessibleName()
def test_active_editor_commits_invalid_text_to_draft_without_losing_it(qtbot):
table = TargetTable()
qtbot.addWidget(table)
table.populate((target_row(),))
table.show()
table.edit(table.model().index(0, 6))
editor = table.findChild(QLineEdit)
editor.setText('BAD PART !!@#')
assert table.has_pending_editor()
assert table.commit_editor()
assert table.rows()[0].new_part_number == 'BAD PART !!@#' and table.dirty
with pytest.raises(TaskCenterError):
compile_target_rules(table.rows())
assert not table.has_pending_editor()
def test_rejected_readonly_editor_commit_preserves_text_and_allows_retry(qtbot):
table = TargetTable()
qtbot.addWidget(table)
table.populate((target_row(),))
table.show()
table.edit(table.model().index(0, 6))
editor = table.findChild(QLineEdit)
editor.setText('PENDING-NEW')
table.set_plan_editable(False)
with pytest.raises(TaskCenterError, match='editor_commit'):
table.commit_editor()
assert table.rows()[0].new_part_number == 'NEW'
assert table.has_pending_editor() and editor.text() == 'PENDING-NEW' and editor.isVisible()
table.set_plan_editable(True)
assert table.commit_editor()
assert table.rows()[0].new_part_number == 'PENDING-NEW'
assert not table.has_pending_editor()
def test_unchanged_after_trim_editor_can_close_without_false_rejection(qtbot):
table = TargetTable()
qtbot.addWidget(table)
table.populate((target_row(),))
table.show()
table.edit(table.model().index(0, 6))
table.findChild(QLineEdit).setText(' NEW ')
assert table.commit_editor()
assert table.rows()[0].new_part_number == 'NEW' and not table.dirty
+1 -1
View File
@@ -26,7 +26,7 @@ def test_task_management_is_a_menu_and_new_task_is_at_the_top(ui):
assert panel.new_button.geometry().top()<panel.search.geometry().top()
assert not panel.edit_button.isVisible()
panel.manage_menu.sync()
assert any(action.text()==panel.edit_button.text()for action in panel.manage_menu.actions())
assert any(action.text().split('\t')[0]==panel.edit_button.text()for action in panel.manage_menu.actions())
assert panel.queue_button.isVisible()
assert panel.list.itemDelegate().__class__.__name__=='TaskItemDelegate'