MCPcopy
hub / github.com/moncho/dry / TestTableModel_SortPreservedAfterSetRows

Function TestTableModel_SortPreservedAfterSetRows

appui/table_model_test.go:304–330  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

302}
303
304func TestTableModel_SortPreservedAfterSetRows(t *testing.T) {
305 cols := []Column{{Title: "Name"}, {Title: "Value"}}
306 table := NewTableModel(cols)
307 table.SetSize(80, 25)
308
309 // Set sort field to column 1 (Value)
310 table.NextSort() // now sorting by column 1
311
312 rows := []TableRow{
313 testRow{id: "1", cols: []string{"cherry", "c"}},
314 testRow{id: "2", cols: []string{"apple", "a"}},
315 testRow{id: "3", cols: []string{"banana", "b"}},
316 }
317 table.SetRows(rows)
318 // SetRows does NOT re-sort, so order is insertion order
319 r := table.SelectedRow()
320 if r == nil || r.ID() != "1" {
321 t.Fatalf("expected first row id '1' after SetRows (no sort), got %v", r)
322 }
323
324 // Calling Sort() should re-sort by column 1 (Value)
325 table.Sort()
326 r = table.SelectedRow()
327 if r == nil || r.Columns()[1] != "a" {
328 t.Fatalf("expected first row value 'a' after Sort(), got %v", r)
329 }
330}
331
332func TestTableModel_ViewNotEmpty(t *testing.T) {
333 cols := []Column{{Title: "Name", Width: 20, Fixed: true}}

Callers

nothing calls this directly

Calls 8

SetSizeMethod · 0.95
NextSortMethod · 0.95
SetRowsMethod · 0.95
SelectedRowMethod · 0.95
SortMethod · 0.95
NewTableModelFunction · 0.85
IDMethod · 0.65
ColumnsMethod · 0.65

Tested by

no test coverage detected