fix(html): snapshot responsive variants
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
acaf9d83a0
commit
daaae16493
2 changed files with 19 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue