Skip to content

Commit

Permalink
WIP: panels: update some tests
Browse files Browse the repository at this point in the history
Still needs some work
  • Loading branch information
dfinkel committed Feb 26, 2025
1 parent 094e36d commit 85f92d6
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions panels/panels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,54 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/vimeo/dials"
"github.com/vimeo/dials/json"
"github.com/vimeo/dials/static"
"github.com/vimeo/dials/decoders/json"
"github.com/vimeo/dials/sources/static"
)

type testSubPanel struct {
type testSubPanel[RT, T any] struct {
t testing.TB
sp SetupParams
dCfg interface{}
sp SetupParams[T]
dCfg *T
cmdArgs []string
expectedSCPath []string
expectedArgs []string
expSubDCfg interface{}
expPanelDCfg interface{}
expSubDCfg *T
expPanelDCfg *RT
}

func (t *testSubPanel) Description(scPath []string) string {
func (t *testSubPanel[RT, T]) Description(scPath []string) string {
return "description " + strings.Join(scPath, "-")
}

func (t *testSubPanel) ShortUsage(scPath []string) string {
func (t *testSubPanel[RT, T]) ShortUsage(scPath []string) string {
return "short " + strings.Join(scPath, "-")
}

func (t *testSubPanel) LongUsage(scPath []string) string {
func (t *testSubPanel[RT, T]) LongUsage(scPath []string) string {
return "long " + strings.Join(scPath, "-")
}

func (t *testSubPanel) DefaultConfig() interface{} {
func (t *testSubPanel[RT, T]) DefaultConfig() *T {
return t.dCfg
}

func (t *testSubPanel) SetupParams() SetupParams {
func (t *testSubPanel[RT, T]) SetupParams() SetupParams[T] {
return t.sp
}

func (t *testSubPanel) Run(ctx context.Context, s *Something) error {
func (t *testSubPanel[RT, T]) Run(ctx context.Context, s *Handle[RT, T]) error {
t.t.Logf("args: %q, %q, %q", s.Args, s.CommandArgs, s.SCPath)
assert.Equal(t.t, t.cmdArgs, s.CommandArgs)
assert.Equal(t.t, t.expectedArgs, s.Args)
assert.Equal(t.t, t.expectedSCPath, s.SCPath)
assert.Equal(t.t, t.expSubDCfg, s.Dials.View())

if t.expPanelDCfg != nil {
assert.Equal(t.t, t.expPanelDCfg, s.DialsPath[0].View())
assert.Equal(t.t, t.expPanelDCfg, s.RootDials.View())
}

assert.Equal(t.t, s.Dials, s.DialsPath[1])

return nil
}

Expand Down Expand Up @@ -94,7 +93,10 @@ func TestPanels(t *testing.T) {
},
{
name: "NewDialsFuncPanel",
p: Panel{
p: Panel[struct {
Song string
Artist string
}]{
dCfg: &struct {
Song string
Artist string
Expand Down Expand Up @@ -183,7 +185,7 @@ func TestPanels(t *testing.T) {
tc := testCase
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
sch, regErr := tc.p.Register(tc.scName, &tc.tsp)
sch, regErr := Register(tc.p, tc.scName, &tc.tsp)
require.NoError(t, regErr)
require.NotNil(t, sch)
assert.Len(t, tc.p.schMap, 1)
Expand Down

0 comments on commit 85f92d6

Please sign in to comment.