fix(html): snapshot responsive variants
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 01:52:03 +00:00
parent acaf9d83a0
commit daaae16493
2 changed files with 19 additions and 0 deletions

View file

@ -189,6 +189,9 @@ func (r *Responsive) Variant(name string, layout *Layout) *Responsive {
if r == nil {
return nil
}
if layout != nil {
layout = layout.Clone()
}
r.variants = append(r.variants, responsiveVariant{name: name, layout: layout})
return r
}

View file

@ -84,6 +84,22 @@ func TestResponsive_CloneReturnsIndependentCopy(t *testing.T) {
}
}
func TestResponsive_VariantClonesLayoutInput(t *testing.T) {
layout := NewLayout("C").C(Raw("original"))
responsive := NewResponsive().Variant("desktop", layout)
layout.C(Raw("mutated"))
got := responsive.Render(NewContext())
if !strings.Contains(got, "original") {
t.Fatalf("Variant should snapshot the layout at insertion time, got:\n%s", got)
}
if strings.Contains(got, "mutated") {
t.Fatalf("Variant should not share later layout mutations, got:\n%s", got)
}
}
func TestResponsive_NestedPaths(t *testing.T) {
ctx := NewContext()
inner := NewLayout("HCF").H(Raw("ih")).C(Raw("ic")).F(Raw("if"))