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 value := parsed.FirstChild.FirstChild.NextSibling.LastChild.Attr[0].Val
isComplex := strings.HasPrefix(value, "__eval_") isComplex := strings.HasPrefix(value, "__eval_")
if !isComplex { if !isComplex {
return value value = strings.ReplaceAll(value, "var e=event;", "")
return strings.ReplaceAll(value, "var self=this;", "")
} else { } else {
id := strings.TrimSuffix(value, "(this);") id := strings.TrimSuffix(value, "(this, event);")
script := findScriptById(parsed, id) script := findScriptById(parsed, id)
assert.NotNil(t, script) assert.NotNil(t, script)
funcCall := script.LastChild.Data funcCall := script.LastChild.Data
funcCall = strings.ReplaceAll(funcCall, "\n", "") funcCall = strings.ReplaceAll(funcCall, "\n", "")
funcCall = strings.ReplaceAll(funcCall, "\t", "") 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.TrimPrefix(funcCall, start)
funcCall = strings.TrimSuffix(funcCall, "}") funcCall = strings.TrimSuffix(funcCall, "}")
funcCall = strings.ReplaceAll(funcCall, "let e = event;", "")
funcCall = strings.ReplaceAll(funcCall, "var self=this;", "")
return funcCall return funcCall
} }
} }

View file

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

View file

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