File size: 30,825 Bytes
d292518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
#!/usr/bin/env python3
"""TEXT lane — Vector Pinball (com.dozingcatsoftware.bouncy on this emulator).

Owns CONTENT / OUTPUT strings that an ACTION PRODUCES and app-unique static
strings a faithful recreation must render exactly: the About activity body (and
its table-DEPENDENT rules block), the High Scores panel title, both preference
dialog messages/titles, the preference row titles, the Game speed option labels,
and the menu button labels. This lane is the SOLE owner of exact-string equality.

Every test drives the real user path, reaches the surface via a NAMED depth
helper (and_reach_*/and_enter_*), then reads the resulting text from a fresh ui()
and asserts a normalised substring/equality against what was OBSERVED on the
original. The discriminating flagship (table rules) asserts a string is PRESENT
for table 1 and ABSENT for table 2 (and vice-versa) after tapping the table
picker — action-produced dynamic content.

Two canvas-only facts (the top status strip is a custom scoreView that never
reaches the view tree) use the file's 2 VLM slots: "Touch to start" on the fresh
menu, and the "High Score:" banner produced by playing then ending a game.

Boundaries this lane routes AROUND (owned elsewhere): the independent-flippers
summary pairing and the Game-speed summary "Fast" (STATES); the "No scores for
this table" empty-state and the "Last Score: <n>" numeric row (INTERACTION). The
package arrives as argv[1]; never hardcoded.
"""
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import *          # noqa: F403,E402

SHOTS = os.path.join(RESULTS_DIR, "screenshots")


# ══════════════════════════════════════════════════════════════════════════════
# Small readers
# ══════════════════════════════════════════════════════════════════════════════

def norm(s):
    """Whitespace-collapsed, casefolded — for a punctuation/case-tolerant match."""
    return " ".join((s or "").split()).casefold()


def all_text(nodes):
    return " | ".join(n.get("text", "") for n in nodes if n.get("text"))


def about_text(nodes):
    """The single big AboutActivity TextView body (empty string if absent)."""
    tv = node_by_id(nodes, "aboutTextView")
    return tv.get("text", "") if tv else ""


def pref_title(nodes, label):
    """The android:id/title TextView whose text is exactly `label` (ci). The
    Preferences action-bar title also carries a /title id, so matching on the row
    label text (not just the id) keeps 'Preferences' from being mistaken for a
    row."""
    lab = label.strip().lower()
    for n in nodes:
        if (n.get("resource-id", "").endswith("/title")
                and n.get("text", "").strip().lower() == lab):
            return n
    return None


def on_prefs(nodes=None):
    """True when the BouncyPreferences surface is showing (has a 'Sound' row)."""
    nodes = ui() if nodes is None else nodes
    return pref_title(nodes, "Sound") is not None


def highscore_title(nodes):
    """The High Scores panel TITLE TextView ('High scores'), distinct from the
    OK button and the empty-state noHighScoresTextView. Located as a TextView
    whose text is 'High scores' and which is NOT the noHighScoresTextView."""
    for n in nodes:
        if (n.get("text", "").strip().lower() == "high scores"
                and "TextView" in n.get("class", "")
                and not n.get("resource-id", "").endswith("/noHighScoresTextView")):
            return n
    return None


# ══════════════════════════════════════════════════════════════════════════════
# Depth-family helpers — the and_reach_*/and_enter_* NAME is what backs the
# declared depth>=1 (the depth audit descends into these file-local helpers).
# ══════════════════════════════════════════════════════════════════════════════

def and_reach_about():
    """Depth 1: tap HELP on the menu, confirm the AboutActivity body appeared."""
    n = node_by_id(ui(), "aboutButton") or find_node_ci(ui(), "Help")
    if not n or not tap_node(n):
        return False
    for _ in range(5):
        if about_text(ui()):
            and_enter("about")
            return True
        settle("tap")
    return False


def and_enter_preferences():
    """Depth 1: tap PREFERENCES on the menu, wait for the Sound row to appear."""
    n = node_by_id(ui(), "preferencesButton") or find_node_ci(ui(), "Preferences")
    if not n or not tap_node(n):
        return False
    for _ in range(5):
        if on_prefs():
            and_enter("preferences")
            return True
        settle("tap")
    return False


def and_reach_high_scores():
    """Depth 1: tap HIGH SCORES on the menu (panel swap within the activity),
    confirm the hideHighScoreButton (OK) appeared."""
    n = node_by_id(ui(), "highScoreButton") or find_node_ci(ui(), "High scores")
    if not n or not tap_node(n):
        return False
    for _ in range(5):
        if node_by_id(ui(), "hideHighScoreButton"):
            and_enter("high_scores")
            return True
        settle("tap")
    return False


def and_enter_gamespeed_dialog():
    """Depth 2: Preferences -> tap the 'Game speed' row -> AlertDialog. Confirms
    the three option CheckedTextViews are present."""
    if not and_enter_preferences():
        return False
    row = pref_title(ui(), "Game speed")
    if not row or not tap_node(row):
        return False
    for _ in range(5):
        d = ui()
        if find_node(d, text="Slow") and find_node(d, text="Fast"):
            and_enter("gamespeed_dialog")
            return True
        settle("tap")
    return False


def and_enter_line_width_dialog():
    """Depth 2: Preferences -> tap the 'Line width' row -> AlertDialog. Confirms
    the dialog's EditText/OK appeared."""
    if not and_enter_preferences():
        return False
    row = pref_title(ui(), "Line width")
    if row is None:
        scroll_into_view("Line width")
        row = pref_title(ui(), "Line width")
    if not row or not tap_node(row):
        return False
    for _ in range(5):
        d = ui()
        if node_by_id(d, "OK") or find_node(d, text="OK") or find_by_class(d, "EditText"):
            and_enter("line_width_dialog")
            return True
        settle("tap")
    return False


def _play_taps(rounds=12):
    """Launch the ball and bat at the flippers by tapping the canvas field.
    Coordinates are DERIVED from get_screen_info() — never a pixel literal."""
    s = get_screen_info()
    for _ in range(rounds):
        tap(int(s["width"] * 0.5), int(s["height"] * 0.75))   # launch / centre
        tap(int(s["width"] * 0.2), int(s["height"] * 0.85))   # left flipper zone
        tap(int(s["width"] * 0.8), int(s["height"] * 0.85))   # right flipper zone


def and_reach_menu_with_high_score():
    """Depth 1: from a clean install, START GAME, bat the ball to score, pause,
    END GAME, then restart the app. The restarted menu's canvas top strip then
    renders the 'High Score: <n>' banner (the last-score line is in-memory only
    and is cleared by the restart, so the menu falls back to the high-score
    banner). Returns True once gameplay was actually entered."""
    clear_data()
    launch_app()
    wait_for_foreground()
    sg = node_by_id(ui(), "startGameButton")
    if not sg or not tap_node(sg):
        return False
    settle("tap")
    if node_by_id(ui(), "pauseIcon") is None:
        return False
    and_enter("gameplay")
    _play_taps()
    pi = node_by_id(ui(), "pauseIcon")
    if pi:
        tap_node(pi)
        settle("tap")
    eg = node_by_id(ui(), "endGameButton")
    if eg:
        tap_node(eg)
        settle("tap")
    # Restart so the in-memory last-score clears and the menu shows the high score.
    restart_app()
    wait_for_foreground()
    ui()
    return True


# ══════════════════════════════════════════════════════════════════════════════
# (A) About activity — action-produced body content (depth 1)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_about_content",))
def test_about_content():
    """HELP -> AboutActivity: the aboutTextView body contains the stable authored
    strings 'Brian Nenninger', 'Table Rules', the contact email and the project
    URL. (The version number is intentionally NOT asserted — it changes.) depth 1.
    """
    restart_app()
    wait_for_foreground()
    absent = "brian nenninger" not in norm(all_text(ui()))
    if not and_reach_about():
        record("text_about_content", False,
               "setup_failed: could not open the About screen from HELP",
               depth=1, jump_kind="value",
               expect="About body contains 'Brian Nenninger', 'Table Rules', "
                      "'bnenning@gmail.com', github URL")
        return
    body = norm(about_text(ui()))
    checks = {
        "Brian Nenninger": "brian nenninger" in body,
        "Table Rules": "table rules" in body,
        "bnenning@gmail.com": "bnenning@gmail.com" in body,
        "github URL": "github.com/dozingcat/vector-pinball" in body,
    }
    ok = absent and all(checks.values())
    missing = [k for k, v in checks.items() if not v]
    record("text_about_content", ok,
           "" if ok else (f"behavior_wrong: About body missing {missing}"
                          if missing else
                          "behavior_wrong: 'Brian Nenninger' was already present "
                          "before opening About"),
           depth=1, jump_kind="value",
           expect="About body contains 'Brian Nenninger', 'Table Rules', "
                  "'bnenning@gmail.com', 'github.com/dozingcat/Vector-Pinball'")


@and_test(expects=("text_about_preferences_section",))
def test_about_preferences_section():
    """HELP -> AboutActivity body also documents the settings: it contains the
    'Preferences menu item' lead-in and the per-setting descriptions for Sound,
    Haptic Feedback and Independent Flippers. depth 1."""
    restart_app()
    wait_for_foreground()
    if not and_reach_about():
        record("text_about_preferences_section", False,
               "setup_failed: could not open the About screen from HELP",
               depth=1, jump_kind="value",
               expect="About body documents Sound / Haptic Feedback / "
                      "Independent Flippers preferences")
        return
    body = norm(about_text(ui()))
    checks = {
        "Preferences lead-in": "the preferences menu item allows you to change" in body,
        "Sound desc": "sound: enables and disables sound effects" in body,
        "Haptic desc": "haptic feedback: vibrates on bumper hits" in body,
        "Independent Flippers desc": "independent flippers: when unchecked" in body,
    }
    ok = all(checks.values())
    missing = [k for k, v in checks.items() if not v]
    record("text_about_preferences_section", ok,
           "" if ok else f"behavior_wrong: About settings section missing {missing}",
           depth=1, jump_kind="value",
           expect="About body: 'The Preferences menu item allows you to change...' "
                  "plus Sound / Haptic Feedback / Independent Flippers descriptions")


@and_test(expects=("text_about_table_rules_differ",))
def test_about_table_rules_differ():
    """FLAGSHIP dynamic content: the About body's Table Rules block changes with
    the SELECTED table. From a fresh menu (table 1) -> HELP, the rules contain
    table-1 phrasing ('top or bottom lanes', 'central light') and NOT table-2
    phrasing. From a fresh menu, tap the next-table arrow (-> table 2) -> HELP,
    the rules now contain table-2 phrasing ('circles in the middle', 'red bumper
    in the upper right') and NOT table-1 phrasing. Assert BOTH directions so the
    two About texts provably DIFFER. depth 1, transition."""
    T1 = ("light all the cyan rollovers in the top or bottom lanes", "central light")
    T2 = ("the circles in the middle of the field keep track",
          "red bumper in the upper right")

    # --- Table 1 (fresh menu) ---
    restart_app()
    wait_for_foreground()
    if not and_reach_about():
        record("text_about_table_rules_differ", False,
               "setup_failed: could not open About for table 1",
               depth=1, jump_kind="transition",
               expect="table-1 rules phrasing present, table-2 phrasing absent")
        return
    body1 = norm(about_text(ui()))
    t1_has_t1 = all(p in body1 for p in T1)
    t1_has_t2 = any(p in body1 for p in T2)

    # --- Table 2 (fresh menu -> next table once -> HELP) ---
    and_reset_depth()
    restart_app()
    wait_for_foreground()
    nxt = node_by_id(ui(), "nextTableButton")
    if nxt is None or not tap_node(nxt):
        record("text_about_table_rules_differ", False,
               "setup_failed: nextTableButton not found on the menu",
               depth=1, jump_kind="transition",
               expect="table-2 rules phrasing present after selecting next table")
        return
    settle("tap")
    if not and_reach_about():
        record("text_about_table_rules_differ", False,
               "setup_failed: could not open About for table 2",
               depth=1, jump_kind="transition",
               expect="table-2 rules phrasing present, table-1 phrasing absent")
        return
    body2 = norm(about_text(ui()))
    t2_has_t2 = all(p in body2 for p in T2)
    t2_has_t1 = any(p in body2 for p in T1)

    differ = body1 != body2
    ok = (t1_has_t1 and not t1_has_t2 and t2_has_t2 and not t2_has_t1 and differ)
    record("text_about_table_rules_differ", ok,
           "" if ok else (f"behavior_wrong: table-rules did not switch with the "
                          f"selected table (t1[t1={t1_has_t1},t2={t1_has_t2}] "
                          f"t2[t2={t2_has_t2},t1={t2_has_t1}] differ={differ})"),
           depth=1, jump_kind="transition",
           expect="table1 About has 'top or bottom lanes'/'central light' (no "
                  "table2 phrasing); table2 About has 'circles in the middle'/"
                  "'red bumper in the upper right' (no table1 phrasing)")


# ══════════════════════════════════════════════════════════════════════════════
# (B) High Scores panel title (depth 1)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_highscores_panel_title",))
def test_highscores_panel_title():
    """HIGH SCORES -> highScorePanel: the panel's TITLE reads 'High scores'. The
    title is ABSENT on the menu before the panel opens and PRESENT after. (The
    'No scores'/'Last Score' facts are INTERACTION's — not asserted here.) depth 1.
    """
    clear_data()
    launch_app()
    wait_for_foreground()
    absent = highscore_title(ui()) is None
    if not and_reach_high_scores():
        record("text_highscores_panel_title", False,
               "setup_failed: could not open the High Scores panel",
               depth=1, jump_kind="value", expect="panel title reads 'High scores'")
        return
    title = highscore_title(ui())
    present = title is not None and norm(title.get("text", "")) == "high scores"
    ok = absent and present
    record("text_highscores_panel_title", ok,
           "" if ok else ("behavior_wrong: High Scores panel title was not "
                          "'High scores'" if not present else
                          "behavior_wrong: 'High scores' title was already present "
                          "before opening the panel"),
           depth=1, jump_kind="value",
           expect="High Scores panel title TextView == 'High scores'")


# ══════════════════════════════════════════════════════════════════════════════
# (C) Preference row titles (depth 1)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_prefs_row_titles_all",))
def test_prefs_row_titles_all():
    """PREFERENCES -> the row list renders every authored row title. Assert the
    full set is present (a couple may need scroll_into_view). depth 1."""
    clear_data()
    launch_app()
    wait_for_foreground()
    if not and_enter_preferences():
        record("text_prefs_row_titles_all", False,
               "setup_failed: could not reach Preferences",
               depth=1, jump_kind="value", expect="all preference row titles present")
        return
    wanted = ["Sound", "Background music", "Haptic feedback", "Zoom playfield",
              "Ball trails", "Score animations", "OpenGL rendering", "Game speed",
              "Line width", "Show FPS"]
    missing = []
    for label in wanted:
        if pref_title(ui(), label) is None:
            if scroll_into_view(label) is None or pref_title(ui(), label) is None:
                missing.append(label)
    ok = not missing
    record("text_prefs_row_titles_all", ok,
           "" if ok else f"behavior_wrong: preference row titles missing {missing}",
           depth=1, jump_kind="value",
           expect="rows Sound / Background music / Haptic feedback / Zoom playfield "
                  "/ Ball trails / Score animations / OpenGL rendering / Game speed "
                  "/ Line width / Show FPS all present")


@and_test(expects=("text_prefs_row_music",))
def test_prefs_row_music_title():
    """Individual exact row title: PREFERENCES renders a row titled 'Background
    music' (absent on the menu, present in the list). depth 1."""
    clear_data()
    launch_app()
    wait_for_foreground()
    absent = pref_title(ui(), "Background music") is None
    if not and_enter_preferences():
        record("text_prefs_row_music", False,
               "setup_failed: could not reach Preferences",
               depth=1, jump_kind="value", expect="row titled 'Background music'")
        return
    n = pref_title(ui(), "Background music")
    present = n is not None and norm(n.get("text", "")) == "background music"
    ok = absent and present
    record("text_prefs_row_music", ok,
           "" if ok else "behavior_wrong: no 'Background music' preference row",
           depth=1, jump_kind="value",
           expect="preference row title == 'Background music'")


@and_test(expects=("text_prefs_row_opengl",))
def test_prefs_row_opengl_title():
    """Individual exact row title: PREFERENCES renders a row titled 'OpenGL
    rendering'. depth 1."""
    clear_data()
    launch_app()
    wait_for_foreground()
    if not and_enter_preferences():
        record("text_prefs_row_opengl", False,
               "setup_failed: could not reach Preferences",
               depth=1, jump_kind="value", expect="row titled 'OpenGL rendering'")
        return
    n = pref_title(ui(), "OpenGL rendering") or (
        scroll_into_view("OpenGL rendering") and pref_title(ui(), "OpenGL rendering"))
    present = n is not None and norm(n.get("text", "")) == "opengl rendering"
    record("text_prefs_row_opengl", present,
           "" if present else "behavior_wrong: no 'OpenGL rendering' preference row",
           depth=1, jump_kind="value",
           expect="preference row title == 'OpenGL rendering'")


# ══════════════════════════════════════════════════════════════════════════════
# (D) Preference dialogs — titles + messages + option labels (depth 2)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_linewidth_dialog_message",))
def test_linewidth_dialog_message():
    """PREFERENCES -> 'Line width' -> AlertDialog: the message TextView reads the
    exact authored explanation. depth 2."""
    clear_data()
    launch_app()
    wait_for_foreground()
    expected = ("Enter the line width in pixels, or 0 to use a default width "
                "based on the screen resolution.")
    if not and_enter_line_width_dialog():
        record("text_linewidth_dialog_message", False,
               "setup_failed: could not open the Line width dialog",
               depth=2, jump_kind="value", expect=expected)
        return
    d = ui()
    found = any(norm(n.get("text", "")) == norm(expected) for n in d)
    record("text_linewidth_dialog_message", found,
           "" if found else "behavior_wrong: Line width dialog message text did not "
                            "match the authored explanation",
           depth=2, jump_kind="value", expect=expected)


@and_test(expects=("text_linewidth_dialog_title",))
def test_linewidth_dialog_title():
    """PREFERENCES -> 'Line width' -> AlertDialog: the dialog TITLE reads 'Line
    width'. depth 2."""
    clear_data()
    launch_app()
    wait_for_foreground()
    if not and_enter_line_width_dialog():
        record("text_linewidth_dialog_title", False,
               "setup_failed: could not open the Line width dialog",
               depth=2, jump_kind="value", expect="dialog title == 'Line width'")
        return
    d = ui()
    # The title is a non-EditText, non-Button TextView reading 'Line width'.
    found = any(norm(n.get("text", "")) == "line width"
                and "TextView" in n.get("class", "")
                and "EditText" not in n.get("class", "")
                for n in d)
    record("text_linewidth_dialog_title", found,
           "" if found else "behavior_wrong: Line width dialog title was not "
                            "'Line width'",
           depth=2, jump_kind="value", expect="Line width dialog title == 'Line width'")


@and_test(expects=("text_gamespeed_dialog_options",))
def test_gamespeed_dialog_options():
    """PREFERENCES -> 'Game speed' -> AlertDialog: the three option
    CheckedTextViews read exactly 'Slow', 'Normal', 'Fast'. (The selection
    consequence is STATES'; the option LABEL strings are this lane's.) depth 2."""
    clear_data()
    launch_app()
    wait_for_foreground()
    if not and_enter_gamespeed_dialog():
        record("text_gamespeed_dialog_options", False,
               "setup_failed: could not open the Game speed dialog",
               depth=2, jump_kind="value", expect="options 'Slow', 'Normal', 'Fast'")
        return
    d = ui()
    opts = {norm(n.get("text", "")) for n in d
            if "CheckedTextView" in n.get("class", "") and n.get("text", "").strip()}
    if not opts:  # fall back to any option-like text if the class differs
        opts = {norm(n.get("text", "")) for n in d
                if norm(n.get("text", "")) in ("slow", "normal", "fast")}
    ok = {"slow", "normal", "fast"}.issubset(opts)
    record("text_gamespeed_dialog_options", ok,
           "" if ok else f"behavior_wrong: Game speed option labels wrong (saw {sorted(opts)})",
           depth=2, jump_kind="value",
           expect="Game speed dialog options == Slow / Normal / Fast")


@and_test(expects=("text_gamespeed_dialog_title",))
def test_gamespeed_dialog_title():
    """PREFERENCES -> 'Game speed' -> AlertDialog: the dialog TITLE reads 'Game
    speed'. depth 2."""
    clear_data()
    launch_app()
    wait_for_foreground()
    if not and_enter_gamespeed_dialog():
        record("text_gamespeed_dialog_title", False,
               "setup_failed: could not open the Game speed dialog",
               depth=2, jump_kind="value", expect="dialog title == 'Game speed'")
        return
    d = ui()
    # Title reads 'Game speed' and is not one of the CheckedTextView options.
    found = any(norm(n.get("text", "")) == "game speed"
                and "CheckedTextView" not in n.get("class", "")
                and "TextView" in n.get("class", "")
                for n in d)
    record("text_gamespeed_dialog_title", found,
           "" if found else "behavior_wrong: Game speed dialog title was not "
                            "'Game speed'",
           depth=2, jump_kind="value", expect="Game speed dialog title == 'Game speed'")


# ══════════════════════════════════════════════════════════════════════════════
# (E) Menu surface static labels (depth 0 — kept few; the dynamic tests carry depth)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_menu_button_labels",))
def test_menu_button_labels():
    """The fresh-menu buttons render the app-unique UPPERCASE labels 'START GAME',
    'HIGH SCORES', 'HELP', 'PREFERENCES', 'QUIT'. depth 0."""
    restart_app()
    wait_for_foreground()
    nodes = ui()
    wanted = ["START GAME", "HIGH SCORES", "HELP", "PREFERENCES", "QUIT"]
    missing = [w for w in wanted if find_node_ci(nodes, w) is None]
    ok = not missing
    record("text_menu_button_labels", ok,
           "" if ok else f"behavior_wrong: menu button labels missing {missing}",
           depth=0, jump_kind="value",
           expect="menu buttons START GAME / HIGH SCORES / HELP / PREFERENCES / QUIT")


@and_test(expects=("text_menu_select_table_labels",))
def test_menu_select_table_labels():
    """The fresh-menu table-picker row renders 'Select Table' and the toggle
    renders 'Unlimited Balls' (both keep their mixed case). depth 0."""
    restart_app()
    wait_for_foreground()
    nodes = ui()
    has_select = find_node_ci(nodes, "Select Table") is not None
    has_unlim = find_node_ci(nodes, "Unlimited Balls") is not None
    ok = has_select and has_unlim
    record("text_menu_select_table_labels", ok,
           "" if ok else (f"behavior_wrong: menu labels wrong "
                          f"(Select Table={has_select}, Unlimited Balls={has_unlim})"),
           depth=0, jump_kind="value",
           expect="menu shows 'Select Table' and 'Unlimited Balls'")


# ══════════════════════════════════════════════════════════════════════════════
# (F) VLM — canvas-only status text the view tree never carries (exactly 2)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_menu_touch_to_start_vlm",))
def test_menu_touch_to_start_vlm():
    """The fresh-menu top status strip (scoreView, a Canvas) renders the words
    'Touch to start'. This text never reaches the view tree, so it is a legitimate
    VLM content assertion. clear_data guarantees the fresh (no-high-score) state
    where this banner — not the high-score banner — is shown. depth 0."""
    clear_data()
    launch_app()
    wait_for_foreground()
    ui()  # let the menu settle before the screenshot
    vlm_assert("text_menu_touch_to_start",
               "In the thin status strip at the very top of this pinball menu "
               "screen, do the words 'Touch to start' appear?",
               RESULTS_DIR, depth=0, jump_kind="none", tag="content")


@and_test(expects=("text_high_score_banner_vlm",))
def test_high_score_banner_vlm():
    """After PLAYING and ENDING a game, the menu's top status strip (Canvas)
    renders a banner beginning 'High Score:' followed by the recorded number.
    Produced by the play->end->restart action; canvas-only, so VLM. depth 1."""
    if not and_reach_menu_with_high_score():
        # The @and_test denominator back-fills the declared _vlm name as a failure,
        # so a setup miss on the original still contributes exactly one record.
        record("text_high_score_banner_vlm", False,
               "setup_failed: could not play and end a game to produce a high score",
               depth=1, jump_kind="none", tag="content")
        return
    vlm_assert("text_high_score_banner",
               "Does the text in the very top status strip of this pinball menu "
               "screen begin with the words 'High Score:' followed by a number?",
               RESULTS_DIR, depth=1, jump_kind="none", tag="content")


TESTS = [
    # About activity — body content + dynamic table rules (depth 1)
    test_about_content,
    test_about_preferences_section,
    test_about_table_rules_differ,
    # High Scores panel title (depth 1)
    test_highscores_panel_title,
    # Preference row titles (depth 1)
    test_prefs_row_titles_all,
    test_prefs_row_music_title,
    test_prefs_row_opengl_title,
    # Preference dialogs — titles / message / option labels (depth 2)
    test_linewidth_dialog_message,
    test_linewidth_dialog_title,
    test_gamespeed_dialog_options,
    test_gamespeed_dialog_title,
    # Menu static labels (depth 0)
    test_menu_button_labels,
    test_menu_select_table_labels,
    # VLM — canvas-only status text (exactly 2)
    test_menu_touch_to_start_vlm,
    test_high_score_banner_vlm,
]


if __name__ == "__main__":
    run_suite(TESTS, "text")