mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
test: fix the tui tests with the new model structure
This commit is contained in:
+70
-36
@@ -25,13 +25,17 @@ func setup() {
|
|||||||
}
|
}
|
||||||
os.Setenv("author_file", "author_file_test")
|
os.Setenv("author_file", "author_file_test")
|
||||||
envVar = os.Getenv("author_file")
|
envVar = os.Getenv("author_file")
|
||||||
|
|
||||||
|
utils.Define_users("author_file_test")
|
||||||
}
|
}
|
||||||
|
|
||||||
func teardown() {
|
func teardown() {
|
||||||
// remove test data
|
// remove test data
|
||||||
os.Remove("author_file_test")
|
os.Remove("author_file_test")
|
||||||
os.Setenv("author_file", envVar)
|
os.Setenv("author_file", envVar)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tui_show_users TESTS BEGIN
|
// tui_show_users TESTS BEGIN
|
||||||
func TestShowUser(t *testing.T) {
|
func TestShowUser(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
@@ -62,10 +66,17 @@ func TestEntryTA(t *testing.T) {
|
|||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
m := initialModel("temp")
|
m := listModel()
|
||||||
|
|
||||||
|
// m := tempAuthorModel(&old_m)
|
||||||
tm := teatest.NewTestModel(
|
tm := teatest.NewTestModel(
|
||||||
t, m, teatest.WithInitialTermSize(300, 300),
|
t, m, teatest.WithInitialTermSize(300, 300),
|
||||||
)
|
)
|
||||||
|
tm.Send(tea.KeyMsg{
|
||||||
|
Type: tea.KeyRunes,
|
||||||
|
Runes: []rune("T"),
|
||||||
|
})
|
||||||
|
|
||||||
tm.Type("test")
|
tm.Type("test")
|
||||||
|
|
||||||
tm.Send(tea.KeyMsg{
|
tm.Send(tea.KeyMsg{
|
||||||
@@ -85,31 +96,45 @@ func TestEntryTA(t *testing.T) {
|
|||||||
Runes: []rune("enter"),
|
Runes: []rune("enter"),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tm.Send(tea.KeyMsg{
|
||||||
|
Type: tea.KeyRunes,
|
||||||
|
Runes: []rune("esc"),
|
||||||
|
})
|
||||||
|
|
||||||
fm := tm.FinalModel(t)
|
fm := tm.FinalModel(t)
|
||||||
m, ok := fm.(model_ca)
|
m, ok := fm.(model)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("Expected model_ca, got %T", fm)
|
t.Errorf("Expected model_ca, got %T", fm)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(m.inputs) != 2 {
|
if len(m.list.Items()) != 3 {
|
||||||
t.Errorf("Expected 2 inputs, got %d", len(m.inputs))
|
t.Errorf("Expected 3 inputs, got %d", len(m.list.Items()))
|
||||||
}
|
|
||||||
if m.inputs[0].Value() != "test" {
|
|
||||||
t.Errorf("Expected 'test', got %s", m.inputs[0].Value())
|
|
||||||
}
|
|
||||||
if m.inputs[1].Value() != "testtest@temp.io" {
|
|
||||||
t.Errorf("Expected 'testtest@temp.io', got %s", m.inputs[1].Value())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: read from utils.Users instead
|
||||||
|
// if m.inputs[0].Value() != "test" {
|
||||||
|
// t.Errorf("Expected 'test', got %s", m.inputs[0].Value())
|
||||||
|
// }
|
||||||
|
// if m.inputs[1].Value() != "testtest@temp.io" {
|
||||||
|
// t.Errorf("Expected 'testtest@temp.io', got %s", m.inputs[1].Value())
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_EntryCA(t *testing.T) {
|
func Test_EntryCA(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
m := initialModel("author")
|
m := listModel()
|
||||||
|
|
||||||
|
// mm := createAuthorModel(&m)
|
||||||
tm := teatest.NewTestModel(
|
tm := teatest.NewTestModel(
|
||||||
t, m, teatest.WithInitialTermSize(300, 300),
|
t, m, teatest.WithInitialTermSize(300, 300),
|
||||||
)
|
)
|
||||||
|
tm.Send(tea.KeyMsg{
|
||||||
|
Type: tea.KeyRunes,
|
||||||
|
Runes: []rune("C"),
|
||||||
|
})
|
||||||
|
|
||||||
tm.Type("test")
|
tm.Type("test")
|
||||||
|
|
||||||
tm.Send(tea.KeyMsg{
|
tm.Send(tea.KeyMsg{
|
||||||
@@ -152,37 +177,45 @@ func Test_EntryCA(t *testing.T) {
|
|||||||
Type: tea.KeyRunes,
|
Type: tea.KeyRunes,
|
||||||
Runes: []rune("enter"),
|
Runes: []rune("enter"),
|
||||||
})
|
})
|
||||||
|
tm.Send(tea.KeyMsg{
|
||||||
|
Type: tea.KeyRunes,
|
||||||
|
Runes: []rune("esc"),
|
||||||
|
})
|
||||||
|
|
||||||
fm := tm.FinalModel(t)
|
fm := tm.FinalModel(t)
|
||||||
m, ok := fm.(model_ca)
|
m, ok := fm.(model)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("Expected model_ca, got %T", fm)
|
t.Errorf("Expected model_ca, got %T", fm)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(m.inputs) != 5 {
|
if len(m.list.Items()) != 3 {
|
||||||
t.Errorf("Expected 5 inputs, got %d", len(m.inputs))
|
t.Errorf("Expected 3 inputs, got %d\n%v", len(m.list.Items()), m.list.Items())
|
||||||
}
|
|
||||||
if m.inputs[0].Value() != "test" {
|
|
||||||
t.Errorf("Expected 'test', got %s", m.inputs[0].Value())
|
|
||||||
}
|
|
||||||
if m.inputs[1].Value() != "testtest" {
|
|
||||||
t.Errorf("Expected 'testtest', got %s", m.inputs[1].Value())
|
|
||||||
}
|
|
||||||
if m.inputs[2].Value() != "TestUser" {
|
|
||||||
t.Errorf("Expected 'TestUser', got %s", m.inputs[2].Value())
|
|
||||||
}
|
|
||||||
if m.inputs[3].Value() != "test@temp.io" {
|
|
||||||
t.Errorf("Expected 'test@temp.io', got %s", m.inputs[2].Value())
|
|
||||||
}
|
|
||||||
if m.inputs[4].Value() != "gr1" {
|
|
||||||
t.Errorf("Expected 'gr1', got %s", m.inputs[4].Value())
|
|
||||||
}
|
|
||||||
//No clue why the exclude tag isn't working fix later
|
|
||||||
//TODO: Fix this should be !m.exclude
|
|
||||||
if m.exclude {
|
|
||||||
t.Errorf("Expected exclude to be true, got %v", m.exclude)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Change this to use the file instead to read and compare
|
||||||
|
// if m.list.Items()[len(m.list.Items())] != "test" {
|
||||||
|
// t.Errorf("Expected 'test', got %s", m.inputs[0].Value())
|
||||||
|
// }
|
||||||
|
// if m.inputs[1].Value() != "testtest" {
|
||||||
|
// t.Errorf("Expected 'testtest', got %s", m.inputs[1].Value())
|
||||||
|
// }
|
||||||
|
// if m.inputs[2].Value() != "TestUser" {
|
||||||
|
// t.Errorf("Expected 'TestUser', got %s", m.inputs[2].Value())
|
||||||
|
// }
|
||||||
|
// if m.inputs[3].Value() != "test@temp.io" {
|
||||||
|
// t.Errorf("Expected 'test@temp.io', got %s", m.inputs[2].Value())
|
||||||
|
// }
|
||||||
|
// if m.inputs[4].Value() != "gr1" {
|
||||||
|
// t.Errorf("Expected 'gr1', got %s", m.inputs[4].Value())
|
||||||
|
// }
|
||||||
|
// //No clue why the exclude tag isn't working fix later
|
||||||
|
// //TODO: Fix this should be !m.exclude
|
||||||
|
// if m.exclude {
|
||||||
|
// t.Errorf("Expected exclude to be true, got %v", m.exclude)
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tui_author TESTS END
|
// tui_author TESTS END
|
||||||
|
|
||||||
// tui_commit_message TESTS BEGIN
|
// tui_commit_message TESTS BEGIN
|
||||||
@@ -211,8 +244,8 @@ func Test_EntryCM(t *testing.T) {
|
|||||||
t.Errorf("Expected 'test commit message', got %s", m.textarea.Value())
|
t.Errorf("Expected 'test commit message', got %s", m.textarea.Value())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// tui_commit_message TESTS END
|
|
||||||
|
|
||||||
|
// tui_commit_message TESTS END
|
||||||
|
|
||||||
// tui_list TESTS BEGIN
|
// tui_list TESTS BEGIN
|
||||||
func Test_EntrySelectUsers(t *testing.T) {
|
func Test_EntrySelectUsers(t *testing.T) {
|
||||||
@@ -282,7 +315,7 @@ func Test_EntrySelectAll(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(selected) != 2 {
|
if len(selected) != 2 {
|
||||||
t.Errorf("Expected 2 selected item, got %d", len(selected))
|
t.Errorf("Expected 2 selected item, got %d\n%v", len(selected), selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,4 +393,5 @@ func Test_EntryDeleteAuthor(t *testing.T) {
|
|||||||
t.Errorf("Expected 2 user after deletion, got %d", len(utils.Users))
|
t.Errorf("Expected 2 user after deletion, got %d", len(utils.Users))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tui_list TESTS END
|
// tui_list TESTS END
|
||||||
@@ -18,6 +18,9 @@ var DefExclude = []string{}
|
|||||||
var Groups = map[string][]User{}
|
var Groups = map[string][]User{}
|
||||||
|
|
||||||
func Define_users(author_file string) {
|
func Define_users(author_file string) {
|
||||||
|
// wipe the users map
|
||||||
|
Users = map[string]User{}
|
||||||
|
|
||||||
file, err := os.Open(author_file)
|
file, err := os.Open(author_file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print("File not found")
|
print("File not found")
|
||||||
|
|||||||
Reference in New Issue
Block a user