61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package browser
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"pad/internal/io/pool"
|
|
"pad/internal/io/pool/mock"
|
|
)
|
|
|
|
// TestTapDirectory verifies that tapping a directory entry updates the
|
|
// BrowserState.CurrentPath.
|
|
func TestTapDirectory(t *testing.T) {
|
|
state := NewBrowserState()
|
|
fs := mock.NewFileSystem()
|
|
wp := pool.NewWorkerPool(1)
|
|
bm, _ := NewBrowserManager(state, wp, fs)
|
|
state.CurrentPath = "/root"
|
|
|
|
// Mock entries: a subdirectory "sub" and a file
|
|
entries := []Entry{
|
|
NewEntry("/root/sub", "sub", 0, time.Time{}, true),
|
|
NewEntry("/root/file.txt", "file.txt", 100, time.Time{}, false),
|
|
}
|
|
// Inject entries into the state
|
|
state.Pages[0] = NewPage(0, entries)
|
|
state.TotalEntries = 2
|
|
|
|
// Simulate tapping the directory at index 0
|
|
HandleBrowserTap(bm, state, 0)
|
|
|
|
if state.CurrentPath != "/root/sub" {
|
|
t.Errorf("expected CurrentPath='/root/sub', got %s", state.CurrentPath)
|
|
}
|
|
}
|
|
|
|
// TestTapUp verifies that tapping a ".." entry updates the
|
|
// BrowserState.CurrentPath to the parent directory.
|
|
func TestTapUp(t *testing.T) {
|
|
state := NewBrowserState()
|
|
fs := mock.NewFileSystem()
|
|
wp := pool.NewWorkerPool(1)
|
|
bm, _ := NewBrowserManager(state, wp, fs)
|
|
state.CurrentPath = "/root/sub"
|
|
|
|
// Mock entries: ".." and a file
|
|
entries := []Entry{
|
|
NewEntry("/root", "..", 0, time.Time{}, true),
|
|
NewEntry("/root/sub/file.txt", "file.txt", 100, time.Time{}, false),
|
|
}
|
|
state.Pages[0] = NewPage(0, entries)
|
|
state.TotalEntries = 2
|
|
|
|
// Simulate tapping the ".." entry at index 0
|
|
HandleBrowserTap(bm, state, 0)
|
|
|
|
if state.CurrentPath != "/root" {
|
|
t.Errorf("expected CurrentPath='/root', got %s", state.CurrentPath)
|
|
}
|
|
}
|