Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/internal/handle_file_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func setupModelAndPerformOperation(t *testing.T, startDir string, useSelectMode
itemName string, selectedItems []string, isCut bool) *model {
t.Helper()
m := defaultTestModel(startDir)
TeaUpdateWithErrCheck(m, nil)
TeaUpdate(m, nil)

setupPanelModeAndSelection(t, m, useSelectMode, itemName, selectedItems)
performCopyOrCutOperation(t, m, isCut)
Expand Down
6 changes: 3 additions & 3 deletions src/internal/model_file_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ func TestFileCreation(t *testing.T) {
for _, tt := range testdata {
m := defaultTestModel(testChildDir)

TeaUpdateWithErrCheck(m, nil)
TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.FilePanelItemCreate[0]))
TeaUpdate(m, nil)
TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.FilePanelItemCreate[0]))

assert.Empty(t, m.typingModal.errorMesssage)

m.typingModal.textInput.SetValue(tt.fileName)

TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.ConfirmTyping[0]))
TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.ConfirmTyping[0]))

if tt.expectedError {
assert.NotEmpty(t, m.typingModal.errorMesssage, "expected an error for input: %q", tt.fileName)
Expand Down
8 changes: 4 additions & 4 deletions src/internal/model_navigation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestFilePanelNavigation(t *testing.T) {
m.getFocusedFilePanel().render = tt.startRender
m.getFocusedFilePanel().searchBar.SetValue("asdf")
for _, s := range tt.keyInput {
TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(s))
TeaUpdate(m, utils.TeaRuneKeyMsg(s))
}

assert.Equal(t, tt.resultDir, m.getFocusedFilePanel().location)
Expand All @@ -137,9 +137,9 @@ func TestFilePanelNavigation(t *testing.T) {

// Go back to original directory

TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.OpenSPFPrompt[0]))
TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg("cd "+tt.startDir))
TeaUpdateWithErrCheck(m, tea.KeyMsg{Type: tea.KeyEnter})
TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.OpenSPFPrompt[0]))
TeaUpdate(m, utils.TeaRuneKeyMsg("cd "+tt.startDir))
TeaUpdate(m, tea.KeyMsg{Type: tea.KeyEnter})

// Make sure we have original curson and render
assert.Equal(t, tt.startCursor, m.getFocusedFilePanel().cursor)
Expand Down
158 changes: 79 additions & 79 deletions src/internal/model_prompt_test.go

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/internal/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestQuit(t *testing.T) {
t.Run("Normal Quit", func(t *testing.T) {
m := defaultTestModel(testDir)
assert.Equal(t, notQuitting, m.modelQuitState)
cmd := TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.Quit[0]))
cmd := TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.Quit[0]))
assert.Equal(t, quitDone, m.modelQuitState)
assert.True(t, IsTeaQuit(cmd))
})
Expand All @@ -122,23 +122,23 @@ func TestQuit(t *testing.T) {
})

assert.Equal(t, notQuitting, m.modelQuitState)
cmd := TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.Quit[0]))
cmd := TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.Quit[0]))
assert.Equal(t, quitConfirmationInitiated, m.modelQuitState)
assert.False(t, IsTeaQuit(cmd))

// Now we would be asked for confirmation.
// Cancel the quit
cmd = TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.CancelTyping[0]))
cmd = TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.CancelTyping[0]))
assert.Equal(t, notQuitting, m.modelQuitState)
assert.False(t, IsTeaQuit(cmd))

// Again trigger quit
cmd = TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.Quit[0]))
cmd = TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.Quit[0]))
assert.Equal(t, quitConfirmationInitiated, m.modelQuitState)
assert.False(t, IsTeaQuit(cmd))

// Confirm this time
cmd = TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.Confirm[0]))
cmd = TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.Confirm[0]))
assert.Equal(t, quitDone, m.modelQuitState)
assert.True(t, IsTeaQuit(cmd))
})
Expand All @@ -150,7 +150,7 @@ func TestQuit(t *testing.T) {

assert.Equal(t, notQuitting, m.modelQuitState)

cmd := TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.CdQuit[0]))
cmd := TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.CdQuit[0]))

assert.Equal(t, quitDone, m.modelQuitState)
assert.True(t, IsTeaQuit(cmd))
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestChooserFile(t *testing.T) {
require.NoError(t, err)
}
variable.SetChooserFile(tt.chooserFile)
cmd := TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(tt.hotkey))
cmd := TeaUpdate(m, utils.TeaRuneKeyMsg(tt.hotkey))

if tt.expectedQuit {
assert.Equal(t, quitDone, m.modelQuitState)
Expand Down Expand Up @@ -282,12 +282,12 @@ func TestZoxide(t *testing.T) {
require.NoError(t, err, "Failed to navigate to dir3")
assert.Equal(t, dir3, m.getFocusedFilePanel().location, "Should be in dir3 after navigation")

TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.OpenZoxide[0]))
TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.OpenZoxide[0]))
assert.True(t, m.zoxideModal.IsOpen(), "Zoxide modal should open when pressing 'z' key")

// Type "dir2" to search for it
for _, char := range "dir2" {
TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(string(char)))
TeaUpdate(m, utils.TeaRuneKeyMsg(string(char)))
}

results := m.zoxideModal.GetResults()
Expand All @@ -300,7 +300,7 @@ func TestZoxide(t *testing.T) {
assert.Contains(t, resultPaths, dir2, "dir2 should be found by zoxide UI search")

// Press enter to navigate to dir2
TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.ConfirmTyping[0]))
TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.ConfirmTyping[0]))
assert.False(t, m.zoxideModal.IsOpen(), "Zoxide modal should close after navigation")
assert.Equal(t, dir2, m.getFocusedFilePanel().location, "Should navigate back to dir2 after zoxide selection")
})
Expand All @@ -309,7 +309,7 @@ func TestZoxide(t *testing.T) {
common.Config.ZoxideSupport = false
m := defaultTestModelWithZClient(zClient, dir1)

TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.OpenZoxide[0]))
TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.OpenZoxide[0]))
assert.True(t, m.zoxideModal.IsOpen(), "Zoxide modal should open even when ZoxideSupport is disabled")

results := m.zoxideModal.GetResults()
Expand Down
20 changes: 6 additions & 14 deletions src/internal/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const DefaultTestTimeout = time.Second
func defaultTestModel(dirs ...string) *model {
m := defaultModelConfig(false, false, false, dirs, nil)
m.disableMetadata = true
_, _ = TeaUpdate(m, tea.WindowSizeMsg{Width: 2 * common.MinimumWidth, Height: 2 * common.MinimumHeight})
TeaUpdate(m, tea.WindowSizeMsg{Width: 2 * common.MinimumWidth, Height: 2 * common.MinimumHeight})
return m
}

func defaultTestModelWithZClient(zClient *zoxidelib.Client, dirs ...string) *model {
m := defaultModelConfig(false, false, false, dirs, zClient)
m.disableMetadata = true
_, _ = TeaUpdate(m, tea.WindowSizeMsg{Width: 2 * common.MinimumWidth, Height: 2 * common.MinimumHeight})
TeaUpdate(m, tea.WindowSizeMsg{Width: 2 * common.MinimumWidth, Height: 2 * common.MinimumHeight})
return m
}

Expand All @@ -52,17 +52,9 @@ func setupPanelModeAndSelection(t *testing.T, m *model, useSelectMode bool, item

// -------------------- Bubletea utilities

// TeaUpdate : Utility to send update to model , majorly used in tests
// Not using pointer receiver as this is more like a utility, than
// a member function of model
// TODO : Should we validate that returned value is of type *model ?
// and equal to m ? We are assuming that to be true as of now
func TeaUpdate(m *model, msg tea.Msg) (tea.Cmd, error) {
_, cmd := m.Update(msg)
return cmd, nil
}

func TeaUpdateWithErrCheck(m *model, msg tea.Msg) tea.Cmd {
func TeaUpdate(m *model, msg tea.Msg) tea.Cmd {
_, cmd := m.Update(msg)
return cmd
}
Expand Down Expand Up @@ -106,9 +98,9 @@ func ExecuteTeaCmdWithTimeout(cmd tea.Cmd, timeout time.Duration) tea.Msg {
func performCopyOrCutOperation(t *testing.T, m *model, isCut bool) {
t.Helper()
if isCut {
TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.CutItems[0]))
TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.CutItems[0]))
} else {
TeaUpdateWithErrCheck(m, utils.TeaRuneKeyMsg(common.Hotkeys.CopyItems[0]))
TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.CopyItems[0]))
}
}

Expand Down Expand Up @@ -213,7 +205,7 @@ func navigateToTargetDir(t *testing.T, m *model, startDir, targetDir string) {
if targetDir != startDir {
err := m.updateCurrentFilePanelDir(targetDir)
require.NoError(t, err)
TeaUpdateWithErrCheck(m, nil)
TeaUpdate(m, nil)
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/pkg/file_preview/image_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,6 @@ func (p *ImagePreviewer) ImagePreview(path string, maxWidth int, maxHeight int,
// ImagePreviewWithRenderer generates an image preview using the specified renderer
func (p *ImagePreviewer) ImagePreviewWithRenderer(path string, maxWidth int, maxHeight int,
defaultBGColor string, renderer ImageRenderer, sideAreaWidth int) (string, error) {
// Validate dimensions
if maxWidth <= 0 || maxHeight <= 0 {
return "", fmt.Errorf("dimensions must be positive (maxWidth=%d, maxHeight=%d)", maxWidth, maxHeight)
}

info, err := os.Stat(path)
if err != nil {
return "", err
Expand Down
5 changes: 3 additions & 2 deletions src/pkg/file_preview/kitty.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func generateKittyClearCommands() string {
clearPlacementsCmd := "\x1b_Ga=d,p=1\x1b\\"
buf.WriteString(clearPlacementsCmd)

// Add a small delay command to ensure clearing is processed
// Reset text formatting to default
buf.WriteString("\x1b[0m")

return buf.String()
Expand All @@ -94,7 +94,8 @@ func generatePlacementID(path string) uint32 {

// renderWithKittyUsingTermCap renders an image using Kitty graphics protocol with terminal capabilities
func (p *ImagePreviewer) renderWithKittyUsingTermCap(img image.Image, path string,
originalWidth, originalHeight, maxWidth, maxHeight int, sideAreaWidth int) (string, error) {
originalWidth, originalHeight, maxWidth, maxHeight int, sideAreaWidth int,
) (string, error) {
// Validate dimensions
if maxWidth <= 0 || maxHeight <= 0 {
return "", fmt.Errorf("dimensions must be positive (maxWidth=%d, maxHeight=%d)", maxWidth, maxHeight)
Expand Down
2 changes: 1 addition & 1 deletion testsuite/core/tmux_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def start_spf(self, start_dir : str = None, args : list[str] = None) -> None:
self._is_spf_running = True

def _send_key(self, key : str) -> None:
self.logger.debug("sendind key : %s", repr(key))
self.logger.debug("sending key : %s", repr(key))
self.spf_pane.send_keys(key, enter=False)

def send_text_input(self, text : str, all_at_once : bool = True) -> None:
Expand Down
Loading