(t *testing.T, onlineStatus OnlineStatus)
| 2064 | } |
| 2065 | |
| 2066 | func testTui_search(t *testing.T, onlineStatus OnlineStatus) { |
| 2067 | // Setup |
| 2068 | defer testutils.BackupAndRestore(t)() |
| 2069 | tester, _, _ := setupTestTui(t, onlineStatus) |
| 2070 | |
| 2071 | // Check hishtory export to confirm the right commands are in the initial set of history entries |
| 2072 | out := tester.RunInteractiveShell(t, `hishtory export`) |
| 2073 | expected := "ls ~/\necho 'aaaaaa bbbb'\n" |
| 2074 | if diff := cmp.Diff(expected, out); diff != "" { |
| 2075 | t.Fatalf("hishtory export mismatch (-expected +got):\n%s", diff) |
| 2076 | } |
| 2077 | |
| 2078 | // Check the output when there is a search |
| 2079 | out = captureTerminalOutput(t, tester, []string{ |
| 2080 | "hishtory SPACE tquery ENTER", |
| 2081 | "ls", |
| 2082 | }) |
| 2083 | out = stripTuiCommandPrefix(t, out) |
| 2084 | testutils.CompareGoldens(t, out, "TestTui-Search") |
| 2085 | |
| 2086 | // Check the output when there is a selected result |
| 2087 | out = captureTerminalOutputWithComplexCommands(t, tester, []TmuxCommand{ |
| 2088 | {Keys: "hishtory SPACE tquery ENTER"}, |
| 2089 | // Extra delay to ensure that the search for 'ls' finishes before we select an entry |
| 2090 | {Keys: "ls", ExtraDelay: 2.0}, |
| 2091 | {Keys: "ENTER"}, |
| 2092 | }) |
| 2093 | out = strings.Split(stripTuiCommandPrefix(t, out), "\n")[0] |
| 2094 | expected = `ls ~/` |
| 2095 | if diff := cmp.Diff(expected, out); diff != "" { |
| 2096 | t.Fatalf("hishtory tquery selection mismatch (-expected +got):\n%s", diff) |
| 2097 | } |
| 2098 | |
| 2099 | // Check the output when the initial search is invalid |
| 2100 | out = captureTerminalOutputWithComplexCommands(t, tester, []TmuxCommand{ |
| 2101 | // ExtraDelay to ensure that after searching for 'foo:' it gets the real results for an empty query |
| 2102 | {Keys: "hishtory SPACE tquery SPACE foo: ENTER", ExtraDelay: 1.5}, |
| 2103 | {Keys: "ls", ExtraDelay: 1.0}, |
| 2104 | }) |
| 2105 | out = stripRequiredPrefix(t, out, "hishtory tquery foo:") |
| 2106 | testutils.CompareGoldens(t, out, "TestTui-InitialInvalidSearch") |
| 2107 | |
| 2108 | // Check the output when the search is invalid |
| 2109 | out = captureTerminalOutputWithComplexCommands(t, tester, []TmuxCommand{ |
| 2110 | {Keys: "hishtory SPACE tquery ENTER", ExtraDelay: 1.0}, |
| 2111 | // ExtraDelay to ensure that the search for 'ls' finishes before we make it invalid by adding ':' |
| 2112 | {Keys: "ls", ExtraDelay: 1.5}, |
| 2113 | {Keys: ":"}, |
| 2114 | }) |
| 2115 | out = stripTuiCommandPrefix(t, out) |
| 2116 | testutils.CompareGoldens(t, out, "TestTui-InvalidSearch") |
| 2117 | |
| 2118 | // Check the output when the search is invalid and then edited to become valid |
| 2119 | out = captureTerminalOutput(t, tester, []string{ |
| 2120 | "hishtory SPACE tquery ENTER", |
| 2121 | "ls: BSpace", |
| 2122 | }) |
| 2123 | out = stripTuiCommandPrefix(t, out) |
no test coverage detected