diff --git a/tests/shell/test-boot-screen.sh b/tests/shell/test-boot-screen.sh new file mode 100755 index 0000000..87036cf --- /dev/null +++ b/tests/shell/test-boot-screen.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +# The boot screen is two frames stitched to look like one, and every way it +# comes apart is silent - the page still loads, the match still starts, and +# what a player sees is only wrong if you happen to be looking: +# +# - the string drifts. It lives twice, in index.html for the frame we serve +# and in msg.json for the frame the client builds. Nothing links them. +# - the key is misspelled. The client merges msg.json over its built-in table +# per key, so a typo is not an error, it is upstream's default coming back. +# - lang.js moves. It has to run before the loader stub reads the language; +# after it, the file is fetched for whatever locale the browser asked for +# and the string only reaches English browsers. +# - a file 404s. The insignia is a background-image and the faces are +# @font-face - a missing one is a blank box and a fallback face, not a log +# line. +# +# None of this is reachable without a browser, so what is checked here is that +# the pieces exist, agree with each other, and are wired in the right order. +set -uo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +WEB="$ROOT/suramadu/web" +HTML="$WEB/index.html" +MSG="$WEB/javascript/nls/en/msg.json" + +pass=0; fail=0 +check() { if "${@:2}"; then echo "ok $1"; pass=$((pass+1)); else echo "FAIL $1"; fail=$((fail+1)); fi; } + +for f in "$HTML" "$MSG" "$WEB/lang.js" "$WEB/fonts.css" "$WEB/theme.css" "$WEB/insignia.svg"; do + [ -s "$f" ] || { echo "FAIL ${f#"$ROOT"/} is missing or empty"; exit 1; } +done + +# --- the string exists once per frame, and they agree ------------------------ + +check "msg.json parses" python3 -c "import json,sys; json.load(open(sys.argv[1]))" "$MSG" + +# The key upstream looks up. Spelled any other way this file is inert. +check "msg.json carries dialog.startingDialog" python3 - "$MSG" <<'PY' +import json, sys +msg = json.load(open(sys.argv[1], encoding="utf-8")) +sys.exit(0 if isinstance(msg.get("dialog.startingDialog"), str) and + msg["dialog.startingDialog"].strip() else 1) +PY + +check "the two frames say the same thing" python3 - "$MSG" "$HTML" <<'PY' +import json, re, sys + +msg = json.load(open(sys.argv[1], encoding="utf-8"))["dialog.startingDialog"] +html = open(sys.argv[2], encoding="utf-8").read() + +m = re.search(r'
([^<]*)
', html) +if m is None: + print("index.html has no to compare against")
+ sys.exit(1)
+if m.group(1).strip() != msg.strip():
+ print("index.html: %r" % m.group(1).strip())
+ print("msg.json : %r" % msg.strip())
+ print("The first frame and the second would say different things.")
+ sys.exit(1)
+PY
+
+# The client asks for javascript/nls/