test(table): failing text alignment

This commit is contained in:
bashbunni
2024-09-26 11:58:39 -07:00
parent 6548f4e501
commit 9516572c1c
2 changed files with 35 additions and 0 deletions
+28
View File
@@ -209,6 +209,7 @@ func TestSetStyleFunc(t *testing.T) {
func TestWithStyleFunc(t *testing.T) {
t.Run("single cell styling", func(t *testing.T) {
// #502
s := DefaultStyles()
s.BorderHeader = false
biscuits := New(
@@ -237,6 +238,7 @@ func TestWithStyleFunc(t *testing.T) {
golden.RequireEqual(t, []byte(biscuits.View()))
})
t.Run("cell styling by content", func(t *testing.T) {
// #502
rows := []Row{
{"Chocolate Digestives", "UK", "Yes"},
{"Tim Tams", "Australia", "No"},
@@ -268,4 +270,30 @@ func TestWithStyleFunc(t *testing.T) {
}))
golden.RequireEqual(t, []byte(biscuits.View()))
})
t.Run("change column text alignment", func(t *testing.T) {
// #399
s := DefaultStyles()
s.BorderHeader = false
biscuits := New(
WithColumns([]Column{
{Title: "Name", Width: 25},
{Title: "Country of Origin", Width: 16},
{Title: "Dunk-able", Width: 12},
}),
WithRows([]Row{
{"Chocolate Digestives", "UK", "Yes"},
{"Tim Tams", "Australia", "No"},
{"Hobnobs", "UK", "Yes"},
}),
WithStyleFunc(func(row, col int) lipgloss.Style {
if row == table.HeaderRow {
return s.Header
}
if col == 1 {
return s.Cell.Align(lipgloss.Right)
}
return s.Cell
}))
golden.RequireEqual(t, []byte(biscuits.View()))
})
}
@@ -0,0 +1,7 @@
╭──────────────────────┬───────────────────┬───────────╮
Name │ Country of Origin │ Dunk-able │
├──────────────────────┼───────────────────┼───────────┤
│ Chocolate Digestives │ UK│ Yes │
│ Tim Tams │ Australia│ No │
│ Hobnobs │ UK│ Yes │
╰──────────────────────┴───────────────────┴───────────╯