diff --git a/src/cmd/tui/tui_test.go b/src/cmd/tui/tui_test.go index 8fd2e91..852814f 100644 --- a/src/cmd/tui/tui_test.go +++ b/src/cmd/tui/tui_test.go @@ -25,13 +25,17 @@ func setup() { } os.Setenv("author_file", "author_file_test") envVar = os.Getenv("author_file") + + utils.Define_users("author_file_test") } func teardown() { // remove test data os.Remove("author_file_test") os.Setenv("author_file", envVar) + } + // tui_show_users TESTS BEGIN func TestShowUser(t *testing.T) { setup() @@ -62,10 +66,17 @@ func TestEntryTA(t *testing.T) { setup() defer teardown() - m := initialModel("temp") + m := listModel() + + // m := tempAuthorModel(&old_m) tm := teatest.NewTestModel( t, m, teatest.WithInitialTermSize(300, 300), ) + tm.Send(tea.KeyMsg{ + Type: tea.KeyRunes, + Runes: []rune("T"), + }) + tm.Type("test") tm.Send(tea.KeyMsg{ @@ -85,31 +96,45 @@ func TestEntryTA(t *testing.T) { Runes: []rune("enter"), }) + tm.Send(tea.KeyMsg{ + Type: tea.KeyRunes, + Runes: []rune("esc"), + }) + fm := tm.FinalModel(t) - m, ok := fm.(model_ca) + m, ok := fm.(model) if !ok { t.Errorf("Expected model_ca, got %T", fm) } - if len(m.inputs) != 2 { - t.Errorf("Expected 2 inputs, got %d", len(m.inputs)) - } - 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()) + if len(m.list.Items()) != 3 { + t.Errorf("Expected 3 inputs, got %d", len(m.list.Items())) } + + //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) { setup() defer teardown() - m := initialModel("author") + m := listModel() + + // mm := createAuthorModel(&m) tm := teatest.NewTestModel( t, m, teatest.WithInitialTermSize(300, 300), ) + tm.Send(tea.KeyMsg{ + Type: tea.KeyRunes, + Runes: []rune("C"), + }) + tm.Type("test") tm.Send(tea.KeyMsg{ @@ -123,11 +148,11 @@ func Test_EntryCA(t *testing.T) { Runes: []rune("enter"), }) - tm.Type ("TestUser") + tm.Type("TestUser") tm.Send(tea.KeyMsg{ Type: tea.KeyRunes, Runes: []rune("enter"), - }) + }) tm.Type("test@temp.io") tm.Send(tea.KeyMsg{ @@ -152,37 +177,45 @@ func Test_EntryCA(t *testing.T) { Type: tea.KeyRunes, Runes: []rune("enter"), }) + tm.Send(tea.KeyMsg{ + Type: tea.KeyRunes, + Runes: []rune("esc"), + }) fm := tm.FinalModel(t) - m, ok := fm.(model_ca) + m, ok := fm.(model) if !ok { t.Errorf("Expected model_ca, got %T", fm) } - if len(m.inputs) != 5 { - t.Errorf("Expected 5 inputs, got %d", len(m.inputs)) - } - 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) + if len(m.list.Items()) != 3 { + 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" { + // 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_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()) } } -// tui_commit_message TESTS END +// tui_commit_message TESTS END // tui_list TESTS BEGIN func Test_EntrySelectUsers(t *testing.T) { @@ -282,7 +315,7 @@ func Test_EntrySelectAll(t *testing.T) { } 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)) } } -// tui_list TESTS END \ No newline at end of file + +// tui_list TESTS END diff --git a/src/cmd/utils/user_util.go b/src/cmd/utils/user_util.go index e5ded0e..258051b 100644 --- a/src/cmd/utils/user_util.go +++ b/src/cmd/utils/user_util.go @@ -18,6 +18,9 @@ var DefExclude = []string{} var Groups = map[string][]User{} func Define_users(author_file string) { + // wipe the users map + Users = map[string]User{} + file, err := os.Open(author_file) if err != nil { print("File not found")