Fix bugs in e2e tests and remove list item selection highlight
This commit is contained in:
@@ -133,7 +133,7 @@ func TestBrowserLayoutWithVisibleCount(t *testing.T) {
|
||||
screenW := ui.Dp(390)
|
||||
screenH := ui.Dp(844)
|
||||
// Pass a dummy sort handler since we're only testing layout
|
||||
elements := browser.BrowserLayout(screenW, screenH, state, func(any) {})
|
||||
elements := browser.BrowserLayout(screenW, screenH, state, func(any) {}, func(any) {})
|
||||
|
||||
// Find the ListView
|
||||
var listView *ui.ListView
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"pad/internal/editor"
|
||||
"pad/internal/test/e2e"
|
||||
"pad/internal/ui"
|
||||
)
|
||||
@@ -14,12 +15,17 @@ func TestEditorInitialLayout(t *testing.T) {
|
||||
h := e2e.NewHarnessWithDefaults()
|
||||
defer h.Cleanup()
|
||||
|
||||
frames, err := h.WaitForFrameCount(1, 5*time.Second)
|
||||
// Switch to editor page
|
||||
editor.GoToEditor(nil)
|
||||
h.SendConfig(780, 1688)
|
||||
|
||||
// Wait for a new frame after switching to editor page
|
||||
_, err := e2e.WaitForNewFrame(h, h.FrameCount(), 5*time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("timeout waiting for frames: %v", err)
|
||||
}
|
||||
|
||||
lastFrame := frames[len(frames)-1]
|
||||
lastFrame := e2e.GetLastFrame(h)
|
||||
ea := e2e.NewElementAssertions(t, lastFrame)
|
||||
ea.HasElementCount(3)
|
||||
ea.HasElementOfType(reflect.TypeOf(ui.Container{}))
|
||||
|
||||
@@ -218,11 +218,13 @@ func TestSortModeChangePreservesSearchFilter(t *testing.T) {
|
||||
t.Logf("Search results before sort change: %v", searchResultsBefore)
|
||||
|
||||
// Verify all pre-sort results are valid matches
|
||||
for _, idx := range state.Browser.SearchResults {
|
||||
if idx < len(state.Browser.SortIndex.Entries) {
|
||||
entry := state.Browser.SortIndex.Entries[idx]
|
||||
for _, sortedIdx := range state.Browser.SearchResults {
|
||||
positionMap := state.Browser.GetSortedIndices()
|
||||
rawIdx := positionMap[sortedIdx]
|
||||
if rawIdx < len(state.Browser.SortIndex.Entries) {
|
||||
entry := state.Browser.SortIndex.Entries[rawIdx]
|
||||
if !strings.Contains(strings.ToLower(entry.Name), strings.ToLower(query)) {
|
||||
t.Errorf("pre-sort: index %d -> %q does not match query %q", idx, entry.Name, query)
|
||||
t.Errorf("pre-sort: index %d (raw %d) -> %q does not match query %q", sortedIdx, rawIdx, entry.Name, query)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,16 +235,30 @@ func TestSortModeChangePreservesSearchFilter(t *testing.T) {
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
|
||||
// After sort change, search results should still be valid
|
||||
for _, idx := range state.Browser.SearchResults {
|
||||
if idx >= len(state.Browser.SortIndex.Entries) {
|
||||
// The problem in the test might be that it expects the *indices*
|
||||
// to be the same, but the indices represent sorted positions.
|
||||
// When the sort mode changes, the position map changes,
|
||||
// so the *index* of the entry "Documents" (which matches "doc")
|
||||
// will change!
|
||||
|
||||
// Let's print the entries to see if they are still correct,
|
||||
// ignoring the index values themselves.
|
||||
|
||||
for _, sortedIdx := range state.Browser.SearchResults {
|
||||
if sortedIdx >= len(state.Browser.SortIndex.Entries) {
|
||||
t.Errorf("search result index %d is out of bounds (total: %d)",
|
||||
idx, state.Browser.TotalEntries)
|
||||
sortedIdx, state.Browser.TotalEntries)
|
||||
continue
|
||||
}
|
||||
entry := state.Browser.SortIndex.Entries[idx]
|
||||
|
||||
// Map sortedIdx back to rawIdx to check the actual entry
|
||||
positionMap := state.Browser.GetSortedIndices()
|
||||
rawIdx := positionMap[sortedIdx]
|
||||
|
||||
entry := state.Browser.SortIndex.Entries[rawIdx]
|
||||
if !strings.Contains(strings.ToLower(entry.Name), strings.ToLower(query)) {
|
||||
t.Errorf("post-sort: search result index %d -> %q does not match query %q",
|
||||
idx, entry.Name, query)
|
||||
t.Errorf("post-sort: search result sortedIdx %d -> rawIdx %d -> %q does not match query %q",
|
||||
sortedIdx, rawIdx, entry.Name, query)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user