mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
test: increase test coverage of tui to around 70%
This commit is contained in:
+63
-2
@@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Slug-Boi/cocommit/src/cmd/utils"
|
"github.com/Slug-Boi/cocommit/src/cmd/utils"
|
||||||
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/x/exp/teatest"
|
"github.com/charmbracelet/x/exp/teatest"
|
||||||
)
|
)
|
||||||
@@ -172,7 +173,6 @@ func TestErrorGetMissingFields(t *testing.T) {
|
|||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
|
|
||||||
// Test case 1: No inputs
|
// Test case 1: No inputs
|
||||||
m := createAuthorModel(nil)
|
m := createAuthorModel(nil)
|
||||||
errorGetMissingFields(m)
|
errorGetMissingFields(m)
|
||||||
@@ -316,6 +316,67 @@ func Test_EntryCA(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestModelCAInit(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
m := model_ca{}
|
||||||
|
cmd := m.Init()
|
||||||
|
|
||||||
|
if cmd == nil {
|
||||||
|
t.Errorf("Expected a non-nil command, got nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd() != textinput.Blink() {
|
||||||
|
t.Errorf("Expected textinput.Blink command, got a different command")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TestCreateGHAuthorModel(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
// Define a test user
|
||||||
|
testUser := utils.User{
|
||||||
|
Shortname: "gh",
|
||||||
|
Longname: "GitHubUser",
|
||||||
|
Username: "GitHubUser-gh",
|
||||||
|
Email: "github@user.com",
|
||||||
|
Groups: []string{"grp1", "grp2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the model using the test user
|
||||||
|
m := createGHAuthorModel(nil, testUser)
|
||||||
|
|
||||||
|
// Verify the inputs are correctly initialized
|
||||||
|
if m.inputs[0].Value() != testUser.Shortname {
|
||||||
|
t.Errorf("Expected Shortname '%s', got '%s'", testUser.Shortname, m.inputs[0].Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.inputs[1].Value() != testUser.Longname {
|
||||||
|
t.Errorf("Expected Longname '%s', got '%s'", testUser.Longname, m.inputs[1].Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.inputs[2].Value() != testUser.Username {
|
||||||
|
t.Errorf("Expected Username '%s', got '%s'", testUser.Username, m.inputs[2].Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.inputs[3].Value() != "" {
|
||||||
|
t.Errorf("Expected Email to be empty, got '%s'", m.inputs[3].Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedGroups := strings.Join(testUser.Groups, "|")
|
||||||
|
if m.inputs[4].Value() != expectedGroups {
|
||||||
|
t.Errorf("Expected Groups '%s', got '%s'", expectedGroups, m.inputs[4].Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the first input is focused
|
||||||
|
if !m.inputs[0].Focused() {
|
||||||
|
t.Errorf("Expected first input to be focused")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// tui_author TESTS END
|
// tui_author TESTS END
|
||||||
|
|
||||||
// tui_commit_message TESTS BEGIN
|
// tui_commit_message TESTS BEGIN
|
||||||
@@ -364,6 +425,7 @@ func Test_EntryCM_Quit(t *testing.T) {
|
|||||||
t.Errorf("Expected empty textarea, got %s", m.textarea.Value())
|
t.Errorf("Expected empty textarea, got %s", m.textarea.Value())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cannot test sigkill as it does not play nicely with these types of tests :(
|
// cannot test sigkill as it does not play nicely with these types of tests :(
|
||||||
|
|
||||||
func Test_EntryCM_Unfocuse(t *testing.T) {
|
func Test_EntryCM_Unfocuse(t *testing.T) {
|
||||||
@@ -576,5 +638,4 @@ func Test_pagination(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// tui_groups TESTS END
|
// tui_groups TESTS END
|
||||||
|
|||||||
Reference in New Issue
Block a user