Skip to content

Add View Type swap test and gate RedHerb card edit links#935

Draft
malberts wants to merge 2 commits into
masterfrom
test/view-swap-and-card-edit-gating
Draft

Add View Type swap test and gate RedHerb card edit links#935
malberts wants to merge 2 commits into
masterfrom
test/view-swap-and-card-edit-gating

Conversation

@malberts

@malberts malberts commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Two follow-ups from the review of #921 (View Type registration).

Regression test for the View Type swap

#921 made ViewTypeRegistry reactive so a View Type registered after NeoWikiApp has already resolved its views re-triggers resolution, swapping the fallback infobox for the registered component. This is the warm-cache path where an extension's frontend module loads after the app mounts. That behaviour had no automated coverage (NeoWikiApp is never mounted in the suite); it was only verified in the browser.

This adds a NeoWikiApp test that drives the production resolution path: a {{#view: | layout=}} placeholder whose Layout selects a View Type that is not yet registered renders the fallback infobox, the type is registered afterwards, and the test asserts the rendered component swaps from the infobox to the registered one. It fails if the registry is made non-reactive again (confirmed by temporarily reverting the reactive() call). It resolves through the Layout (the path the parser emits via data-mw-neowiki-layout-name), not the unused data-mw-neowiki-view-type attribute.

Gate the RedHerb card's edit links

The redherb-card example gated its Edit subject button on canEditSubject, but the Edit schema and Edit layout links rendered for everyone, so a viewer without edit rights was shown edit affordances they cannot use (the links target action=edit, which without edit rights only yields the read-only view-source page). The card now resolves the Schema and Layout edit rights through the useSchemaPermissions / useLayoutPermissions composables and hides each link when the viewer cannot edit that page, consistent with how the subject editor is gated. It checks the real Schema and Layout permissions rather than reusing canEditSubject, since those are distinct rights.

This UX change has no unit test (the RedHerb example extension has no JS test harness in the repo). It is verified in the browser (automated, Playwright): with the example extension loaded, an editor sees all three edit affordances, an anonymous viewer sees none, the card still renders, and the console is clean.

malberts and others added 2 commits June 26, 2026 21:34
The reactive ViewTypeRegistry lets a View Type registered after
NeoWikiApp has resolved its views re-trigger resolution, swapping the
fallback infobox for the registered component (the warm-cache path
where an extension's frontend module loads late). That behaviour was
only verified in the browser.

Drive the production resolution path: a {{#view: | layout=}} placeholder
whose Layout selects a not-yet-registered View Type renders the fallback
infobox; register the type afterwards and assert the rendered component
swaps from the infobox to the registered one. The test fails if the
registry is made non-reactive again.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The redherb-card example showed its Edit subject button only to users
who can edit the subject, but the Edit schema and Edit layout links
rendered for everyone, so anonymous viewers were shown edit affordances
they cannot use (the links target action=edit, which without edit rights
only yields the read-only view-source page).

Resolve the Schema and Layout edit rights through the useSchemaPermissions
/ useLayoutPermissions composables and hide each link when the viewer
cannot edit that page, consistent with how the subject editor is gated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@malberts
malberts force-pushed the test/view-swap-and-card-edit-gating branch from ee2a239 to 19895a1 Compare June 26, 2026 19:34
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.

1 participant