(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestFilePanelNavigation(t *testing.T) { |
| 19 | /* |
| 20 | We want to test |
| 21 | (1) Switching to parent directory |
| 22 | (2) Switching to parent on being at root "/" |
| 23 | (3) Entering current directory |
| 24 | (4) Entering via cd / command |
| 25 | (5) Cd to itself via cd . command |
| 26 | |
| 27 | Make sure to validate |
| 28 | - Search bar is cleared |
| 29 | - The cursor and render values are restored correctly |
| 30 | */ |
| 31 | |
| 32 | curTestDir := t.TempDir() |
| 33 | dir1 := filepath.Join(curTestDir, "dir1") |
| 34 | dir2 := filepath.Join(curTestDir, "dir2") |
| 35 | file1 := filepath.Join(curTestDir, "file1.txt") |
| 36 | // We >=3 files in dir1 and >=2 files in dir2 |
| 37 | // so that cursor=2, and cursor=1 are valid values. |
| 38 | file2 := filepath.Join(dir1, "file2.txt") |
| 39 | file3 := filepath.Join(dir1, "file3.txt") |
| 40 | file4 := filepath.Join(dir1, "file4.txt") |
| 41 | file5 := filepath.Join(dir2, "file5.txt") |
| 42 | file6 := filepath.Join(dir2, "file6.txt") |
| 43 | |
| 44 | rootDir := "/" |
| 45 | |
| 46 | if runtime.GOOS == utils.OsWindows { |
| 47 | rootDir = "\\" |
| 48 | } |
| 49 | |
| 50 | utils.SetupDirectories(t, dir1, dir2) |
| 51 | utils.SetupFiles(t, file1, file2, file3, file4, file5, file6) |
| 52 | |
| 53 | testdata := []struct { |
| 54 | name string |
| 55 | startDir string |
| 56 | resultDir string |
| 57 | startCursor int |
| 58 | keyInput []string |
| 59 | searchBarClear bool |
| 60 | }{ |
| 61 | { |
| 62 | name: "Switch to parent", |
| 63 | startDir: dir1, |
| 64 | resultDir: curTestDir, |
| 65 | startCursor: 1, |
| 66 | keyInput: []string{ |
| 67 | common.Hotkeys.ParentDirectory[0], |
| 68 | }, |
| 69 | searchBarClear: true, |
| 70 | }, |
| 71 | { |
| 72 | name: "Switch to parent when at root", |
| 73 | startDir: rootDir, |
| 74 | resultDir: rootDir, |
| 75 | startCursor: 0, |
nothing calls this directly
no test coverage detected