1
0
Files
breadcrumb-the-shire/tests/Architecture/FrontendRuntimeEntrypointContractTest.php
fs b2982bdac7 feat(ui): token-select primitive for large multi-selects
Adds tokenSelectForm() in core/Support/helpers/ui.php: an inline
typeahead combobox + flat alphabetical removable list, designed for
selections that outgrow the chip-header of the vendor MultiSelect
(roles, permissions, and similar admin pickers).

Contract:
- Hidden <select multiple name="<name>[]"> is the form submission source —
  consumers read via $request->body() verbatim, no parsing
- Items are ['id' => int, <labelKey> => string, 'key' => string?]
  where labelKeys default to ['description', 'label', 'name']; 'key' is
  an invisible fuzzy-match hint
- $labelOverrides lets callers swap emptyState / removeTooltip /
  noMatches / clearAll / countSuffix / errorMessage with domain copy
- $disabled renders pure-presentation list (no combobox, no remove)

Runtime:
- initTokenSelect in web/js/components/app-token-select.js is registered
  as 'token-select' in app-init.js; destroy()/cleanupFns contract
- Syncs the hidden <select> on every mutation and dispatches 'change'
  so dependent UI can react

Wired up: pages/admin/permissions/_form.phtml (assigned roles),
pages/admin/roles/_form.phtml (permissions + assignable roles).
Helper contract lives in tests/Support/Helpers/TokenSelectFormHelperTest.php;
runtime contract + entrypoint registration + host usage are enforced by
FrontendRuntime*ContractTest.php.

Coexists with multiSelectForm() — pick tokenSelectForm() when the
selected set can grow beyond ~10 items or typeahead is expected.
Docs in CLAUDE.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 23:52:32 +02:00

58 lines
3.5 KiB
PHP

<?php
namespace MintyPHP\Tests\Architecture;
use PHPUnit\Framework\TestCase;
class FrontendRuntimeEntrypointContractTest extends TestCase
{
use ProjectFileAssertionSupport;
public function testEntrypointsUseRuntimeRegistrationWithoutSideeffectComponentImports(): void
{
$defaultEntry = $this->readProjectFile('web/js/app-init.js');
$loginEntry = $this->readProjectFile('web/js/app-login-init.js');
$this->assertStringContainsString("import { createComponentRuntime } from './core/app-component-runtime.js';", $defaultEntry);
$this->assertStringContainsString("import { createComponentRuntime } from './core/app-component-runtime.js';", $loginEntry);
$this->assertDoesNotMatchRegularExpression('/import\s+[\'"]\.\/components\//', $defaultEntry);
$this->assertDoesNotMatchRegularExpression('/import\s+[\'"]\.\/components\//', $loginEntry);
$this->assertStringContainsString("runtime.register('sidebar-toggle', initSidebarToggle", $defaultEntry);
$this->assertStringContainsString("runtime.register('global-search', initGlobalSearch", $defaultEntry);
$this->assertStringContainsString("runtime.register('token-select', initTokenSelect", $defaultEntry);
$this->assertStringContainsString("await mountModuleComponentsByPhase('late');", $defaultEntry);
$this->assertStringContainsString('moduleRuntimeComponents', $defaultEntry);
$this->assertStringContainsString("selector: '[data-app-component=\"tabs\"]'", $defaultEntry);
$this->assertStringContainsString('runtime.mountAll();', $defaultEntry);
$this->assertStringContainsString("runtime.register('password-hints', initPasswordHints", $loginEntry);
$this->assertStringContainsString("runtime.register('password-toggle', initPasswordToggles", $loginEntry);
$this->assertStringContainsString("runtime.register('login-submit-lock', initLoginSubmitLock", $loginEntry);
$this->assertStringContainsString('runtime.mountAll();', $loginEntry);
}
public function testBookmarkLegacyEntrypointFileIsRemoved(): void
{
$this->assertFileDoesNotExist($this->projectRootPath() . '/web/js/components/app-bookmark-init.js');
}
public function testPageEditorUsesPageModuleEntrypointWithPageConfig(): void
{
$pageEditor = $this->readProjectFile('web/js/components/app-page-editor.js');
$pageEditorEntry = $this->readProjectFile('web/js/pages/app-page-editor-entry.js');
$adminPage = $this->readProjectFile('pages/page/index(default).phtml');
$publicPage = $this->readProjectFile('pages/public-page/index(page).phtml');
$this->assertStringContainsString('export function initPageEditor(root = document, config = {})', $pageEditor);
$this->assertStringNotContainsString('const form = document.querySelector', $pageEditor);
$this->assertStringContainsString("readPageConfig('page-editor')", $pageEditorEntry);
$this->assertStringContainsString("assetVersion('js/pages/app-page-editor-entry.js')", $adminPage);
$this->assertStringContainsString("assetVersion('js/pages/app-page-editor-entry.js')", $publicPage);
$this->assertStringNotContainsString("assetVersion('js/components/app-page-editor.js')", $adminPage);
$this->assertStringNotContainsString("assetVersion('js/components/app-page-editor.js')", $publicPage);
$this->assertStringContainsString('id="page-config-page-editor"', $adminPage);
$this->assertStringContainsString('id="page-config-page-editor"', $publicPage);
}
}