refactor: integration tests use Imprint pipeline
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5acf63cb4b
commit
2fab89ea46
1 changed files with 23 additions and 26 deletions
|
|
@ -1,11 +1,9 @@
|
||||||
package html
|
package html
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
i18n "forge.lthn.ai/core/go-i18n"
|
i18n "forge.lthn.ai/core/go-i18n"
|
||||||
"forge.lthn.ai/core/go-i18n/reversal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIntegration_RenderThenReverse(t *testing.T) {
|
func TestIntegration_RenderThenReverse(t *testing.T) {
|
||||||
|
|
@ -18,12 +16,7 @@ func TestIntegration_RenderThenReverse(t *testing.T) {
|
||||||
C(El("p", Text("Files deleted successfully"))).
|
C(El("p", Text("Files deleted successfully"))).
|
||||||
F(El("small", Text("Completed")))
|
F(El("small", Text("Completed")))
|
||||||
|
|
||||||
rendered := page.Render(ctx)
|
imp := Imprint(page, ctx)
|
||||||
text := stripTags(rendered)
|
|
||||||
|
|
||||||
tok := reversal.NewTokeniser()
|
|
||||||
tokens := tok.Tokenise(text)
|
|
||||||
imp := reversal.NewImprint(tokens)
|
|
||||||
|
|
||||||
if imp.UniqueVerbs == 0 {
|
if imp.UniqueVerbs == 0 {
|
||||||
t.Error("reversal found no verbs in rendered page")
|
t.Error("reversal found no verbs in rendered page")
|
||||||
|
|
@ -33,23 +26,27 @@ func TestIntegration_RenderThenReverse(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stripTags removes HTML tags for plain text extraction.
|
func TestIntegration_ResponsiveImprint(t *testing.T) {
|
||||||
func stripTags(html string) string {
|
svc, _ := i18n.New()
|
||||||
var b strings.Builder
|
i18n.SetDefault(svc)
|
||||||
inTag := false
|
ctx := NewContext()
|
||||||
for _, r := range html {
|
|
||||||
if r == '<' {
|
r := NewResponsive().
|
||||||
inTag = true
|
Variant("desktop", NewLayout("HLCRF").
|
||||||
b.WriteByte(' ')
|
H(El("h1", Text("Building project"))).
|
||||||
continue
|
L(El("nav", Text("Deleted files"))).
|
||||||
|
C(El("p", Text("Files deleted successfully"))).
|
||||||
|
R(El("aside", Text("Completed"))).
|
||||||
|
F(El("small", Text("Completed")))).
|
||||||
|
Variant("mobile", NewLayout("C").
|
||||||
|
C(El("p", Text("Files deleted successfully"))))
|
||||||
|
|
||||||
|
imp := Imprint(r, ctx)
|
||||||
|
|
||||||
|
if imp.TokenCount == 0 {
|
||||||
|
t.Error("responsive imprint produced zero tokens")
|
||||||
}
|
}
|
||||||
if r == '>' {
|
if imp.UniqueVerbs == 0 {
|
||||||
inTag = false
|
t.Error("responsive imprint found no verbs")
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
if !inTag {
|
|
||||||
b.WriteRune(r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(b.String())
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue