[Tests] Drive item views from a playback (#7819)

QtTesting's own `currentChanged` command aborts on a one-element row list, so
pqWidgetTestEventPlayer drives views itself:

- selectRow selects a row through the selection model, the whole row, without a
  mouse event
- clickRow left-clicks the centre of a cell, so the view's own handlers run
- doubleClickRow double-clicks it, for views whose double click acts

A tree addresses a row by the path of rows leading to it ("2/0" is the first
child of the third top-level row), and a click opens a collapsed path first.
Rows are model rows, so a filtered or sorted model counts the rows it shows.

Asserting what a command did needs QtTesting's check players, which the XML
source never reached: it marked every event an action, so `modelRowCount` was
rejected as unknown. An event now carries `type="check"` to be played as a
check.

Testing/item_view_test.xml drives the grouped settings navigation through
selectRow and clickRow and asserts the page stack followed.
Testing/deck_editor_double_click_test.xml proves the difference between the two
clicks: a single click on a card database row only selects it, a double click
adds the card to the deck.
This commit is contained in:
BruebachL 2026-11-10 09:12:10 +01:00 • committed by GitHub
parent f089414f1c
commit 0498ea8907
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 279 additions and 3 deletions

View file

@ -66,14 +66,34 @@ A test is an `<events>` list. Widgets are named by their path from the main wind
| `screenshot` | `path` | saves an image of the addressed widget; `$VAR` expands from the environment |
| `dumpTree` | `path` | writes the addressed widget's subtree with the paths tests address |
| `resize` | `WIDTHxHEIGHT` | resizes the addressed widget's window |
| `selectRow` | `row[/row…][,column]` | selects a row of an item view through its selection model |
| `clickRow` | `row[/row…][,column]` | left-clicks a cell, so the view's own handlers run |
| `doubleClickRow` | `row[/row…][,column]` | double-clicks a cell |
The card, item and property commands are `pqCockatriceEventPlayer`
(`cockatrice/src/game_graphics/pq_cockatrice_event_player.h`). They resolve cards by name
and zone through the `QGraphicsScene` and send real mouse events at the card's current
viewport position, so a test does not depend on the window size or screen resolution.
The capture commands are `pqWidgetTestEventPlayer`
(`cockatrice/src/interface/pq_widget_test_event_player.h`).
The capture and row commands are `pqWidgetTestEventPlayer`
(`cockatrice/src/interface/pq_widget_test_event_player.h`). Rows are model rows of the
addressed view, so a filtered or sorted model counts the rows it shows. A tree addresses a
row by the path of rows leading to it: `2/0` is the first child of the third top-level
row. A click opens a collapsed path first.
## Assertions
`expectProperty` is an action. It fails playback unless a widget property matches.
QtTesting's own check commands assert model state instead, and they only run when the
event carries `type="check"`. Without it the event is an action, and a check command is
rejected as unknown:
```xml
<event widget="MainWindow/.../deckView" command="modelRowCount" arguments="1" type="check" />
```
`modelRowCount` compares `model()->rowCount()`. `modelItemData` compares the data of one
cell, addressed as `row.column,text` (`modelItemData "0.0,Lightning Bolt"`).
## Screenshots
@ -121,3 +141,9 @@ Record the tree in the same playback that clicks, and copy paths from that dump:
./Testing/run_test.sh Testing/screenshot_test.xml
less build/screenshots/widget-tree.txt
```
### Selecting a row
QtTesting's own `currentChanged` takes `row|column`. `0:0` reaches `OldGetIndex`, which
calls `.at(1)` on a one-element list and aborts the process. Select through `selectRow`
(or click through `clickRow`) instead. Never use `currentChanged`.