From 6e2293beb5209100da1403ca5b63c22c8cc393db Mon Sep 17 00:00:00 2001 From: Slug-Boi Date: Sat, 16 Nov 2024 22:17:09 +0100 Subject: [PATCH] refactor: cleanup code --- src/cmd/tui/tui_author.go | 70 +-------------------------------------- src/cmd/tui/tui_list.go | 1 - src/cmd/tui/tui_test.go | 13 +++++--- 3 files changed, 9 insertions(+), 75 deletions(-) diff --git a/src/cmd/tui/tui_author.go b/src/cmd/tui/tui_author.go index acbe804..6213ff1 100644 --- a/src/cmd/tui/tui_author.go +++ b/src/cmd/tui/tui_author.go @@ -290,73 +290,5 @@ func (m *model_ca) TempAddAuthor() { i := item(item_str) parent_m.list.InsertItem(len(parent_m.list.Items())+1, item(item_str)) selectToggle(i) - } + } } - -// func Entry_CA() string { -// m, err := tea.NewProgram(initialModel("author")).Run() -// if err != nil { -// fmt.Printf("could not start program: %s\n", err) -// os.Exit(1) -// } - -// if len(m.(model_ca).inputs) > 0 && -// m.(model_ca).inputs[0].Value() != "" && -// m.(model_ca).inputs[1].Value() != "" && -// m.(model_ca).inputs[2].Value() != "" && -// m.(model_ca).inputs[3].Value() != "" { -// author_file := utils.Find_authorfile() -// f, err := os.OpenFile(author_file, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) -// if err != nil { -// panic(err) -// } - -// defer f.Close() - -// sb := strings.Builder{} -// sb.WriteRune('\n') - -// sb.WriteString(fmt.Sprintf("%s|%s|%s|%s", -// m.(model_ca).inputs[0].Value(), -// m.(model_ca).inputs[1].Value(), -// m.(model_ca).inputs[2].Value(), -// m.(model_ca).inputs[3].Value())) - -// if m.(model_ca).exclude { -// sb.WriteString(fmt.Sprintf("|%s", "ex")) -// } - -// if m.(model_ca).inputs[4].Value() != "" { -// sb.WriteString(fmt.Sprintf(";;%s", m.(model_ca).inputs[4].Value())) -// } - -// //sb.WriteRune('\n') - -// if _, err = f.WriteString(sb.String()); err != nil { -// panic(err) -// } -// utils.Define_users(utils.Find_authorfile()) -// return m.(model_ca).inputs[0].Value() -// } -// return "" -// } - -// func Entry_TA() string { -// //old_m = old_m - -// m, err := tea.NewProgram(initialModel("temp")).Run() -// if err != nil { -// fmt.Printf("could not start program: %s\n", err) -// os.Exit(1) -// } - -// if len(m.(model_ca).inputs) > 0 && -// m.(model_ca).inputs[0].Value() != "" && -// m.(model_ca).inputs[1].Value() != "" { -// utils.TempAddUser(m.(model_ca).inputs[0].Value(), m.(model_ca).inputs[1].Value()) -// return m.(model_ca).inputs[0].Value() + ":" + m.(model_ca).inputs[1].Value() -// } - -// return "" - -// } diff --git a/src/cmd/tui/tui_list.go b/src/cmd/tui/tui_list.go index 60b3c82..a0d1fa1 100644 --- a/src/cmd/tui/tui_list.go +++ b/src/cmd/tui/tui_list.go @@ -198,7 +198,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, m.keys.groupSelect): // TODO: Look into how to select multiple groups sub_model = newModel() - //group := Entry_GR() return m, tea.ClearScreen case key.Matches(msg, m.keys.tempAdd): diff --git a/src/cmd/tui/tui_test.go b/src/cmd/tui/tui_test.go index eaf42a5..33f4ed7 100644 --- a/src/cmd/tui/tui_test.go +++ b/src/cmd/tui/tui_test.go @@ -26,7 +26,7 @@ func setup() { } os.Setenv("author_file", "author_file_test") envVar = os.Getenv("author_file") - + utils.Define_users("author_file_test") } @@ -34,7 +34,6 @@ func teardown() { // remove test data os.Remove("author_file_test") os.Setenv("author_file", envVar) - } // tui_show_users TESTS BEGIN @@ -164,7 +163,7 @@ func Test_EntryCA(t *testing.T) { Runes: []rune("enter"), }) - tm.Type("gr1") + tm.Type("gr6") tm.Send(tea.KeyMsg{ Type: tea.KeyRunes, Runes: []rune("enter"), @@ -196,12 +195,11 @@ func Test_EntryCA(t *testing.T) { t.Errorf("Expected 3 inputs, got %d\n%v", len(m.list.Items()), m.list.Items()) } - //TODO: For some reason the test is not writing to the author file despite working in the actual program // var user utils.User // utils.Define_users("author_file_test") // data, _ := os.ReadFile("author_file_test") - // t.Errorf("Data: %s", data) + // t.Errorf("Data: %s", data) // if _, ok := utils.Users["test"]; !ok { // t.Errorf("Expected 'testing2' to be in the users map") @@ -405,6 +403,8 @@ func Test_GroupSelection(t *testing.T) { setup() defer teardown() + t.Errorf("%v", elected) + m := listModel() tm := teatest.NewTestModel( t, m, teatest.WithInitialTermSize(300, 300), @@ -430,6 +430,9 @@ func Test_GroupSelection(t *testing.T) { t.Errorf("Expected model, got %T", fm) } + t.Errorf("%v", utils.Groups) + t.Errorf("%v", selected) + if len(selected) != 1 { t.Errorf("Expected 1 selected item, got %d", len(selected)) }