Skip to content

Commit

Permalink
test: update to test latest webui
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Jun 2, 2024
1 parent 619dba0 commit 88c6249
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 47 deletions.
21 changes: 13 additions & 8 deletions tests/call_js_from_v_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ fn test_js_fn_call() {
await webui.call("close_window")
}'
// Show window, wait for it to be recognized as shown.
w.show(utils.gen_html(@FN, script),
await: true
) or { assert false, err.str() }
w.show(utils.gen_html(@FN, script), await: true) or { assert false, err.str() }

// We call `w.close()` from the last V function that is called from JS.
// Ensure that it closes, otherwise the test can run infinitely. Timeout after 1min.
if !utils.timeout(30, fn [w] () bool {
return !w.is_shown()
}) {
assert false, 'Timeout while waiting for JS to call V.'
}
spawn fn [w] () {
if !utils.timeout(30, fn [w] () bool {
return !w.is_shown()
}) {
assert false, 'Timeout while waiting for JS to call V.'
exit(1)
}
}()
}

fn test_run_wait() {
ui.wait() // Call wait once at the end of all tests.
}
57 changes: 34 additions & 23 deletions tests/call_v_from_js_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ fn test_v_fn_call() {
}, 500)'

// Show window, wait for it to be recognized as shown.
w.show(utils.gen_html(@FN, script),
await: true
) or { assert false, err.str() }
w.show(utils.gen_html(@FN, script), await: true) or { assert false, err.str() }

// Wait for v_fn to be called.
if !utils.timeout(30, fn [mut app] () bool {
return app.fn_was_called
}) {
assert false, 'Timeout while waiting for JS to call V.'
}
spawn fn [mut app] () {
if !utils.timeout(30, fn [mut app] () bool {
return app.fn_was_called
}) {
assert false, 'Timeout while waiting for JS to call V.'
}
}()
}

struct Person {
Expand Down Expand Up @@ -80,11 +80,13 @@ fn test_get_js_arg() {

// We call `w.close()` from the last V function that is called from JS.
// Ensure that it closes, otherwise the test can run infinitely. Timeout after 1min.
if !utils.timeout(60, fn [w] () bool {
return !w.is_shown()
}) {
assert false, 'Timeout while waiting JS calling V.'
}
spawn fn [w] () {
if !utils.timeout(60, fn [w] () bool {
return !w.is_shown()
}) {
assert false, 'Timeout while waiting JS calling V.'
}
}()
}

// V function bound to JS callback in next tests
Expand Down Expand Up @@ -117,11 +119,13 @@ fn test_get_js_arg_at_idx() {
await: true
) or { assert false, err.str() }

if !utils.timeout(60, fn [w] () bool {
return !w.is_shown()
}) {
assert false, 'Timeout while waiting JS calling V.'
}
spawn fn [w] () {
if !utils.timeout(60, fn [w] () bool {
return !w.is_shown()
}) {
assert false, 'Timeout while waiting JS calling V.'
}
}()
}

fn test_return_value_to_js() {
Expand Down Expand Up @@ -160,9 +164,16 @@ fn test_return_value_to_js() {
await: true
) or { assert false, err.str() }

if !utils.timeout(60, fn [w] () bool {
return !w.is_shown()
}) {
assert false, 'Timeout while waiting JS calling V.'
}
spawn fn [w] () {
if !utils.timeout(60, fn [w] () bool {
return !w.is_shown()
}) {
assert false, 'Timeout while waiting JS calling V.'
exit(1)
}
}()
}

fn test_run_wait() {
ui.wait() // Call wait once at the end of the test.
}
17 changes: 12 additions & 5 deletions tests/thread_gc_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ fn test_thread_gc() {
) or { assert false, err.str() }

log.info('> w.is_shown: ${w.is_shown()}')
if !utils.timeout(30, fn [mut app] () bool {
return app.fn_was_called
}) {
assert false, 'Timeout while waiting for the v binded callback to be called'
}
spawn fn [mut app] () {
if !utils.timeout(30, fn [mut app] () bool {
return app.fn_was_called
}) {
assert false, 'Timeout while waiting for the V callback to be called'
exit(1)
}
}()
}

fn test_run_wait() {
ui.wait() // Call wait once at the end of all tests.
}
23 changes: 12 additions & 11 deletions tests/window_close_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ fn test_window_close() {

// Wait for the window to show
ui.set_timeout(30)
w.show('<html style="background: #654da9; color: #eee">
<head><script src="webui.js"></script></head>
<body><samp>${@FN}</samp></body>
</html>') or {
assert false, err.str()
}
w.show(utils.gen_html(@FN, '')) or { assert false, err.str() }
for i in 0 .. 30 {
if w.is_shown() {
break
Expand All @@ -25,9 +20,15 @@ fn test_window_close() {

w.close()
// Wait for the window to close
if !utils.timeout(10, fn [w] () bool {
return !w.is_shown()
}) {
assert false, 'Failed closing window.'
}
spawn fn [w] () {
if !utils.timeout(10, fn [w] () bool {
return !w.is_shown()
}) {
assert false, 'Failed closing window.'
}
}()
}

fn test_run_wait() {
ui.wait() // Call wait once at the end of all tests.
}

0 comments on commit 88c6249

Please sign in to comment.