ReviewOS

also looking at this

craft-native/craft

test(ios): verify app termination before local notification delivery

#308
Merged glennmichael123 wants to merge codex/ios-notification-deadline into main
5 files +96 -21
scripts/mobile-e2e/driver.htmlmodified+13-4
Changes to scripts/mobile-e2e/driver.html
@@ -512,8 +512,9 @@
512512 // arrival is not a tap.
513513 //
514514 // #258: opened by the local link, the page schedules a notification of
515 // its own, with data, a few seconds out. The test kills the app before it
516 // fires and taps it, and this same report says what the tap carried.
515 // its own, with data, far enough out for the UI test to stop the app.
516 // The test kills it before it fires and taps it, and this same report
517 // says what the tap carried.
517518 //
518519 // Permission is asked for only when the link asks, because nothing
519520 // answers the prompt on the launches simctl makes. iOS only: Android has
@@ -527,12 +528,20 @@
527528 }
528529 if (launch && launch.url.indexOf('://e2e/local') !== -1) {
529530 var scheduled = function (text) { document.getElementById('notification-local').textContent = 'CRAFT-E2E-LOCAL-SCHEDULED ' + text }
531 var delay = Number(new URL(launch.url).searchParams.get('delayMs'))
532 if (!Number.isInteger(delay) || delay < 60000 || delay > 180000) {
533 scheduled('rejected invalid scheduling window')
534 return
535 }
536 // Record the earliest delivery time before crossing the bridge. A
537 // slow completion must not invent a later deadline for the UI test.
538 var fireAt = Date.now() + delay
530539 window.craft.notifications.schedule({
531540 title: 'Craft E2E',
532541 body: NONCE + ' local',
533 delay: 8000,
542 delay: delay,
534543 data: { craftE2E: NONCE, stage: 'local', nested: { kept: true } }
535 }).then(function () { scheduled('ok') }, function (error) { scheduled('rejected ' + describeError(error).message) })
544 }).then(function () { scheduled('ok ' + fireAt) }, function (error) { scheduled('rejected ' + describeError(error).message) })
536545 }
537546 var onTap = window.craft.notifications && window.craft.notifications.onTap
538547 var seen = { dispatched: 0, taps: [], onTap: typeof onTap, unsubscribe: null }