mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Unit testing for sorting method
This commit is contained in:
@@ -469,7 +469,7 @@ async def test_datatable_on_click_cell_cursor():
|
|||||||
assert cell_selected_event.coordinate == Coordinate(1, 0)
|
assert cell_selected_event.coordinate == Coordinate(1, 0)
|
||||||
|
|
||||||
|
|
||||||
async def test_datatable_on_click_row_cursor():
|
async def test_on_click_row_cursor():
|
||||||
"""When the row cursor is used, and we click, we emit a RowHighlighted
|
"""When the row cursor is used, and we click, we emit a RowHighlighted
|
||||||
*and* a RowSelected message for the row that was clicked."""
|
*and* a RowSelected message for the row that was clicked."""
|
||||||
app = DataTableApp()
|
app = DataTableApp()
|
||||||
@@ -495,7 +495,7 @@ async def test_datatable_on_click_row_cursor():
|
|||||||
assert row_highlighted.cursor_row == 1
|
assert row_highlighted.cursor_row == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_datatable_on_click_column_cursor():
|
async def test_on_click_column_cursor():
|
||||||
"""When the column cursor is used, and we click, we emit a ColumnHighlighted
|
"""When the column cursor is used, and we click, we emit a ColumnHighlighted
|
||||||
*and* a ColumnSelected message for the column that was clicked."""
|
*and* a ColumnSelected message for the column that was clicked."""
|
||||||
app = DataTableApp()
|
app = DataTableApp()
|
||||||
@@ -524,7 +524,7 @@ async def test_datatable_on_click_column_cursor():
|
|||||||
assert column_highlighted.cursor_column == 0
|
assert column_highlighted.cursor_column == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_datatable_hover_coordinate():
|
async def test_hover_coordinate():
|
||||||
"""Ensure that the hover_coordinate reactive is updated as expected."""
|
"""Ensure that the hover_coordinate reactive is updated as expected."""
|
||||||
app = DataTableApp()
|
app = DataTableApp()
|
||||||
async with app.run_test():
|
async with app.run_test():
|
||||||
@@ -551,6 +551,35 @@ async def test_datatable_hover_coordinate():
|
|||||||
assert table.hover_coordinate == Coordinate(1, 2)
|
assert table.hover_coordinate == Coordinate(1, 2)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_sort_coordinate_and_key_access():
|
||||||
|
"""Ensure that, after sorting, that coordinates and cell keys
|
||||||
|
can still be used to retrieve the correct cell."""
|
||||||
|
app = DataTableApp()
|
||||||
|
async with app.run_test():
|
||||||
|
table = app.query_one(DataTable)
|
||||||
|
column = table.add_column("number")
|
||||||
|
row_three = table.add_row(3)
|
||||||
|
row_one = table.add_row(1)
|
||||||
|
row_two = table.add_row(2)
|
||||||
|
|
||||||
|
# Items inserted in correct initial positions (before sort)
|
||||||
|
assert table.get_value_at(Coordinate(0, 0)) == 3
|
||||||
|
assert table.get_value_at(Coordinate(1, 0)) == 1
|
||||||
|
assert table.get_value_at(Coordinate(2, 0)) == 2
|
||||||
|
|
||||||
|
table.sort(column)
|
||||||
|
|
||||||
|
# The keys still refer to the same cells...
|
||||||
|
assert table.get_cell_value(row_one, column) == 1
|
||||||
|
assert table.get_cell_value(row_two, column) == 2
|
||||||
|
assert table.get_cell_value(row_three, column) == 3
|
||||||
|
|
||||||
|
# ...even though the values under the coordinates have changed...
|
||||||
|
assert table.get_value_at(Coordinate(0, 0)) == 1
|
||||||
|
assert table.get_value_at(Coordinate(1, 0)) == 2
|
||||||
|
assert table.get_value_at(Coordinate(2, 0)) == 3
|
||||||
|
|
||||||
|
|
||||||
def test_key_equals_equivalent_string():
|
def test_key_equals_equivalent_string():
|
||||||
text = "Hello"
|
text = "Hello"
|
||||||
key = RowKey(text)
|
key = RowKey(text)
|
||||||
|
|||||||
Reference in New Issue
Block a user