Skip to content

test(e2e): add image rendering and TOC sidebar smoke tests - #4441

Closed
rkristelijn wants to merge 1 commit into
marktext:developfrom
rkristelijn:test/image-toc-e2e
Closed

rkristelijn wants to merge 1 commit into
marktext:developfrom
rkristelijn:test/image-toc-e2e

Conversation

@rkristelijn

Copy link
Copy Markdown
Contributor

Summary

Adds two e2e smoke tests that verify core rendering still works after engine changes:

  1. Image rendering — opens link-image.md, asserts <img> is visible in the editor
  2. TOC sidebar — opens headings.md, opens TOC sidebar, asserts heading entries appear

Why

The @muyajs/core migration (efcaf0c2) broke image loading and TOC generation. These tests would have caught the regression.

Status

These tests are expected to fail on current develop until the image/TOC regression is fixed. They serve as a regression gate for future engine changes.

Files

File Purpose
test/e2e/image-toc-render.spec.ts Two test suites (image + TOC)
test/e2e/data/headings.md Fixture with 5 headings at different levels

These tests verify that:
- Images render as visible <img> elements in the editor
- TOC sidebar populates with heading entries from the document

Currently failing due to the @muyajs/core migration (efcaf0c)
breaking image loading and TOC generation.
Jocs pushed a commit that referenced this pull request Jun 18, 2026
…4448)

* fix: populate the table of contents on open and fix link navigation

The @muyajs/core migration broke table-of-contents generation (see #4441):
the sidebar TOC stayed empty until the first edit, and clicking a TOC entry
did not scroll to the heading (the click-to-navigate behaviour requested in

- Seed the TOC from the engine on file load and on tab switch. The engine
  emits no json-change in those paths, so listToc/toc remained empty until a
  document change occurred.
- Resolve TOC link clicks by heading order. @muyajs/core slugs are stable
  per-block ids that are not stamped onto the heading DOM, so a `#slug`
  selector never matched; walk the headings in document order and map the
  slug to its index instead.

Refs #2992
Refs #4441

* fix(toc): scope heading navigation to top-level headings

Address review on #4448: scrollToHeader resolved a slug to its index in
listToc, then indexed querySelectorAll('h1..h6'). getTOC only walks
top-level scrollPage children (no recursion), so headings nested in
blockquotes/list items or inside raw-HTML blocks were counted by the DOM
but not by getTOC, shifting every later index and scrolling to the wrong
heading.

Scope the DOM query to direct-child headings (:scope > h1..h6) so the DOM
set matches getTOC's set by construction. Extract the resolution into a
pure resolveTocHeadingElement (util/tocNavigation.ts) so it is unit
testable.

Also from the review:
- extract a shared scrollElementIntoView(el) helper, de-duping the
  getBoundingClientRect + animatedScrollTo math between scrollToHeader
  and scrollToElement
- reword the UPDATE_TOC JSDoc: it is an unconditional re-seed on
  load/switch, drop the inaccurate deep-equal 'subset' rationale
- add toc-navigation.spec.ts covering UPDATE_TOC (seed + unconditional
  re-seed) and the slug->index resolution, pinning the nested / raw-HTML
  heading edge case (no longer relying on the unmerged #4441 e2e)

Refs #4448

* fix(toc): anchor heading query on .mu-container, not the scroll root

Runtime verification (opening a doc and clicking a TOC entry) surfaced
that the previous ':scope > hN' selector matched zero headings: the
scroll container returned by getScrollContainer() is muya's root
(.mu-editor), which WRAPS the scrollPage root (.mu-container) whose
direct children are the top-level blocks. The headings are one level
deeper than ':scope >' looked, so the click resolved to nothing and the
editor never scrolled.

Anchor the selector on '.mu-container > hN' so it matches the top-level
headings wherever .mu-container sits under the scroll container, while
still excluding nested (blockquote/list) and raw-HTML headings. Update
the unit fixture to mirror the real .mu-editor > .mu-container > heading
nesting so a regression to a scroller-scoped selector is caught.

Verified in-app: TOC seeds with the 3 top-level headings on open, and
clicking 'Top Two' scrolls it to the target offset (y=320) past the
interleaved blockquote/raw-HTML headings.

Refs #4448
@Jocs Jocs closed this Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants