mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[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:
parent
f089414f1c
commit
0498ea8907
7 changed files with 279 additions and 3 deletions
|
|
@ -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`.
|
||||
|
|
|
|||
34
Testing/deck_editor_double_click_test.xml
Normal file
34
Testing/deck_editor_double_click_test.xml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<events>
|
||||
<!--
|
||||
A single click and a double click differ, and only a double click acts.
|
||||
|
||||
The card database view adds the card under the mouse to the deck on
|
||||
double click (CardDatabaseView::actDoubleClick); a single click only
|
||||
moves the current row and updates the preview. Asserting the deck's row
|
||||
count after each proves the MouseButtonDblClick event really reaches the
|
||||
view, which a page-index assertion in the settings tree cannot show.
|
||||
|
||||
The visual deck editor shows its cards in a picture grid, which is not an
|
||||
item view, so the addressable list is the one in its card database dock.
|
||||
Which card lands in the deck does not matter: the test asserts that a
|
||||
click adds nothing and a double click adds one.
|
||||
|
||||
Assertions carry type="check": QtTesting only reaches its check players
|
||||
with a check event.
|
||||
-->
|
||||
<event widget="MainWindow/tabSupervisor/stackedWidget/TabHome/homeWidget/homeActionsScrollArea/qt_scrollarea_viewport/homeButtonsBox/homeCreateNewDeckButton" command="activate" arguments="" />
|
||||
<event widget="MainWindow" command="process_events" arguments="1500" />
|
||||
|
||||
<!-- A fresh deck starts empty -->
|
||||
<event widget="MainWindow/tabSupervisor/stackedWidget/TabDeckEditorVisual/deckDock/deckDockContents/deckSplitter/deckListPane/deckView" command="modelRowCount" arguments="0" type="check" />
|
||||
|
||||
<!-- A single click only selects the card -->
|
||||
<event widget="MainWindow/tabSupervisor/stackedWidget/TabDeckEditorVisual/databaseDisplayDock/databaseDisplayDockContents/databaseDisplayWidget/databaseView" command="clickRow" arguments="0" />
|
||||
<event widget="MainWindow" command="process_events" arguments="300" />
|
||||
<event widget="MainWindow/tabSupervisor/stackedWidget/TabDeckEditorVisual/deckDock/deckDockContents/deckSplitter/deckListPane/deckView" command="modelRowCount" arguments="0" type="check" />
|
||||
|
||||
<!-- A double click adds the card -->
|
||||
<event widget="MainWindow/tabSupervisor/stackedWidget/TabDeckEditorVisual/databaseDisplayDock/databaseDisplayDockContents/databaseDisplayWidget/databaseView" command="doubleClickRow" arguments="0" />
|
||||
<event widget="MainWindow" command="process_events" arguments="300" />
|
||||
<event widget="MainWindow/tabSupervisor/stackedWidget/TabDeckEditorVisual/deckDock/deckDockContents/deckSplitter/deckListPane/deckView" command="modelRowCount" arguments="1" type="check" />
|
||||
</events>
|
||||
34
Testing/item_view_test.xml
Normal file
34
Testing/item_view_test.xml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<events>
|
||||
<!--
|
||||
Item-view driving through a playback.
|
||||
|
||||
QtTesting's own `currentChanged` command aborts on a one-element row
|
||||
list, so rows are selected through the view's selection model or clicked
|
||||
with real mouse events instead.
|
||||
|
||||
The settings navigation tree is grouped, so a page is addressed as
|
||||
"group/page": the groups are Application, Cards & Data, Chat &
|
||||
Sound and Advanced, and the page stack follows the page order
|
||||
General(0) ... Shortcuts(7). Selecting a group header does nothing — the
|
||||
headers are not selectable.
|
||||
|
||||
Double click is covered by deck_editor_double_click_test.xml, where it
|
||||
has an effect a single click does not have.
|
||||
-->
|
||||
<event widget="MainWindow/menubar" command="activate" arguments="cockatriceMenu" />
|
||||
<event widget="MainWindow/menubar/cockatriceMenu" command="activate" arguments="actionSettings" />
|
||||
<event widget="MainWindow" command="pause" arguments="500" />
|
||||
<event widget="MainWindow/settingsDialog/settingsView/pagesContainer/pagesWidget" command="expectProperty" arguments="currentIndex,0" />
|
||||
|
||||
<!-- Chat & Sound group, second page: Sound -->
|
||||
<event widget="MainWindow/settingsDialog/settingsView/navTree" command="selectRow" arguments="2/1" />
|
||||
<event widget="MainWindow" command="pause" arguments="300" />
|
||||
<event widget="MainWindow/settingsDialog/settingsView/pagesContainer/pagesWidget" command="expectProperty" arguments="currentIndex,6" />
|
||||
|
||||
<!-- A click goes through the view rather than the selection model: Deck Editor -->
|
||||
<event widget="MainWindow/settingsDialog/settingsView/navTree" command="clickRow" arguments="1/0" />
|
||||
<event widget="MainWindow" command="pause" arguments="300" />
|
||||
<event widget="MainWindow/settingsDialog/settingsView/pagesContainer/pagesWidget" command="expectProperty" arguments="currentIndex,3" />
|
||||
|
||||
<event widget="MainWindow/settingsDialog/settingsOkButton" command="activate" arguments="" />
|
||||
</events>
|
||||
Loading…
Add table
Add a link
Reference in a new issue