Skip to content

Commit 7dde8ae

Browse files
committed
test: verify initial file path positions cursor on file in parent directory
1 parent 72b9683 commit 7dde8ae

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/internal/model_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,37 @@ func TestBasic(t *testing.T) {
9595
})
9696
}
9797

98+
func TestInitialFilePathPositionsCursor(t *testing.T) {
99+
curTestDir := filepath.Join(testDir, "TestInitialFilePathPositionsCursor")
100+
dir1 := filepath.Join(curTestDir, "dir1")
101+
file1 := filepath.Join(dir1, "file1.txt")
102+
103+
utils.SetupDirectories(t, curTestDir, dir1)
104+
utils.SetupFiles(t, file1)
105+
t.Cleanup(func() { _ = os.RemoveAll(curTestDir) })
106+
107+
// Initialize model with a file path; cursor should land on that file
108+
m := defaultTestModel(file1)
109+
110+
// Populate elements for the panel and apply target cursor
111+
m.getFilePanelItems()
112+
113+
panel := m.getFocusedFilePanel()
114+
require.Equal(t, dir1, panel.location, "Panel should open on parent directory")
115+
require.NotEmpty(t, panel.element, "Panel elements should be populated")
116+
117+
// Find file in the element list and compare with cursor index
118+
targetIdx := -1
119+
for i, el := range panel.element {
120+
if el.name == filepath.Base(file1) {
121+
targetIdx = i
122+
break
123+
}
124+
}
125+
require.NotEqual(t, -1, targetIdx, "Target file must exist in panel elements")
126+
assert.Equal(t, targetIdx, panel.cursor, "Cursor should point to the target file")
127+
}
128+
98129
func TestQuit(t *testing.T) {
99130
// Test
100131
// 1 - Normal quit

0 commit comments

Comments
 (0)