summaryrefslogtreecommitdiff
path: root/internal/tui/dashboard/files_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-09 22:41:07 +0200
committerPaul Buetow <paul@buetow.org>2026-03-09 22:41:07 +0200
commit1af7cf5fe51fa13e828cdef6268348ec9cd7bd7c (patch)
treef8d28d4faa627b31175c0c39164c2ea84e022e90 /internal/tui/dashboard/files_test.go
parenta4c72ad2cbe4ca857a5880675563b2ab4d24e1b5 (diff)
tui: add sortable files dashboard table modes (task 364)
Diffstat (limited to 'internal/tui/dashboard/files_test.go')
-rw-r--r--internal/tui/dashboard/files_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/tui/dashboard/files_test.go b/internal/tui/dashboard/files_test.go
index 1be958a..87ada56 100644
--- a/internal/tui/dashboard/files_test.go
+++ b/internal/tui/dashboard/files_test.go
@@ -27,6 +27,12 @@ func TestRenderFilesIncludesHeaders(t *testing.T) {
t.Fatalf("expected token %q in files table output", token)
}
}
+ if !strings.Contains(out, "s:sort") {
+ t.Fatalf("expected files sort hint in output")
+ }
+ if !strings.Contains(out, "sort: default") {
+ t.Fatalf("expected files default sort label in output")
+ }
}
func TestRenderFilesNoData(t *testing.T) {
@@ -106,3 +112,37 @@ func TestDirPathWidthAccountsForFilesColumn(t *testing.T) {
t.Fatalf("expected dirPathWidth to reserve 6 extra chars, got dir=%d file=%d", got, filePathWidth(180))
}
}
+
+func TestSortedFileSnapshotsUsesSelectedSortKey(t *testing.T) {
+ rows := []statsengine.FileSnapshot{
+ {Path: "/tmp/z.log", Accesses: 9, BytesRead: 10},
+ {Path: "/tmp/a.log", Accesses: 3, BytesRead: 50},
+ }
+
+ sorted := sortedFileSnapshots(rows, tableSortState[fileSortKey]{active: true, key: fileSortKeyPath})
+ if sorted[0].Path != "/tmp/a.log" {
+ t.Fatalf("expected path sort to put /tmp/a.log first, got %q", sorted[0].Path)
+ }
+
+ sorted = sortedFileSnapshots(rows, tableSortState[fileSortKey]{active: true, key: fileSortKeyRead})
+ if sorted[0].Path != "/tmp/a.log" {
+ t.Fatalf("expected read desc sort to put /tmp/a.log first, got %q", sorted[0].Path)
+ }
+}
+
+func TestSortedDirSnapshotsUsesSelectedSortKey(t *testing.T) {
+ rows := []DirSnapshot{
+ {Dir: "/var/log", Accesses: 9, FileCount: 1},
+ {Dir: "/tmp", Accesses: 3, FileCount: 4},
+ }
+
+ sorted := sortedDirSnapshots(rows, tableSortState[fileDirSortKey]{active: true, key: fileDirSortKeyDir})
+ if sorted[0].Dir != "/tmp" {
+ t.Fatalf("expected dir sort to put /tmp first, got %q", sorted[0].Dir)
+ }
+
+ sorted = sortedDirSnapshots(rows, tableSortState[fileDirSortKey]{active: true, key: fileDirSortKeyFileCount})
+ if sorted[0].Dir != "/tmp" {
+ t.Fatalf("expected file-count sort to put /tmp first, got %q", sorted[0].Dir)
+ }
+}