49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package ui
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDirectDOMDereferencesExist(t *testing.T) {
|
|
app, err := Files.ReadFile("static/app.js")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
html, err := Files.ReadFile("static/index.html")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
page := string(html)
|
|
idPattern := regexp.MustCompile(`id="([^"]+)"`)
|
|
ids := map[string]bool{}
|
|
for _, m := range idPattern.FindAllStringSubmatch(page, -1) {
|
|
ids[m[1]] = true
|
|
}
|
|
|
|
// A direct $('#id').property dereference is fatal when the element does not
|
|
// exist. This exact class of regression previously stopped all state renders.
|
|
derefPattern := regexp.MustCompile(`\$\('#([^']+)'\)\.[A-Za-z_]`)
|
|
for _, m := range derefPattern.FindAllStringSubmatch(string(app), -1) {
|
|
if !ids[m[1]] {
|
|
t.Errorf("app.js directly dereferences missing DOM id %q", m[1])
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSystemStatusRenderIsIsolated(t *testing.T) {
|
|
app, err := Files.ReadFile("static/app.js")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
js := string(app)
|
|
if strings.Contains(js, "$('#stt').title") || strings.Contains(js, "$('#tts').title") {
|
|
t.Fatal("legacy voice selectors would abort renderState")
|
|
}
|
|
if !strings.Contains(js, "safeRender('system-status',renderSystemStatus)") {
|
|
t.Fatal("system status render must be isolated from domain renderers")
|
|
}
|
|
}
|