Move goldens func to testutils and use it for some simple horizontal scrolling tests

This commit is contained in:
David Dworken
2023-02-11 09:09:48 -08:00
parent e1cb97f7c6
commit fea151261f
7 changed files with 205 additions and 87 deletions

View File

@@ -2,7 +2,11 @@
package table
import "testing"
import (
"testing"
"github.com/ddworken/hishtory/shared/testutils"
)
func TestFromValues(t *testing.T) {
input := "foo1,bar1\nfoo2,bar2\nfoo3,bar3"
@@ -41,6 +45,24 @@ func TestFromValuesWithTabSeparator(t *testing.T) {
}
}
func TestHScoll(t *testing.T) {
table := New(
WithColumns([]Column{{Title: "Column1", Width: 10}, {Title: "Column2", Width: 20}}),
WithRows([]Row{
{"a1", "a2345"},
{"b1", "b23"},
{"c1", "c1234567890abcdefghijklmnopqrstuvwxyz"},
}),
)
testutils.CompareGoldens(t, table.View(), "unittestTable-truncatedTable")
table.MoveRight(1)
testutils.CompareGoldens(t, table.View(), "unittestTable-truncatedTable-right1")
table.MoveRight(1)
testutils.CompareGoldens(t, table.View(), "unittestTable-truncatedTable-right2")
table.MoveRight(1)
testutils.CompareGoldens(t, table.View(), "unittestTable-truncatedTable-right3")
}
func deepEqual(a, b []Row) bool {
if len(a) != len(b) {
return false