Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions tests/test_render_margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
SUGGESTION_PAGE,
_publish,
compare_with,
key_line,
leaf_page,
live_url,
margins_laid_out,
Expand Down Expand Up @@ -93,6 +94,39 @@ def resized_shell(page, inline_size, height):
]


# The key line's page-map-item route, and how far the chord has come through it. Every
# destination carries its complete route from the moment `g` arms the chord, so the row's
# text reads the same before and after `m` aims the list; what advances is each keycap's
# state. `address.js` names the span the capped list actually holds, so it is derived here
# the same way rather than written out.
PAGE_MAP_ITEM_HINT = '.lf-keyline .lf-key[data-lf-commands~="navigation.page-map-item"]'


def address_span(count):
capped = min(count, 9)
return f"1–{capped}" if capped > 1 else "1"


def expect_page_map_address(page, count, pressed):
# The steps and their states are read once, on the repaint's own frame, because a
# retried read of a state that moves goes green on whichever tick lands inside its
# budget. Only the count and the row's word, neither of which the chord advances, are
# left to `expect`.
key_line(page)
hint = page.locator(PAGE_MAP_ITEM_HINT)
expect(hint).to_have_count(1)
expect(hint).to_contain_text("page-map items")
keys = hint.locator(".lf-key-sequence > kbd")
assert keys.evaluate_all("keys => keys.map(key => key.textContent)") == [
"g",
"m",
address_span(count),
]
assert keys.evaluate_all("keys => keys.map(key => key.dataset.lfKeyState)") == [
"pressed"
] * pressed + ["neutral"] * (3 - pressed)
Comment thread
leaf-agent marked this conversation as resolved.


def test_g_addresses_the_page_map_prefix_in_its_announced_order(browser, serve):
"""The first nine Page-map locations keep their announced position as address."""
page, errors = open_page(browser, serve(PAGE_MAP_PAGE, events=PAGE_MAP_EVENTS))
Expand Down Expand Up @@ -165,13 +199,9 @@ 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")
)
expect_page_map_address(page, address["count"], pressed=1)
page.keyboard.press("m")
expect(page.locator(".lf-keyline")).to_contain_text(
re.compile(r"1–9\s*page-map items")
)
expect_page_map_address(page, address["count"], pressed=2)
page.keyboard.press(str(address["number"]))

preview = page.locator(".lf-margin-preview")
Expand Down Expand Up @@ -275,13 +305,9 @@ 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")
)
expect_page_map_address(page, draft_address["count"], pressed=1)
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_page_map_address(page, draft_address["count"], pressed=2)
assert draft_address["number"] <= 9
page.keyboard.press(str(draft_address["number"]))
expect(draft_item.locator(".lf-draft-pencil")).to_be_focused()
Expand Down
Loading