Testing highlighted events via keyboard cursor movement

This commit is contained in:
Darren Burns
2023-02-08 14:01:42 +00:00
parent 64840daa0e
commit 2fe73c0c28
2 changed files with 36 additions and 1 deletions

View File

@@ -67,7 +67,10 @@ class StringKey:
def __eq__(self, other: object) -> bool:
# Strings will match Keys containing the same string value.
# Otherwise, you'll need to supply the exact same key object.
return hash(self) == hash(other)
try:
return hash(self) == hash(other)
except TypeError:
return False
def __lt__(self, other):
if isinstance(other, str):

View File

@@ -617,6 +617,38 @@ async def test_sort_reverse_coordinate_and_key_access():
assert table.ordered_rows[2].key == row_one
async def test_cell_cursor_highlight_events():
app = DataTableApp()
async with app.run_test():
table = app.query_one(DataTable)
column_one_key, column_two_key = table.add_columns("A", "B")
_ = table.add_row(0, 1)
row_two_key = table.add_row(2, 3)
# Since initial position is (0, 0), cursor doesn't move so no event posted
table.action_cursor_up()
table.action_cursor_left()
await wait_for_idle(0)
assert table.app.message_names == ["CellHighlighted"]
table.action_cursor_down()
await wait_for_idle(0)
assert len(table.app.messages) == 2
latest_message: DataTable.CellHighlighted = table.app.messages[-1]
assert latest_message.value == 2
assert latest_message.coordinate == Coordinate(1, 0)
assert latest_message.cell_key == CellKey(row_two_key, column_one_key)
table.action_cursor_right()
await wait_for_idle(0)
assert len(table.app.messages) == 3
latest_message = table.app.messages[-1]
assert latest_message.coordinate == Coordinate(1, 1)
assert latest_message.cell_key == CellKey(row_two_key, column_two_key)
def test_key_equals_equivalent_string():
text = "Hello"
key = RowKey(text)