-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IMPROVEMENT-26: List title should show the command which is going to …
…be executed (#27) IMPROVEMENT-26: List title should show the command which is going to be executed
- Loading branch information
1 parent
6485108
commit cd374a3
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) | ||
} |