From 15392b9091037e09819744a4c299d6948ad38bd1 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Wed, 18 Jan 2023 13:19:45 +0000 Subject: [PATCH] Add DataTable medium-sized test for clearing --- tests/test_data_table.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_data_table.py diff --git a/tests/test_data_table.py b/tests/test_data_table.py new file mode 100644 index 000000000..78e9b7743 --- /dev/null +++ b/tests/test_data_table.py @@ -0,0 +1,36 @@ +from textual.app import App +from textual.coordinate import Coordinate +from textual.widgets import DataTable + + +class DataTableApp(App): + def compose(self): + yield DataTable() + + +async def test_clear(): + app = DataTableApp() + async with app.run_test(): + table = app.query_one(DataTable) + assert table.cursor_cell == Coordinate(0, 0) + assert table.hover_cell == Coordinate(0, 0) + + # Add some data and update cursor positions + table.add_column("Column0") + table.add_rows([["Row0"], ["Row1"], ["Row2"]]) + table.cursor_cell = Coordinate(1, 0) + table.hover_cell = Coordinate(2, 0) + + # Ensure the cursor positions are reset to origin on clear() + table.clear() + assert table.cursor_cell == Coordinate(0, 0) + assert table.hover_cell == Coordinate(0, 0) + + # Ensure that the table has been cleared + assert table.data == {} + assert table.rows == {} + assert len(table.columns) == 1 + + # Clearing the columns too + table.clear(columns=True) + assert len(table.columns) == 0