mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
test: add group selection test
This commit is contained in:
@@ -291,8 +291,6 @@ func (m *model_ca) TempAddAuthor() {
|
|||||||
parent_m.list.InsertItem(len(parent_m.list.Items())+1, item(item_str))
|
parent_m.list.InsertItem(len(parent_m.list.Items())+1, item(item_str))
|
||||||
selectToggle(i)
|
selectToggle(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// func Entry_CA() string {
|
// func Entry_CA() string {
|
||||||
|
|||||||
+69
-28
@@ -3,6 +3,7 @@ package tui
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ 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")
|
utils.Define_users("author_file_test")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,13 +112,16 @@ func TestEntryTA(t *testing.T) {
|
|||||||
t.Errorf("Expected 3 inputs, got %d", len(m.list.Items()))
|
t.Errorf("Expected 3 inputs, got %d", len(m.list.Items()))
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: read from utils.Users instead
|
item := string(m.list.Items()[len(m.list.Items())-1].(item))
|
||||||
// if m.inputs[0].Value() != "test" {
|
split := strings.Split(item, " - ")
|
||||||
// t.Errorf("Expected 'test', got %s", m.inputs[0].Value())
|
|
||||||
// }
|
if split[0] != "test" {
|
||||||
// if m.inputs[1].Value() != "testtest@temp.io" {
|
t.Errorf("Expected 'test', got %s", split[0])
|
||||||
// t.Errorf("Expected 'testtest@temp.io', got %s", m.inputs[1].Value())
|
}
|
||||||
// }
|
|
||||||
|
if split[1] != "testtest@temp.io" {
|
||||||
|
t.Errorf("Expected 'testtest@temp.io', got %s", split[1])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_EntryCA(t *testing.T) {
|
func Test_EntryCA(t *testing.T) {
|
||||||
@@ -142,7 +146,7 @@ func Test_EntryCA(t *testing.T) {
|
|||||||
Runes: []rune("enter"),
|
Runes: []rune("enter"),
|
||||||
})
|
})
|
||||||
|
|
||||||
tm.Type("testtest")
|
tm.Type("testing2")
|
||||||
tm.Send(tea.KeyMsg{
|
tm.Send(tea.KeyMsg{
|
||||||
Type: tea.KeyRunes,
|
Type: tea.KeyRunes,
|
||||||
Runes: []rune("enter"),
|
Runes: []rune("enter"),
|
||||||
@@ -185,33 +189,32 @@ func Test_EntryCA(t *testing.T) {
|
|||||||
fm := tm.FinalModel(t)
|
fm := tm.FinalModel(t)
|
||||||
m, ok := fm.(model)
|
m, ok := fm.(model)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("Expected model_ca, got %T", fm)
|
t.Errorf("Expected model, got %T", fm)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(m.list.Items()) != 3 {
|
if len(m.list.Items()) != 3 {
|
||||||
t.Errorf("Expected 3 inputs, got %d\n%v", len(m.list.Items()), m.list.Items())
|
t.Errorf("Expected 3 inputs, got %d\n%v", len(m.list.Items()), m.list.Items())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Change this to use the file instead to read and compare
|
|
||||||
// if m.list.Items()[len(m.list.Items())] != "test" {
|
//TODO: For some reason the test is not writing to the author file despite working in the actual program
|
||||||
// t.Errorf("Expected 'test', got %s", m.inputs[0].Value())
|
// var user utils.User
|
||||||
|
// utils.Define_users("author_file_test")
|
||||||
|
// data, _ := os.ReadFile("author_file_test")
|
||||||
|
// t.Errorf("Data: %s", data)
|
||||||
|
|
||||||
|
// if _, ok := utils.Users["test"]; !ok {
|
||||||
|
// t.Errorf("Expected 'testing2' to be in the users map")
|
||||||
// }
|
// }
|
||||||
// if m.inputs[1].Value() != "testtest" {
|
|
||||||
// t.Errorf("Expected 'testtest', got %s", m.inputs[1].Value())
|
// user = utils.Users["testing2"]
|
||||||
|
|
||||||
|
// if user.Username != "TestUser" {
|
||||||
|
// t.Errorf("Expected 'TestUser', got %s", user.Username)
|
||||||
// }
|
// }
|
||||||
// if m.inputs[2].Value() != "TestUser" {
|
|
||||||
// t.Errorf("Expected 'TestUser', got %s", m.inputs[2].Value())
|
// if user.Email != "test@temp.io" {
|
||||||
// }
|
// t.Errorf("Expected 'test@temp.io', got %s", user.Email)
|
||||||
// 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)
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -395,3 +398,41 @@ func Test_EntryDeleteAuthor(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// tui_list TESTS END
|
// tui_list TESTS END
|
||||||
|
|
||||||
|
// tui_groups TESTS BEGIN
|
||||||
|
|
||||||
|
func Test_GroupSelection(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
m := listModel()
|
||||||
|
tm := teatest.NewTestModel(
|
||||||
|
t, m, teatest.WithInitialTermSize(300, 300),
|
||||||
|
)
|
||||||
|
tm.Send(tea.KeyMsg{
|
||||||
|
Type: tea.KeyRunes,
|
||||||
|
Runes: []rune("f"),
|
||||||
|
})
|
||||||
|
|
||||||
|
tm.Send(tea.KeyMsg{
|
||||||
|
Type: tea.KeyRunes,
|
||||||
|
Runes: []rune("enter"),
|
||||||
|
})
|
||||||
|
|
||||||
|
tm.Send(tea.KeyMsg{
|
||||||
|
Type: tea.KeyRunes,
|
||||||
|
Runes: []rune("enter"),
|
||||||
|
})
|
||||||
|
|
||||||
|
fm := tm.FinalModel(t)
|
||||||
|
m, ok := fm.(model)
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("Expected model, got %T", fm)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(selected) != 1 {
|
||||||
|
t.Errorf("Expected 1 selected item, got %d", len(selected))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// tui_groups TESTS END
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ var Groups = map[string][]User{}
|
|||||||
func Define_users(author_file string) {
|
func Define_users(author_file string) {
|
||||||
// wipe the users map
|
// wipe the users map
|
||||||
Users = map[string]User{}
|
Users = map[string]User{}
|
||||||
|
DefExclude = []string{}
|
||||||
|
Groups = map[string][]User{}
|
||||||
|
|
||||||
file, err := os.Open(author_file)
|
file, err := os.Open(author_file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user