fix tests

This commit is contained in:
maddalax 2024-10-03 15:35:19 -05:00
parent a06f5fea12
commit 496981efd0
3 changed files with 8 additions and 10 deletions

View file

@ -32,17 +32,20 @@ func renderJs(t *testing.T, command Command) string {
value := parsed.FirstChild.FirstChild.NextSibling.LastChild.Attr[0].Val
isComplex := strings.HasPrefix(value, "__eval_")
if !isComplex {
return value
value = strings.ReplaceAll(value, "var e=event;", "")
return strings.ReplaceAll(value, "var self=this;", "")
} else {
id := strings.TrimSuffix(value, "(this);")
id := strings.TrimSuffix(value, "(this, event);")
script := findScriptById(parsed, id)
assert.NotNil(t, script)
funcCall := script.LastChild.Data
funcCall = strings.ReplaceAll(funcCall, "\n", "")
funcCall = strings.ReplaceAll(funcCall, "\t", "")
start := fmt.Sprintf("function %s(self) {", id)
start := fmt.Sprintf("function %s(self, event) {", id)
funcCall = strings.TrimPrefix(funcCall, start)
funcCall = strings.TrimSuffix(funcCall, "}")
funcCall = strings.ReplaceAll(funcCall, "let e = event;", "")
funcCall = strings.ReplaceAll(funcCall, "var self=this;", "")
return funcCall
}
}

View file

@ -307,12 +307,7 @@ func SetValue(value string) SimpleJsCommand {
func SubmitFormOnEnter() ComplexJsCommand {
// language=JavaScript
return EvalJs(`
if (event.code === 'Enter') {
console.log('submitting form');
setTimeout(() => {
self.form.dispatchEvent(new Event('submit', { cancelable: true }));
}, 250)
}
if (event.code === 'Enter') { self.form.dispatchEvent(new Event('submit', { cancelable: true })); }
`)
}

View file

@ -46,7 +46,7 @@ func TestRender(t *testing.T) {
assert.Equal(t,
expected,
result)
strings.ReplaceAll(result, "var self=this;var e=event;", ""))
}
func TestRenderAttributes_1(t *testing.T) {