Skip to content

Commit

Permalink
IMPROVEMENT-26: List title should show the command which is going to …
Browse files Browse the repository at this point in the history
…be executed (#27)

IMPROVEMENT-26: List title should show the command which is going to be executed
  • Loading branch information
grafviktor authored Dec 2, 2023
1 parent 6485108 commit cd374a3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/ui/component/hostlist/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (m listModel) listTitleUpdate(msg tea.Msg) listModel {
return m
}

m.innerModel.Title = fmt.Sprintf("goto: %s", item.Unwrap().Address)
m.innerModel.Title = ssh.ConstructCMD("ssh", utils.HostModelToOptionsAdaptor(*item.Unwrap())...)

return m
}
Expand Down
47 changes: 47 additions & 0 deletions internal/ui/component/hostlist/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Package hostlist implements the host list view.
package hostlist

import (
"errors"
"testing"

"github.com/charmbracelet/bubbles/list"
"github.com/stretchr/testify/require"

"github.com/grafviktor/goto/internal/model"
)

func TestListTitleUpdate(t *testing.T) {
// List title should show error message if error happened
t.Run("Error Message", func(t *testing.T) {
errMsg := errors.New("test error")
msg := msgErrorOccured{err: errMsg}
model := listModel{innerModel: list.New([]list.Item{}, list.NewDefaultDelegate(), 0, 0)}
newModel := model.listTitleUpdate(msg)

if newModel.innerModel.Title != errMsg.Error() {
t.Errorf("Expected title to be %q, but got %q", errMsg.Error(), newModel.innerModel.Title)
}
})

t.Run("Focus Changed Message", func(t *testing.T) {
// Create a new host
h := model.NewHost(0, "", "", "localhost", "root", "id_rsa", "2222")

// Create items
items := []list.Item{ListItemHost{h}}

// Create a lm with initial state
lm := listModel{innerModel: list.New(items, list.NewDefaultDelegate(), 0, 0)}

// Select host
lm.innerModel.Select(0)

// Create a message of type msgFocusChanged
msg := msgFocusChanged{}
// Apply the function
lm = lm.listTitleUpdate(msg)

require.Equal(t, lm.innerModel.Title, "ssh localhost -l root -p 2222 -i id_rsa")
})
}

0 comments on commit cd374a3

Please sign in to comment.