File size: 29,297 Bytes
c1c6a0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""TEXT lane — EasyNotes (Kotlin/Compose note app).

This lane owns CONTENT / OUTPUT text and is the SOLE owner of exact-string
equality: strings an interaction PRODUCES (empty/no-match placeholders, the card
that reflects a typed title/body, status/label strings on surfaces you open) and
opaque rendered cores (markdown that renders to a surface the view tree cannot
give as a formatted string).

Every test drives the app through the user path, reads the produced string out of
a FRESH ui(), and asserts it. Discriminating tests assert ABSENT-before /
PRESENT-after where the string is produced by a trigger.

Package comes ONLY from argv[1]; no literal package/coordinate/serial appears here.
"""
import os
import re
import sys

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


# ── local helpers ────────────────────────────────────────────────────────────

def all_text(nodes):
    """All visible `text` values joined — for substring/normalised comparison."""
    return " | ".join(n.get("text", "") for n in nodes if n.get("text"))


def all_desc(nodes):
    """All content-desc values joined — for content-desc string assertions."""
    return " | ".join(n.get("content-desc", "") for n in nodes if n.get("content-desc"))


def unescape_entities(s):
    """The kit's XML parser does NOT decode HTML entities, so a label whose visible
    text is 'Colors & Styles' arrives as the literal 'Colors & Styles'.
    Normalise both sides before an exact-string comparison so the entity never
    causes a false failure."""
    return (s.replace("&amp;", "&").replace("&lt;", "<").replace("&gt;", ">")
             .replace("&apos;", "'").replace("&quot;", '"'))


def norm(s):
    """Entity-decode + strip + casefold — a faithful recreation may differ in case
    but not in the words."""
    return unescape_entities(s).strip().casefold()


def contains_text(nodes, needle):
    """True iff any node's (entity-decoded) text contains `needle`, case-insensitive."""
    n = norm(needle)
    return any(n in norm(x) for x in (nd.get("text", "") for nd in nodes) if x)


def contains_desc(nodes, needle):
    n = norm(needle)
    return any(n in norm(x) for x in (nd.get("content-desc", "") for nd in nodes) if x)


def edittexts_by_y(nodes):
    """The Edit page has two unlabelled EditTexts (Name on top, Description below);
    document order is not reliable, so order by y."""
    return sorted(find_by_class(nodes, "EditText"),
                  key=lambda n: n.get("_bounds", (0, 0, 0, 0))[1])


def open_home():
    """Fresh Home with app data intact."""
    restart_app()
    wait_for_foreground()
    settle("launch")


def open_empty_home():
    """Fresh Home with NO notes (empty DB)."""
    clear_data()
    launch_app()
    wait_for_foreground()
    settle("launch")


def create_note(title, body):
    """Create a note through the GUI (New Note FAB → Name → Description → Done).
    Returns True if it left the Edit surface back to Home."""
    fab = find_node(ui(), content_desc="New Note")
    if not tap_node(fab):
        return False
    settle("tap")
    fields = edittexts_by_y(ui())
    if not fields:
        return False
    if title:
        type_text(fields[0], title)
        settle("text")
    if body:
        fields = edittexts_by_y(ui())
        if len(fields) > 1:
            type_text(fields[1], body)
            settle("text")
    done = find_node(ui(), content_desc="Done")
    if not tap_node(done):
        return False
    settle("tap")
    return True


# ── depth-family helpers (name-backed so a declared depth>=1 is honest) ────────

def and_enter_settings():
    """Home → Settings gear. Counts one surface."""
    n = find_node(ui(), content_desc="Settings")
    ok = and_reach_surface(n, "Support", "New Note") if n else False
    if not ok and n:                      # fall back to a generic surface change
        before = and_showing()
        tap_node(n)
        if surface_changed(before, and_showing()):
            and_enter("Settings")
            ok = True
    return ok


def and_enter_about():
    """(assumes on Settings) Settings → About. Counts one surface."""
    n = find_node_ci(ui(), "About") or scroll_into_view("About")
    if not n:
        return False
    before = and_showing()
    tap_node(n)
    if surface_changed(before, and_showing()):
        and_enter("About")
        return True
    return False


def and_enter_preview(title):
    """Home → open a note card (opens on the Preview page). Counts one surface."""
    n = find_node(ui(), text=title)
    if not n:
        return False
    before = and_showing()
    tap(n["_center"][0], n["_center"][1])
    settle("tap")
    if surface_changed(before, and_showing()):
        and_enter("Preview")
        return True
    return False


def and_enter_more_menu():
    """(assumes on Preview) tap Info (⋮) → More dropdown. Counts one surface."""
    n = find_node(ui(), content_desc="Info")
    if not n:
        return False
    before = and_showing()
    tap_node(n)
    settle("tap")
    if surface_changed(before, and_showing()):
        and_enter("More")
        return True
    return False


def and_reach_note_info():
    """(assumes More dropdown open) tap Information → Note Info bottom sheet."""
    n = find_node_ci(ui(), "Information")
    if not n:
        return False
    return and_reach_surface(n, "Created Time", "Copy")


# ══════════════════════════════════════════════════════════════════════════════
# Placeholder strings produced by empty / no-match states
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_empty_home_placeholder",))
def test_empty_home_placeholder():
    open_empty_home()
    nodes = ui()
    got = contains_text(nodes, "No created notes.")
    record("text_empty_home_placeholder", got,
           "" if got else "behavior_wrong: empty Home did not show the "
           "placeholder 'No created notes.' — got text=%r" % all_text(nodes),
           depth=0, jump_kind="value", expect="No created notes.")


@and_test(expects=("text_search_no_match",))
def test_search_no_match():
    open_empty_home()
    if not create_note("Groceries", "Milk"):
        record("text_search_no_match", False,
               "setup_failed: could not create a note to search over",
               depth=0, jump_kind="value", expect="No notes found.")
        return
    # Trigger: type a query that matches nothing.
    before = contains_text(ui(), "No notes found.")
    stext = find_node(ui(), text="Search") or find_node(ui(), content_desc="Search")
    if not tap_node(stext):
        record("text_search_no_match", False,
               "setup_failed: could not focus the search bar",
               depth=0, jump_kind="value", expect="No notes found.")
        return
    settle("tap")
    field = find_by_class(ui(), "EditText")
    if not field:
        record("text_search_no_match", False,
               "setup_failed: search bar did not become an editable field",
               depth=0, jump_kind="value", expect="No notes found.")
        return
    type_text(field[0], "zzqqxx", verify_focus=False)
    settle("text")
    after = contains_text(ui(), "No notes found.")
    ok = (not before) and after
    record("text_search_no_match", ok,
           "" if ok else "behavior_wrong: gibberish query did not produce the "
           "'No notes found.' placeholder (before=%s after=%s)" % (before, after),
           depth=0, jump_kind="value", expect="No notes found.")


@and_test(expects=("text_empty_note_discard_placeholder",))
def test_empty_note_discard_placeholder():
    # An empty note (no title, no body) is discarded on leave -> the produced
    # string after this no-op create is still the empty placeholder. The trigger
    # dips into Edit and back, but the OBSERVATION is read on Home, so depth=0.
    open_empty_home()
    if not create_note("", ""):
        record("text_empty_note_discard_placeholder", False,
               "setup_failed: could not open/leave a new empty note",
               depth=0, jump_kind="value", expect="No created notes.")
        return
    nodes = ui()
    ok = contains_text(nodes, "No created notes.")
    record("text_empty_note_discard_placeholder", ok,
           "" if ok else "behavior_wrong: after discarding an empty note the Home "
           "placeholder 'No created notes.' was absent — got %r" % all_text(nodes),
           depth=0, jump_kind="value", expect="No created notes.")


# ══════════════════════════════════════════════════════════════════════════════
# The card content an ACTION produced — exact title / body strings
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_card_title",))
def test_card_title_reflects_typed_title():
    open_empty_home()
    absent = contains_text(ui(), "GroceryList")
    if not create_note("GroceryList", "Milk and eggs"):
        record("text_card_title", False,
               "setup_failed: could not create the note",
               depth=0, jump_kind="value", expect="GroceryList")
        return
    nodes = ui()
    # exact title string on the produced card
    title_node = find_node(nodes, text="GroceryList")
    ok = (not absent) and title_node is not None
    record("text_card_title", ok,
           "" if ok else "behavior_wrong: produced card title != 'GroceryList' "
           "(got text=%r)" % all_text(nodes),
           depth=0, jump_kind="value", expect="GroceryList")


@and_test(expects=("text_card_body_preview",))
def test_card_body_reflects_typed_body():
    open_empty_home()
    if not create_note("GroceryList", "Milk and eggs"):
        record("text_card_body_preview", False,
               "setup_failed: could not create the note",
               depth=0, jump_kind="value", expect="Milk and eggs")
        return
    nodes = ui()
    ok = contains_text(nodes, "Milk and eggs")
    record("text_card_body_preview", ok,
           "" if ok else "behavior_wrong: card body preview did not contain the "
           "typed body 'Milk and eggs' — got %r" % all_text(nodes),
           depth=0, jump_kind="value", expect="Milk and eggs")


@and_test(expects=("text_home_card_strips_markdown",))
def test_home_card_body_strips_markdown():
    # A body of "# Heading" renders on the Home card preview as "Heading" (the '#'
    # marker stripped) — a produced, markdown-rendered string.
    open_empty_home()
    if not create_note("MdCard", "# Heading"):
        record("text_home_card_strips_markdown", False,
               "setup_failed: could not create the markdown note",
               depth=0, jump_kind="value", expect="Heading (no '#')")
        return
    nodes = ui()
    has_heading = contains_text(nodes, "Heading")
    # the raw '#Heading'/'# Heading' marker must NOT survive in the preview text
    raw_hash = any("#" in (n.get("text", "")) for n in nodes)
    ok = has_heading and not raw_hash
    record("text_home_card_strips_markdown", ok,
           "" if ok else "behavior_wrong: Home card did not render '# Heading' as "
           "'Heading' without the '#' (has_heading=%s raw_hash=%s text=%r)"
           % (has_heading, raw_hash, all_text(nodes)),
           depth=0, jump_kind="value", expect="Heading (no '#')")


# ══════════════════════════════════════════════════════════════════════════════
# content-desc strings PRODUCED on a state change (focus Description)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_desc_focus_toolbar_descs",))
def test_desc_focus_shows_markdown_toolbar_descs():
    # Trigger: focus the Description field -> the markdown toolbar appears with the
    # content-desc strings "Bullet List", "Checkbox", "Insert Image".
    open_home()
    fab = find_node(ui(), content_desc="New Note")
    if not tap_node(fab):
        record("text_desc_focus_toolbar_descs", False,
               "setup_failed: New Note FAB not tappable",
               depth=1, jump_kind="value", expect="Checkbox, Insert Image")
        return
    settle("tap")
    before_desc = all_desc(ui())
    absent = ("Checkbox" not in before_desc) and ("Insert Image" not in before_desc)
    fields = edittexts_by_y(ui())
    if len(fields) < 2:
        record("text_desc_focus_toolbar_descs", False,
               "setup_failed: no Description field on the Edit surface",
               depth=1, jump_kind="value", expect="Checkbox, Insert Image")
        return
    and_enter("markdown toolbar")          # focusing Desc reveals the toolbar surface
    tap_node(fields[1])
    settle("keyboard")
    nodes = ui()
    present = contains_desc(nodes, "Checkbox") and contains_desc(nodes, "Insert Image")
    ok = absent and present
    record("text_desc_focus_toolbar_descs", ok,
           "" if ok else "behavior_wrong: focusing Description did not reveal the "
           "toolbar content-descs 'Checkbox'/'Insert Image' (absent=%s present=%s "
           "desc=%r)" % (absent, present, all_desc(nodes)),
           depth=1, jump_kind="value", expect="Checkbox, Insert Image")


@and_test(expects=("text_desc_focus_undo_redo_descs",))
def test_desc_focus_shows_undo_redo_descs():
    # Trigger: focus Description -> "Undo" and "Redo" content-desc appear in the top bar.
    open_home()
    fab = find_node(ui(), content_desc="New Note")
    if not tap_node(fab):
        record("text_desc_focus_undo_redo_descs", False,
               "setup_failed: New Note FAB not tappable",
               depth=1, jump_kind="value", expect="Undo, Redo")
        return
    settle("tap")
    before_desc = all_desc(ui())
    absent = ("Undo" not in before_desc) and ("Redo" not in before_desc)
    fields = edittexts_by_y(ui())
    if len(fields) < 2:
        record("text_desc_focus_undo_redo_descs", False,
               "setup_failed: no Description field on the Edit surface",
               depth=1, jump_kind="value", expect="Undo, Redo")
        return
    and_enter("edit-with-undo-redo")
    tap_node(fields[1])
    settle("keyboard")
    nodes = ui()
    present = contains_desc(nodes, "Undo") and contains_desc(nodes, "Redo")
    ok = absent and present
    record("text_desc_focus_undo_redo_descs", ok,
           "" if ok else "behavior_wrong: focusing Description did not reveal the "
           "'Undo'/'Redo' content-descs (absent=%s present=%s desc=%r)"
           % (absent, present, all_desc(nodes)),
           depth=1, jump_kind="value", expect="Undo, Redo")


# ══════════════════════════════════════════════════════════════════════════════
# Settings section label strings (depth 1)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_settings_section_labels",))
def test_settings_section_labels():
    open_home()
    if not and_enter_settings():
        record("text_settings_section_labels", False,
               "setup_failed: could not reach the Settings surface",
               depth=1, jump_kind="value",
               expect="Colors & Styles, Behavior, Language, Backup")
        return
    nodes = ui()
    # exact section strings; "Colors & Styles" arrives entity-encoded -> normalise
    wanted = ["Colors & Styles", "Behavior", "Language", "Backup",
              "Privacy", "Tools", "About"]
    missing = [w for w in wanted if not contains_text(nodes, w)]
    ok = not missing
    record("text_settings_section_labels", ok,
           "" if ok else "behavior_wrong: Settings missing section label(s) %r "
           "— got text=%r" % (missing, all_text(nodes)),
           depth=1, jump_kind="value",
           expect="Colors & Styles, Behavior, Language, Backup, Privacy, Tools, About")


# ══════════════════════════════════════════════════════════════════════════════
# About label strings (depth 2) — assert the LABELS, not the version VALUE
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_about_labels",))
def test_about_labels():
    open_home()
    if not and_enter_settings():
        record("text_about_labels", False,
               "setup_failed: could not reach Settings",
               depth=2, jump_kind="value", expect="Version, Build Type")
        return
    if not and_enter_about():
        record("text_about_labels", False,
               "setup_failed: could not reach the About surface",
               depth=2, jump_kind="value", expect="Version, Build Type")
        return
    nodes = ui()
    # Assert the produced LABEL strings only — a recreation cannot know the value
    # "1.7-fdroid", so asserting it would be unfair rather than discriminating.
    has_version = contains_text(nodes, "Version")
    has_build = contains_text(nodes, "Build Type")
    ok = has_version and has_build
    record("text_about_labels", ok,
           "" if ok else "behavior_wrong: About missing label(s) "
           "'Version'/'Build Type' (version=%s build=%s text=%r)"
           % (has_version, has_build, all_text(nodes)),
           depth=2, jump_kind="value", expect="Version, Build Type")


# ══════════════════════════════════════════════════════════════════════════════
# More dropdown label strings (depth 2)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_more_menu_labels",))
def test_more_menu_labels():
    open_empty_home()
    if not create_note("MenuNote", "some body text"):
        record("text_more_menu_labels", False,
               "setup_failed: could not create a note to open",
               depth=2, jump_kind="value", expect="Pinned, Copy, Information")
        return
    if not and_enter_preview("MenuNote"):
        record("text_more_menu_labels", False,
               "setup_failed: could not open the note Preview",
               depth=2, jump_kind="value", expect="Pinned, Copy, Information")
        return
    if not and_enter_more_menu():
        record("text_more_menu_labels", False,
               "setup_failed: could not open the More (Info) dropdown",
               depth=2, jump_kind="value", expect="Pinned, Copy, Information")
        return
    nodes = ui()
    # exact non-destructive menu label strings the dropdown produced
    wanted = ["Pinned", "Copy", "Information"]
    missing = [w for w in wanted if not contains_text(nodes, w)]
    ok = not missing
    record("text_more_menu_labels", ok,
           "" if ok else "behavior_wrong: More dropdown missing label(s) %r — "
           "got text=%r" % (missing, all_text(nodes)),
           depth=2, jump_kind="value", expect="Pinned, Copy, Information")


# ══════════════════════════════════════════════════════════════════════════════
# Note Info modal label strings + Created Time FORMAT (depth 3)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_note_info_labels",))
def test_note_info_labels():
    open_empty_home()
    if not create_note("InfoNote", "Milk Eggs Bread"):
        record("text_note_info_labels", False,
               "setup_failed: could not create the note",
               depth=3, jump_kind="value", expect="Created Time, Words, Characters")
        return
    if not and_enter_preview("InfoNote"):
        record("text_note_info_labels", False,
               "setup_failed: could not open Preview",
               depth=3, jump_kind="value", expect="Created Time, Words, Characters")
        return
    if not and_enter_more_menu():
        record("text_note_info_labels", False,
               "setup_failed: could not open the More dropdown",
               depth=3, jump_kind="value", expect="Created Time, Words, Characters")
        return
    if not and_reach_note_info():
        record("text_note_info_labels", False,
               "setup_failed: could not open the Note Info modal",
               depth=3, jump_kind="value", expect="Created Time, Words, Characters")
        return
    nodes = ui()
    wanted = ["Created Time", "Words", "Characters"]
    missing = [w for w in wanted if not contains_text(nodes, w)]
    ok = not missing
    record("text_note_info_labels", ok,
           "" if ok else "behavior_wrong: Note Info modal missing label(s) %r — "
           "got text=%r" % (missing, all_text(nodes)),
           depth=3, jump_kind="value", expect="Created Time, Words, Characters")


@and_test(expects=("text_note_info_created_time_format",))
def test_note_info_created_time_format():
    open_empty_home()
    if not create_note("TimeNote", "hello world"):
        record("text_note_info_created_time_format", False,
               "setup_failed: could not create the note",
               depth=3, jump_kind="value", expect="Created Time = yyyy-MM-dd HH:mm:ss")
        return
    if not (and_enter_preview("TimeNote") and and_enter_more_menu()
            and and_reach_note_info()):
        record("text_note_info_created_time_format", False,
               "setup_failed: could not reach the Note Info modal",
               depth=3, jump_kind="value", expect="Created Time = yyyy-MM-dd HH:mm:ss")
        return
    nodes = ui()
    # The Created Time VALUE is a produced dynamic string; assert its SHAPE
    # (yyyy-MM-dd HH:mm:ss), not any specific timestamp.
    pat = re.compile(r"\b\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\b")
    matched = any(pat.search(n.get("text", "")) for n in nodes)
    record("text_note_info_created_time_format", matched,
           "" if matched else "behavior_wrong: Created Time value did not match the "
           "'yyyy-MM-dd HH:mm:ss' format — got text=%r" % all_text(nodes),
           depth=3, jump_kind="value", expect="Created Time = yyyy-MM-dd HH:mm:ss")


# ══════════════════════════════════════════════════════════════════════════════
# Markdown render — the '#' marker is stripped in Preview (dump-readable RULE side)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_preview_heading_stripped",))
def test_preview_heading_marker_stripped():
    open_empty_home()
    if not create_note("MdNote", "# Heading"):
        record("text_preview_heading_stripped", False,
               "setup_failed: could not create the markdown note",
               depth=1, jump_kind="value", expect="Heading (no '#')")
        return
    if not and_enter_preview("MdNote"):
        record("text_preview_heading_stripped", False,
               "setup_failed: could not open Preview",
               depth=1, jump_kind="value", expect="Heading (no '#')")
        return
    nodes = ui()
    has_heading = contains_text(nodes, "Heading")
    raw_hash = any("#" in (n.get("text", "")) for n in nodes)
    ok = has_heading and not raw_hash
    record("text_preview_heading_stripped", ok,
           "" if ok else "behavior_wrong: Preview did not render '# Heading' as "
           "'Heading' without the '#' (has_heading=%s raw_hash=%s text=%r)"
           % (has_heading, raw_hash, all_text(nodes)),
           depth=1, jump_kind="value", expect="Heading (no '#')")


# ══════════════════════════════════════════════════════════════════════════════
# VLM (budget = 2) — rendered visual properties markdown produces that the view
# tree cannot expose: the HEADING is enlarged, and a **bold** span is heavier.
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("text_preview_heading_render_vlm",))
def test_preview_heading_render_vlm():
    open_empty_home()
    if not create_note("HeadNote", "# Heading"):
        record("text_preview_heading_render_vlm", False,
               "setup_failed: could not create the markdown note",
               depth=1, jump_kind="value", tag="size")
        return
    if not and_enter_preview("HeadNote"):
        record("text_preview_heading_render_vlm", False,
               "setup_failed: could not open Preview",
               depth=1, jump_kind="value", tag="size")
        return
    # The text 'Heading' is in the tree but its rendered SIZE (heading vs body) is
    # not — that rendered property is the VLM's job.
    vlm_assert("text_preview_heading_render",
               "Is the word 'Heading' shown as a large heading, clearly bigger "
               "than normal body text, with NO '#' hash character visible before "
               "it?", RESULTS_DIR, depth=1, jump_kind="value", tag="size")


@and_test(expects=("text_preview_bold_render_vlm",))
def test_preview_bold_render_vlm():
    open_empty_home()
    if not create_note("BoldNote", "word **strongword** end"):
        record("text_preview_bold_render_vlm", False,
               "setup_failed: could not create the markdown note",
               depth=1, jump_kind="value", tag="shape")
        return
    if not and_enter_preview("BoldNote"):
        record("text_preview_bold_render_vlm", False,
               "setup_failed: could not open Preview",
               depth=1, jump_kind="value", tag="shape")
        return
    # The '**' markers are stripped in the tree (text reads 'word strongword end'),
    # but the tree cannot say 'strongword' is BOLD — a rendered font-weight property.
    vlm_assert("text_preview_bold_render",
               "In the note body, is the single word 'strongword' shown in bold "
               "(noticeably thicker/heavier) while the surrounding words 'word' and "
               "'end' are in normal weight, with no '*' asterisk characters "
               "visible?", RESULTS_DIR, depth=1, jump_kind="value", tag="shape")


TESTS = [
    test_empty_home_placeholder,
    test_search_no_match,
    test_empty_note_discard_placeholder,
    test_card_title_reflects_typed_title,
    test_card_body_reflects_typed_body,
    test_home_card_body_strips_markdown,
    test_desc_focus_shows_markdown_toolbar_descs,
    test_desc_focus_shows_undo_redo_descs,
    test_settings_section_labels,
    test_about_labels,
    test_more_menu_labels,
    test_note_info_labels,
    test_note_info_created_time_format,
    test_preview_heading_marker_stripped,
    test_preview_heading_render_vlm,
    test_preview_bold_render_vlm,
]


if __name__ == "__main__":
    if not device_online():
        print("Device not reachable — the tunnel may have dropped.")
    run_suite(TESTS, "text")