mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-23 14:01:00 +01:00
Add test to confirm that window resizing works
This commit is contained in:
parent
ebfdaa7a4a
commit
c0bd577084
@ -1870,7 +1870,7 @@ func TestTui(t *testing.T) {
|
||||
|
||||
// Check the output when the size is smaller
|
||||
out = captureTerminalOutputWithShellNameAndDimensions(t, tester, tester.ShellName(), 100, 20, []TmuxCommand{
|
||||
TmuxCommand{Keys: "hishtory SPACE tquery ENTER"},
|
||||
{Keys: "hishtory SPACE tquery ENTER"},
|
||||
})
|
||||
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
|
||||
compareGoldens(t, out, "TestTui-SmallTerminal")
|
||||
@ -1896,6 +1896,15 @@ func TestTui(t *testing.T) {
|
||||
if !testutils.IsGithubAction() {
|
||||
compareGoldens(t, out, "TestTui-Exit")
|
||||
}
|
||||
|
||||
// Check that it resizes after the terminal size is adjusted
|
||||
testutils.Check(t, db.Create(testutils.MakeFakeHistoryEntry("echo 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'")).Error)
|
||||
out = captureTerminalOutputWithShellNameAndDimensions(t, tester, tester.ShellName(), 100, 20, []TmuxCommand{
|
||||
{Keys: "hishtory SPACE tquery ENTER"},
|
||||
{ResizeX: 300, ResizeY: 100},
|
||||
})
|
||||
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
|
||||
compareGoldens(t, out, "TestTui-Resize")
|
||||
}
|
||||
|
||||
func captureTerminalOutput(t *testing.T, tester shellTester, commands []string) string {
|
||||
@ -1904,6 +1913,8 @@ func captureTerminalOutput(t *testing.T, tester shellTester, commands []string)
|
||||
|
||||
type TmuxCommand struct {
|
||||
Keys string
|
||||
ResizeX int
|
||||
ResizeY int
|
||||
}
|
||||
|
||||
func captureTerminalOutputWithShellName(t *testing.T, tester shellTester, overriddenShellName string, commands []string) string {
|
||||
@ -1914,8 +1925,6 @@ func captureTerminalOutputWithShellName(t *testing.T, tester shellTester, overri
|
||||
return captureTerminalOutputWithShellNameAndDimensions(t, tester, overriddenShellName, 200, 50, sCommands)
|
||||
}
|
||||
|
||||
// TODO: add tests for auto-resizing. They can use the tmux resize-pane command
|
||||
|
||||
func captureTerminalOutputWithShellNameAndDimensions(t *testing.T, tester shellTester, overriddenShellName string, width, height int, commands []TmuxCommand) string {
|
||||
sleepAmount := "0.1"
|
||||
if runtime.GOOS == "linux" {
|
||||
@ -1937,9 +1946,14 @@ func captureTerminalOutputWithShellNameAndDimensions(t *testing.T, tester shellT
|
||||
}
|
||||
fullCommand += " sleep " + sleepAmount + "\n"
|
||||
for _, cmd := range commands {
|
||||
if cmd.Keys != "" {
|
||||
fullCommand += " tmux send -t foo -- "
|
||||
fullCommand += cmd.Keys
|
||||
fullCommand += "\n"
|
||||
}
|
||||
if cmd.ResizeX != 0 && cmd.ResizeY != 0 {
|
||||
fullCommand += fmt.Sprintf(" tmux resize-window -t foo -x %d -y %d\n", cmd.ResizeX, cmd.ResizeY)
|
||||
}
|
||||
fullCommand += " sleep " + sleepAmount + "\n"
|
||||
}
|
||||
fullCommand += " sleep 0.5\n"
|
||||
|
26
client/lib/goldens/TestTui-Resize
Normal file
26
client/lib/goldens/TestTui-Resize
Normal file
@ -0,0 +1,26 @@
|
||||
Search Query: > ls
|
||||
|
||||
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname CWD Timestamp Runtime Exit Code Command │
|
||||
│───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:26 PDT 3s 2 echo 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' │
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:21 PDT 3s 2 echo 'aaaaaa bbbb' │
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:16 PDT 3s 2 ls ~/ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
Loading…
Reference in New Issue
Block a user