Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions internal/render/tui/repostableheader/reposTableHeader_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package repostableheader

import (
"strings"
"testing"

"github.com/mabd-dev/reposcan/pkg/report"
)

func TestHeaderSetReportCountsRepositoriesAndDirtyStates(t *testing.T) {
reportWithStash := report.ScanReport{RepoStates: []report.RepoState{
{UncommitedFiles: []string{"changed.txt"}},
{Stashes: []string{"stash@{0}"}},
{},
}}

for _, tc := range []struct {
name string
countStashAsDirty bool
wantDirty int
}{
{name: "ignore stashes", countStashAsDirty: false, wantDirty: 1},
{name: "count stashes", countStashAsDirty: true, wantDirty: 2},
} {
t.Run(tc.name, func(t *testing.T) {
header := Header{}
header.SetReport(reportWithStash, tc.countStashAsDirty)

if header.repoStatesCount != 3 {
t.Fatalf("repoStatesCount = %d, want 3", header.repoStatesCount)
}
if header.dirtyRepos != tc.wantDirty {
t.Fatalf("dirtyRepos = %d, want %d", header.dirtyRepos, tc.wantDirty)
}
})
}
}

func TestHeaderViewIncludesApplicationNameAndRepositoryCount(t *testing.T) {
header := Header{}
header.SetReport(report.ScanReport{RepoStates: make([]report.RepoState, 2)}, false)

view := header.View()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Header Test Misses Composition

This test verifies the header component in isolation, but the production TUI view combines only the repository table, details, and footer; it never includes the initialized repository header. The test therefore passes while users cannot see reposcan • N repos. Add a regression assertion through the production model view after wiring the header into that layout. This is non-blocking, but the current test does not protect the user-visible behavior.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Artifacts

Evidence from the check

  • Temporary Go test constructs the production TUI model with a populated repository header and asserts the rendered model omits that header, establishing the composition gap.

Evidence from the check

  • Shell command copies the temporary focused test into the TUI package, runs it, and removes the copied test afterward, providing a repeatable production-path check.

Command output from the check

  • Executed the PR's direct header-view test successfully, showing the limited isolated behavior it covers.

Command output from the check

  • Executed the focused production `Model.View()` test successfully; it shows the isolated header text exists but both header strings are absent from the production view.

View artifacts

T-Rex Ran code and verified through T-Rex

for _, want := range []string{"reposcan", "• 2 repos"} {
if !strings.Contains(view, want) {
t.Fatalf("View() = %q, want it to contain %q", view, want)
}
}
}
6 changes: 4 additions & 2 deletions internal/render/tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ func (m Model) View() tea.View {
}

footer := m.getFooterView()
header := m.rtHeader.View()

// Calculate heights
footerHeight := lipgloss.Height(footer)
bodyHeight := m.height - footerHeight
headerHeight := lipgloss.Height(header)
bodyHeight := m.height - headerHeight - footerHeight

reposTableHeight := bodyHeight * sizeReposTableHeightPercent / 100
m.reposTable = m.reposTable.UpdateWindowSize(m.width, reposTableHeight)
Expand All @@ -37,7 +39,7 @@ func (m Model) View() tea.View {
MaxHeight(bodyHeight).
Render(body)

view := lipgloss.JoinVertical(lipgloss.Left, body, footer)
view := lipgloss.JoinVertical(lipgloss.Left, header, body, footer)

view = lipgloss.NewStyle().
Width(m.width).
Expand Down
38 changes: 38 additions & 0 deletions internal/render/tui/view_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package tui

import (
"strings"
"testing"

"charm.land/lipgloss/v2"
"github.com/mabd-dev/reposcan/internal/render/tui/repodetails"
"github.com/mabd-dev/reposcan/internal/render/tui/repostable"
rth "github.com/mabd-dev/reposcan/internal/render/tui/repostableheader"
"github.com/mabd-dev/reposcan/internal/theme"
"github.com/mabd-dev/reposcan/pkg/report"
)

func TestViewIncludesRepositoryHeader(t *testing.T) {
colors := theme.ColorScheme{Foreground: lipgloss.Color("#ffffff"), Muted: lipgloss.Color("#888888")}
theme := theme.Theme{Colors: colors, Styles: theme.Styles{Base: lipgloss.NewStyle(), Muted: lipgloss.NewStyle()}}
report := report.ScanReport{RepoStates: []report.RepoState{{Repo: "alpha", Branch: "main", ID: "alpha"}}}
header := rth.Header{Theme: theme}
header.SetReport(report, false)

m := Model{
width: 80,
height: 24,
theme: theme,
rtHeader: header,
reposTable: repostable.New(theme, report, 80, 12, repostable.Options{}),
repoDetails: repodetails.New(&report.RepoStates[0], theme),
focusStack: []FocusState{FocusReposTable},
}

view := m.View().Content
for _, want := range []string{"reposcan", "1 repos"} {
if !strings.Contains(view, want) {
t.Fatalf("production view missing %q:\n%s", want, view)
}
}
}