Skip to content

Commit

Permalink
test(layout): add grid layout test
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Jan 8, 2025
1 parent 152f09d commit b10915b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ require (
github.com/charmbracelet/bubbletea v1.2.2
github.com/charmbracelet/lipgloss v1.0.0
github.com/charmbracelet/x/ansi v0.4.5
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0
github.com/mitchellh/hashstructure/v2 v2.0.2
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymanbagabas/go-udiff v0.2.0 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
Expand All @@ -14,6 +16,8 @@ github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O
github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSexTdRM=
github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAMdlwSltxJyULnrYbkZpp4k58Co7Tah3ciKhSNo0Q=
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko3AQ4gK1MTS/de7F5hPGx6/k1u0w4TeYmBFwzYVP4=
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
Expand Down
1 change: 0 additions & 1 deletion group.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ func (g *Group) fullHeight() int {
func (g *Group) getContent() (int, string) {
var fields strings.Builder
offset := 0
gap := "\n\n"

// if the focused field is requesting it be zoomed, only show that field.
if g.selector.Selected().Zoom() {
Expand Down
30 changes: 30 additions & 0 deletions huh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
"github.com/charmbracelet/x/exp/golden"
)

var pretty = lipgloss.NewStyle().
Expand Down Expand Up @@ -918,6 +919,35 @@ func TestAbort(t *testing.T) {
}
}

func TestLayoutGrid(t *testing.T) {
form := NewForm(
NewGroup(
NewInput().Title("First"),
NewInput().Title("Second"),
NewInput().Title("Third"),
),
NewGroup(
NewInput().Title("Fourth"),
NewInput().Title("Fifth"),
NewInput().Title("Sixth"),
),
NewGroup(
NewInput().Title("Seventh"),
NewInput().Title("Eigth"),
NewInput().Title("Nineth"),
NewInput().Title("Tenth"),
),
NewGroup(
NewInput().Title("Eleventh"),
NewInput().Title("Twelveth"),
NewInput().Title("Thirteenth"),
),
).WithLayout(LayoutGrid(2, 2)).WithShowHelp(false)
want := ansi.Strip(form.View())
t.Log(want)
golden.RequireEqual(t, []byte(want))
}

// formProgram returns a new Form with a nil input and output, so it can be used as a test program.
func formProgram() *Form {
return NewForm(NewGroup(NewInput().Title("Foo"))).
Expand Down
23 changes: 23 additions & 0 deletions testdata/TestLayoutGrid.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
First Fourth
> >

Second Fifth
> >

Third Sixth
> >

Seventh Eleventh
> >

Eigth Twelveth
> >

Nineth Thirteenth
> >

Tenth
>



0 comments on commit b10915b

Please sign in to comment.