Files
dxdesigner-part-replacement/tests/ui/test_ui_polish.py
T

170 lines
6.7 KiB
Python

"""Visible feedback and keyboard actions obey the existing plan gates."""
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QLineEdit
from dx_productivity.trial_task_center.target_plan import ComponentTarget,TargetPlanRow
def seed_plan(ui):
task=ui.tasks[0]
project=ui.store.list_projects(task.task_id)[0].path
rows=tuple(TargetPlanRow(ComponentTarget(project,'MAIN','1',f'polish-{i}',ref,'OLD','100nF'),i==0,'NEW')
for i,ref in enumerate(('RV05','RV11','C103')))
ui.store.record_target_inventory(task.task_id,tuple(row.target for row in rows))
ui.service.replace_target_plan(task.task_id,rows)
ui.open(task);ui.settle()
ui.window.mapping_tabs.setCurrentIndex(1)
return ui.window.plan_panel
def test_search_feedback_and_no_match_state_are_visible(ui):
panel=seed_plan(ui)
panel.find_text.setText('RV');panel.find()
assert panel.find_result.isVisible()
assert '2 / 3'in panel.find_result.text()
assert panel.next_match_action.isEnabled()
panel.find_text.setText('NOT-PRESENT');panel.find()
assert not panel.next_match_action.isEnabled()
assert panel.table.empty_hint.isVisible()
assert '没有匹配'in panel.table.empty_hint.text()
panel.clear_find()
assert not panel.find_result.isVisible()
assert panel.table.rowCount()==3
assert not panel.table.empty_hint.isVisible()
def test_clean_plan_cannot_be_resaved_and_dirty_plan_can(ui):
panel=seed_plan(ui)
assert not panel.save_button.isEnabled()
assert '已保存'in panel.save_state.text()
panel.table.model().setData(panel.table.model().index(0,6),'NEW-EDIT')
assert panel.save_button.isEnabled()
assert '未保存'in panel.save_state.text()
panel.save_shortcut.trigger();ui.settle()
assert not panel.table.dirty
assert not panel.save_button.isEnabled()
assert any(row.new_part_number=='NEW-EDIT'for row in ui.service.target_plan(ui.tasks[0].task_id))
def test_bulk_edit_requires_selected_rows_and_nonempty_input(ui):
panel=seed_plan(ui)
panel.table.clearSelection();panel.bulk_part.setText('BULK')
assert not panel.bulk_apply.isEnabled()
panel.table.selectRow(1)
assert panel.bulk_apply.isEnabled()
assert '1'in panel.bulk_apply.text()
panel.bulk_part.clear()
assert not panel.bulk_apply.isEnabled()
assert all(row.new_part_number=='NEW'for row in panel.table.rows())
def test_keyboard_save_does_not_bypass_readonly_state(ui):
panel=seed_plan(ui)
panel.table.model().setData(panel.table.model().index(0,6),'UNSAVED')
panel.set_plan_editable(False)
panel.save_shortcut.trigger();ui.settle()
assert panel.table.dirty
assert all(row.new_part_number=='NEW'for row in ui.service.target_plan(ui.tasks[0].task_id))
panel.discard_all()
def test_find_shortcut_focuses_existing_search(ui,qtbot):
panel=seed_plan(ui)
panel.find_shortcut.trigger()
assert panel.find_text.hasFocus()
assert panel.find_shortcut.shortcut().toString()=='Ctrl+F'
def test_keyboard_save_commits_current_cell_editor_before_saving(ui,qtbot):
panel=seed_plan(ui)
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('NEW-TYPED')
assert not panel.table.dirty
panel.save_shortcut.trigger();ui.settle()
assert any(row.new_part_number=='NEW-TYPED'for row in ui.service.target_plan(ui.tasks[0].task_id))
def test_active_cell_enables_save_but_escape_cancels_without_dirtying(ui,qtbot):
panel=seed_plan(ui)
index=panel.table.model().index(0,6)
panel.table.setCurrentIndex(index);panel.table.setFocus();panel.table.edit(index)
editor=panel.table.findChild(QLineEdit)
editor.setText('NOT-COMMITTED')
assert not panel.table.dirty
assert panel.save_button.isEnabled()
assert panel.has_unsaved_plans()
qtbot.keyClick(editor,Qt.Key.Key_Escape);qtbot.wait(20)
assert not panel.table.dirty
assert not panel.save_button.isEnabled()
def test_discard_closes_active_editor_without_committing_it(ui):
panel=seed_plan(ui)
index=panel.table.model().index(0,6)
panel.table.setCurrentIndex(index);panel.table.setFocus();panel.table.edit(index)
panel.table.findChild(QLineEdit).setText('DISCARD-ME')
panel.discard_all()
assert not panel.table.has_pending_editor()
assert not panel.has_unsaved_plans()
assert all(row.new_part_number=='NEW'for row in panel.table.rows())
def test_mouse_save_commits_active_cell_text(ui,qtbot):
panel=seed_plan(ui)
index=panel.table.model().index(0,6)
panel.table.setCurrentIndex(index);panel.table.setFocus();panel.table.edit(index)
panel.table.findChild(QLineEdit).setText('NEW-MOUSE')
qtbot.mouseClick(panel.save_button,Qt.MouseButton.LeftButton);ui.settle()
assert any(row.new_part_number=='NEW-MOUSE'for row in ui.service.target_plan(ui.tasks[0].task_id))
def test_full_project_title_remains_available_when_narrow(ui,qtbot):
title=ui.window.project_summary.name
value='Very long project name with a distinctive suffix '*8
title.setText(value)
ui.window.resize(980,700);qtbot.wait(30)
assert ui.window.width()==980
assert title.text()==value
assert title.toolTip()==value
def test_project_summary_status_does_not_repeat_current_project_scope(ui):
ui.open(ui.tasks[0]); ui.settle()
status=ui.window.project_summary.state.text()
assert not status.startswith('当前工程')
def test_target_table_header_stays_connected_and_supports_horizontal_layout(ui,qtbot):
panel=seed_plan(ui)
table=panel.table
header=table.horizontalHeader()
ui.window.resize(980,700); qtbot.wait(30)
assert header.sectionsMovable()
assert not header.stretchLastSection()
assert table.horizontalScrollMode()==table.ScrollMode.ScrollPerPixel
assert table.horizontalScrollBarPolicy()==Qt.ScrollBarPolicy.ScrollBarAsNeeded
assert table.horizontalScrollBar().maximum()>0
original=header.sectionSize(6)
header.resizeSection(6,original+40)
assert header.sectionSize(6)==original+40
header.moveSection(0,2)
assert header.visualIndex(0)==2
assert table.horizontalHeader().logicalIndex(2)==0
def test_rule_table_header_supports_the_same_horizontal_layout(ui,qtbot):
table=ui.window.mapping_table
ui.window.resize(980,700); qtbot.wait(30)
header=table.horizontalHeader()
assert header.sectionsMovable()
assert not header.stretchLastSection()
assert table.horizontalScrollMode()==table.ScrollMode.ScrollPerPixel
assert table.horizontalScrollBar().maximum()>0
original=header.sectionSize(0)
header.resizeSection(0,original+24)
assert header.sectionSize(0)==original+24
header.moveSection(0,1)
assert header.visualIndex(0)==1