This repository has been archived on 2026-10-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
submarine/internal/submodule/status_test.go
T
Simon FrankenandClaude Opus 5.5 2212b24fe1 Add submarine TUI prototype with mock data
Bubble Tea prototype for browsing repositories with many nested git
submodules: collapsible tree, pins shown as ref + distance, summarized
issue words with severity levels, detail pane, async loading via a
Provider interface backed by mock data. Includes docs/ with
requirements, state model, UX guide, architecture and decision log,
plus AGENTS.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 14:59:53 +02:00

53 lines
1.7 KiB
Go

package submodule
import (
"slices"
"testing"
)
func kinds(is []Issue) []IssueKind {
var out []IssueKind
for _, i := range is {
out = append(out, i.Kind)
}
return out
}
func TestIssues(t *testing.T) {
pushed := PinInfo{Pushed: true}
tests := []struct {
name string
s *Status
want []IssueKind
}{
{"loading", nil, nil},
{"clean", &Status{Pin: pushed}, nil},
{"behind, staged and detached are quiet", &Status{Pin: PinInfo{Pushed: true, Behind: 3}, PinStaged: true, Checkout: CheckoutDetached}, nil},
{"not initialized", &Status{Presence: NotInitialized}, []IssueKind{IssueMissing}},
{"dir missing", &Status{Presence: DirMissing}, []IssueKind{IssueMissing}},
{"untracked is changed", &Status{Worktree: WorktreeUntracked, Pin: pushed}, []IssueKind{IssueChanged}},
{"danger first", &Status{Checkout: CheckoutDiffers, Worktree: WorktreeModified}, []IssueKind{IssueUnpushed, IssueOffPin, IssueChanged}},
{"conflict", &Status{Worktree: WorktreeConflict, Pin: pushed}, []IssueKind{IssueConflict}},
}
for _, tt := range tests {
if got := kinds(tt.s.Issues()); !slices.Equal(got, tt.want) {
t.Errorf("%s: Issues() = %v, want %v", tt.name, got, tt.want)
}
}
}
func TestHiddenIssues(t *testing.T) {
ok := &Status{Pin: PinInfo{Pushed: true}}
dirty := &Status{Worktree: WorktreeModified, Pin: PinInfo{Pushed: true}}
unpushed := &Status{}
grandchild := &Submodule{Status: unpushed}
child := &Submodule{Status: dirty, Children: []*Submodule{grandchild}}
loading := &Submodule{}
root := &Submodule{Status: ok, Children: []*Submodule{child, {Status: ok}, loading}}
count, worst := root.HiddenIssues()
if count != 2 || worst != LevelDanger {
t.Errorf("HiddenIssues() = %d, %v; want 2, LevelDanger", count, worst)
}
}