Files
via/signal_test.go
Ryan Hamamura 7eb86999b2 feat: refactor maplibre for reactive signals and Via-native API
- Export Signal type (signal → Signal) so subpackages can reference it
- Expose viewport signals as public fields (CenterLng, CenterLat, Zoom,
  Bearing, Pitch) for .Text() display and .Bind() usage
- Add signal-backed marker positions (LngSignal/LatSignal) with
  data-effect reactivity for server push and dragend writeback
- Add event system (MapEvent, OnClick, OnLayerClick, OnMouseMove,
  OnContextMenu) using hidden inputs + action triggers
- Add Source interface replacing type-switch, with RawSource escape hatch
- Add CameraOptions for FlyTo/EaseTo/JumpTo/FitBounds/Stop
- Add Control interface with NavigationControl, ScaleControl,
  GeolocateControl, FullscreenControl
- Expand Options with interaction toggles, MaxBounds, and Extra map
- Add effectspike example to validate data-effect with server-pushed signals
- Update maplibre example to showcase all new features
2026-02-20 08:29:24 -10:00

70 lines
1.5 KiB
Go

package via
import (
// "net/http/httptest"
"testing"
"github.com/ryanhamamura/via/h"
"github.com/stretchr/testify/assert"
)
func TestSignalReturnAsString(t *testing.T) {
testcases := []struct {
desc string
given any
expected string
}{
{"string", "test", "test"},
{"other string", "another", "another"},
{"int", 1, "1"},
{"negative int", -99, "-99"},
{"float", 1.1, "1.1"},
{"negative float", -34.345, "-34.345"},
{"positive bool", true, "true"},
{"negative bool", false, "false"},
}
for _, testcase := range testcases {
t.Run(testcase.desc, func(t *testing.T) {
t.Parallel()
var sig *Signal
v := New()
v.Page("/", func(c *Context) {
sig = c.Signal(testcase.given)
c.View(func() h.H { return h.Div() })
})
assert.Equal(t, testcase.expected, sig.String())
})
}
}
func TestSignalReturnAsStringComplexTypes(t *testing.T) {
testcases := []struct {
desc string
given any
expected string
}{
{"string slice", []string{"test"}, `["test"]`},
{"int slice", []int{1, 2}, "[1, 2]"},
{"struct1", struct{ Val string }{"test"}, `{"Val": "test"}`},
{"struct2", struct {
Num int
IsPositive bool
}{1, true}, `{"Num": 1, "IsPositive": true}`},
}
for _, testcase := range testcases {
t.Run(testcase.desc, func(t *testing.T) {
t.Parallel()
var sig *Signal
v := New()
v.Page("/", func(c *Context) {
c.View(func() h.H { return nil })
sig = c.Signal(testcase.given)
})
assert.JSONEq(t, testcase.expected, sig.String())
})
}
}