()
| 65 | |
| 66 | |
| 67 | async def test_datatable_message_emission(): |
| 68 | app = DataTableApp() |
| 69 | expected_messages = [] |
| 70 | async with app.run_test() as pilot: |
| 71 | table = app.query_one(DataTable) |
| 72 | |
| 73 | assert app.message_names == expected_messages |
| 74 | |
| 75 | table.add_columns("Column0", "Column1") |
| 76 | table.add_rows(ROWS) |
| 77 | |
| 78 | # A CellHighlighted is emitted because there were no rows (and |
| 79 | # therefore no highlighted cells), but then a row was added, and |
| 80 | # so the cell at (0, 0) became highlighted. |
| 81 | expected_messages.append("CellHighlighted") |
| 82 | await pilot.pause() |
| 83 | assert app.message_names == expected_messages |
| 84 | |
| 85 | # Pressing Enter when the cursor is on a cell emits a CellSelected |
| 86 | await pilot.press("enter") |
| 87 | await pilot.pause() |
| 88 | expected_messages.append("CellSelected") |
| 89 | assert app.message_names == expected_messages |
| 90 | |
| 91 | # Moving the cursor left and up when the cursor is at origin |
| 92 | # emits no events, since the cursor doesn't move at all. |
| 93 | await pilot.press("left", "up") |
| 94 | assert app.message_names == expected_messages |
| 95 | |
| 96 | # ROW CURSOR |
| 97 | # Switch over to the row cursor... should emit a `RowHighlighted` |
| 98 | table.cursor_type = "row" |
| 99 | expected_messages.append("RowHighlighted") |
| 100 | await pilot.pause() |
| 101 | assert app.message_names == expected_messages |
| 102 | |
| 103 | # Select the row... |
| 104 | await pilot.press("enter") |
| 105 | await pilot.pause() |
| 106 | expected_messages.append("RowSelected") |
| 107 | assert app.message_names == expected_messages |
| 108 | |
| 109 | # COLUMN CURSOR |
| 110 | # Switching to the column cursor emits a `ColumnHighlighted` |
| 111 | table.cursor_type = "column" |
| 112 | expected_messages.append("ColumnHighlighted") |
| 113 | await pilot.pause() |
| 114 | assert app.message_names == expected_messages |
| 115 | |
| 116 | # Select the column... |
| 117 | await pilot.press("enter") |
| 118 | expected_messages.append("ColumnSelected") |
| 119 | await pilot.pause() |
| 120 | assert app.message_names == expected_messages |
| 121 | |
| 122 | # NONE CURSOR |
| 123 | # No messages get emitted at all... |
| 124 | table.cursor_type = "none" |
nothing calls this directly
no test coverage detected
searching dependent graphs…