mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add DataTable medium-sized test for clearing
This commit is contained in:
36
tests/test_data_table.py
Normal file
36
tests/test_data_table.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user