Skip to content

Commit 69cbe84

Browse files
committed
tests: update coverage
1 parent 31bb2db commit 69cbe84

File tree

2 files changed

+161
-9
lines changed

2 files changed

+161
-9
lines changed

internal/config/config_test.go

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,3 +711,155 @@ func TestRemoveFromSlice(t *testing.T) {
711711
})
712712
}
713713
}
714+
715+
func TestFormatStringSlice(t *testing.T) {
716+
tests := []struct {
717+
name string
718+
input []string
719+
expected string
720+
}{
721+
{"empty", nil, "[]"},
722+
{"empty slice", []string{}, "[]"},
723+
{"single", []string{"zoxide"}, `["zoxide"]`},
724+
{"multiple", []string{"zoxide", "direnv"}, `["zoxide", "direnv"]`},
725+
{"three", []string{"a", "b", "c"}, `["a", "b", "c"]`},
726+
}
727+
728+
for _, tt := range tests {
729+
t.Run(tt.name, func(t *testing.T) {
730+
result := formatStringSlice(tt.input)
731+
if result != tt.expected {
732+
t.Errorf("formatStringSlice(%v) = %q, want %q", tt.input, result, tt.expected)
733+
}
734+
})
735+
}
736+
}
737+
738+
func TestJoinStrings(t *testing.T) {
739+
tests := []struct {
740+
name string
741+
input []string
742+
sep string
743+
expected string
744+
}{
745+
{"empty", nil, ", ", ""},
746+
{"single", []string{"a"}, ", ", "a"},
747+
{"two", []string{"a", "b"}, ", ", "a, b"},
748+
{"custom sep", []string{"x", "y", "z"}, "-", "x-y-z"},
749+
}
750+
751+
for _, tt := range tests {
752+
t.Run(tt.name, func(t *testing.T) {
753+
result := joinStrings(tt.input, tt.sep)
754+
if result != tt.expected {
755+
t.Errorf("joinStrings(%v, %q) = %q, want %q", tt.input, tt.sep, result, tt.expected)
756+
}
757+
})
758+
}
759+
}
760+
761+
func TestGenerateHooksSection(t *testing.T) {
762+
tests := []struct {
763+
name string
764+
selections IntegrationSelections
765+
contains []string
766+
absent []string
767+
}{
768+
{
769+
"no integrations",
770+
IntegrationSelections{},
771+
[]string{"# [hooks]", "# post_clone = []"},
772+
[]string{"\n[hooks]\n"},
773+
},
774+
{
775+
"zoxide only",
776+
IntegrationSelections{Zoxide: true},
777+
[]string{"[hooks]\n", `post_clone = ["zoxide"]`, `post_add = ["zoxide"]`},
778+
[]string{"# [hooks]"},
779+
},
780+
{
781+
"github only",
782+
IntegrationSelections{GitHub: true},
783+
[]string{"[hooks]\n", `post_clone = ["gh-default"]`, "post_add = []"},
784+
nil,
785+
},
786+
{
787+
"direnv only",
788+
IntegrationSelections{Direnv: true},
789+
[]string{"[hooks]\n", "post_clone = []", `post_add = ["direnv"]`},
790+
nil,
791+
},
792+
{
793+
"all integrations",
794+
IntegrationSelections{Zoxide: true, GitHub: true, Direnv: true},
795+
[]string{`post_clone = ["zoxide", "gh-default"]`, `post_add = ["zoxide", "direnv"]`},
796+
nil,
797+
},
798+
}
799+
800+
for _, tt := range tests {
801+
t.Run(tt.name, func(t *testing.T) {
802+
result := generateHooksSection(tt.selections)
803+
for _, s := range tt.contains {
804+
if !strings.Contains(result, s) {
805+
t.Errorf("expected %q to contain %q", result, s)
806+
}
807+
}
808+
for _, s := range tt.absent {
809+
if strings.Contains(result, s) {
810+
t.Errorf("expected %q to NOT contain %q", result, s)
811+
}
812+
}
813+
})
814+
}
815+
}
816+
817+
func TestGenerateWorkflowsSection(t *testing.T) {
818+
tests := []struct {
819+
name string
820+
selections IntegrationSelections
821+
contains []string
822+
}{
823+
{
824+
"no extras",
825+
IntegrationSelections{},
826+
[]string{"[workflows.feature]", "[workflows.bugfix]", "github-issue", "post_add = []"},
827+
},
828+
{
829+
"with direnv and zoxide",
830+
IntegrationSelections{Direnv: true, Zoxide: true},
831+
[]string{`post_add = ["direnv", "zoxide"]`, "[workflows.feature]", "[workflows.bugfix]"},
832+
},
833+
}
834+
835+
for _, tt := range tests {
836+
t.Run(tt.name, func(t *testing.T) {
837+
result := generateWorkflowsSection(tt.selections)
838+
for _, s := range tt.contains {
839+
if !strings.Contains(result, s) {
840+
t.Errorf("expected %q to contain %q", result, s)
841+
}
842+
}
843+
})
844+
}
845+
}
846+
847+
func TestGenerateConfigWithIntegrations(t *testing.T) {
848+
// No integrations - should have commented hooks, no workflows
849+
plain := GenerateConfigWithIntegrations(IntegrationSelections{})
850+
if !strings.Contains(plain, "# [hooks]") {
851+
t.Error("expected commented hooks section")
852+
}
853+
if strings.Contains(plain, "[workflows.") {
854+
t.Error("expected no workflows section without GitHub")
855+
}
856+
857+
// With GitHub - should have workflows section
858+
withGH := GenerateConfigWithIntegrations(IntegrationSelections{GitHub: true})
859+
if !strings.Contains(withGH, "[workflows.feature]") {
860+
t.Error("expected workflows section with GitHub enabled")
861+
}
862+
if !strings.Contains(withGH, "[workflows.bugfix]") {
863+
t.Error("expected bugfix workflow with GitHub enabled")
864+
}
865+
}

internal/tui/panels/detail.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,19 @@ func (dp *DetailPanel) renderInfo() string {
141141

142142
var b strings.Builder
143143

144-
b.WriteString(fmt.Sprintf(" %s %s\n",
144+
fmt.Fprintf(&b, " %s %s\n",
145145
dp.tabStyles.label.Render("Branch:"),
146-
dp.tabStyles.value.Render(dp.Branch)))
147-
b.WriteString(fmt.Sprintf(" %s %s\n",
146+
dp.tabStyles.value.Render(dp.Branch))
147+
fmt.Fprintf(&b, " %s %s\n",
148148
dp.tabStyles.label.Render("Path:"),
149-
dp.tabStyles.value.Render(dp.Path)))
150-
b.WriteString(fmt.Sprintf(" %s %s\n",
149+
dp.tabStyles.value.Render(dp.Path))
150+
fmt.Fprintf(&b, " %s %s\n",
151151
dp.tabStyles.label.Render("Status:"),
152-
dp.tabStyles.value.Render(dp.Status)))
152+
dp.tabStyles.value.Render(dp.Status))
153153

154154
if dp.Commits != "" {
155155
b.WriteString("\n")
156-
b.WriteString(fmt.Sprintf(" %s\n", dp.tabStyles.section.Render("── Recent commits ──────────────")))
156+
fmt.Fprintf(&b, " %s\n", dp.tabStyles.section.Render("── Recent commits ──────────────"))
157157
for _, line := range strings.Split(dp.Commits, "\n") {
158158
if line != "" {
159159
b.WriteString(" " + line + "\n")
@@ -163,15 +163,15 @@ func (dp *DetailPanel) renderInfo() string {
163163

164164
if dp.Files != "" {
165165
b.WriteString("\n")
166-
b.WriteString(fmt.Sprintf(" %s\n", dp.tabStyles.section.Render("── Modified files ──────────────")))
166+
fmt.Fprintf(&b, " %s\n", dp.tabStyles.section.Render("── Modified files ──────────────"))
167167
for _, line := range strings.Split(dp.Files, "\n") {
168168
if line != "" {
169169
b.WriteString(" " + line + "\n")
170170
}
171171
}
172172
} else if dp.Status == "clean" {
173173
b.WriteString("\n")
174-
b.WriteString(fmt.Sprintf(" %s\n", dp.tabStyles.section.Render("── Modified files ──────────────")))
174+
fmt.Fprintf(&b, " %s\n", dp.tabStyles.section.Render("── Modified files ──────────────"))
175175
b.WriteString(" (no uncommitted changes)\n")
176176
}
177177

0 commit comments

Comments
 (0)