diff --git a/tests/render_harness.py b/tests/render_harness.py index 29c5f1ce3..c025a0a20 100644 --- a/tests/render_harness.py +++ b/tests/render_harness.py @@ -1198,6 +1198,18 @@ def key_line(page): return page.locator(".lf-keyline").inner_text() +def key_line_route(page, command): + """The keycaps one key-line binding draws, in the order they are pressed. + + A chord's rows keep their complete route while the reader advances through it, so + the text alone no longer says how far a chord has come; `data-lf-key-state` does. + Read the keys through this locator and assert on both. + """ + return page.locator( + f'.lf-keyline .lf-key[data-lf-commands~="{command}"] > .lf-key-sequence > kbd' + ) + + def open_page( browser, url, diff --git a/tests/render_support.py b/tests/render_support.py index be0c9c9bf..7e3028917 100644 --- a/tests/render_support.py +++ b/tests/render_support.py @@ -311,6 +311,7 @@ held_stale, hold_selection, key_line, + key_line_route, leaf_page, margins_laid_out, navigate, @@ -603,6 +604,7 @@ "hold_selection", "in_threads_scrollport", "key_line", + "key_line_route", "leaf_page", "live_leaf", "live_url", diff --git a/tests/test_render_margin.py b/tests/test_render_margin.py index 748522985..10da18441 100644 --- a/tests/test_render_margin.py +++ b/tests/test_render_margin.py @@ -13,6 +13,7 @@ SUGGESTION_PAGE, _publish, compare_with, + key_line_route, leaf_page, live_url, margins_laid_out, @@ -165,13 +166,14 @@ def activation_state(): expect(marker).not_to_be_focused() page.keyboard.press("g") - expect(page.locator(".lf-keyline")).to_contain_text( - re.compile(r"m\s*page-map items") - ) + # The row keeps the whole route from the first press to the last, so how far the + # chord has come is the list key's face rather than which keys the line is drawing. + map_route = key_line_route(page, "navigation.page-map-item") + expect(map_route).to_have_text(["g", "m", "1–9"]) + expect(map_route.nth(1)).to_have_attribute("data-lf-key-state", "neutral") page.keyboard.press("m") - expect(page.locator(".lf-keyline")).to_contain_text( - re.compile(r"1–9\s*page-map items") - ) + expect(map_route).to_have_text(["g", "m", "1–9"]) + expect(map_route.nth(1)).to_have_attribute("data-lf-key-state", "pressed") page.keyboard.press(str(address["number"])) preview = page.locator(".lf-margin-preview") @@ -275,13 +277,13 @@ def test_one_margin_item_owns_a_targets_controls_information_and_more_actions( }""" ) page.keyboard.press("g") - expect(page.locator(".lf-keyline")).to_contain_text( - re.compile(r"m\s*page-map items") - ) + map_route = key_line_route(page, "navigation.page-map-item") + map_steps = ["g", "m", f"1–{min(draft_address['count'], 9)}"] + expect(map_route).to_have_text(map_steps) + expect(map_route.nth(1)).to_have_attribute("data-lf-key-state", "neutral") page.keyboard.press("m") - expect(page.locator(".lf-keyline")).to_contain_text( - re.compile(rf"1–{min(draft_address['count'], 9)}\s*page-map items") - ) + expect(map_route).to_have_text(map_steps) + expect(map_route.nth(1)).to_have_attribute("data-lf-key-state", "pressed") assert draft_address["number"] <= 9 page.keyboard.press(str(draft_address["number"])) expect(draft_item.locator(".lf-draft-pencil")).to_be_focused()