forked from fa/breadcrumb-the-shire
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>
112 lines
5.2 KiB
PHP
112 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Tests\Architecture;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class FrontendRuntimeComponentContractTest extends TestCase
|
|
{
|
|
use FrontendRuntimeContractSupport;
|
|
use ProjectFileAssertionSupport;
|
|
|
|
public function testRuntimeMigratedComponentsDoNotAutoInitialize(): void
|
|
{
|
|
foreach ($this->runtimeMigratedComponentFiles() as $file) {
|
|
$content = $this->readProjectFile($file);
|
|
$this->assertStringNotContainsString('DOMContentLoaded', $content, $file);
|
|
$this->assertStringNotContainsString("if (document.readyState === 'loading')", $content, $file);
|
|
}
|
|
}
|
|
|
|
public function testMigratedComponentsExposeDestroyCleanupPaths(): void
|
|
{
|
|
$sidebar = $this->readProjectFile('web/js/components/app-toggle-sidebar.js');
|
|
$aside = $this->readProjectFile('web/js/components/app-toggle-aside-panels.js');
|
|
$search = $this->readProjectFile('web/js/components/app-global-search.js');
|
|
$bookmarkSave = $this->readProjectFile('modules/bookmarks/web/js/components/app-bookmark-save.js');
|
|
$bookmarkPanel = $this->readProjectFile('modules/bookmarks/web/js/components/app-bookmark-panel.js');
|
|
$multiSelect = $this->readProjectFile('web/js/components/app-multiselect-init.js');
|
|
|
|
$this->assertStringContainsString('destroy: () => {', $sidebar);
|
|
$this->assertStringContainsString("cleanupFns.push(() => document.removeEventListener('keydown', onShortcut));", $sidebar);
|
|
$this->assertStringContainsString("cleanupFns.push(() => mobileQuery.removeEventListener('change', onViewportChange));", $sidebar);
|
|
$this->assertStringContainsString("cleanupFns.push(() => document.removeEventListener('keydown', onEscDrawer));", $sidebar);
|
|
|
|
$this->assertStringContainsString('destroy: () => {', $aside);
|
|
$this->assertStringContainsString("cleanupFns.push(() => document.removeEventListener('keydown', onKeyDown));", $aside);
|
|
|
|
$this->assertStringContainsString('const destroy = () => {', $search);
|
|
$this->assertStringContainsString("document.removeEventListener('keydown', onDocumentKeydown);", $search);
|
|
|
|
$this->assertStringContainsString('const destroy = () => {', $bookmarkSave);
|
|
$this->assertStringContainsString('abortController.abort();', $bookmarkSave);
|
|
|
|
$this->assertStringContainsString('const destroy = () => {', $bookmarkPanel);
|
|
$this->assertStringContainsString('abortController.abort();', $bookmarkPanel);
|
|
$this->assertStringNotContainsString('export const init =', $bookmarkSave);
|
|
$this->assertStringNotContainsString('export const init =', $bookmarkPanel);
|
|
|
|
$this->assertStringContainsString('return {', $multiSelect);
|
|
$this->assertStringContainsString('destroy: () => {', $multiSelect);
|
|
|
|
$tokenSelect = $this->readProjectFile('web/js/components/app-token-select.js');
|
|
|
|
$this->assertStringContainsString('const destroy = () => {', $tokenSelect);
|
|
$this->assertStringContainsString('cleanupFns.push(', $tokenSelect);
|
|
}
|
|
|
|
public function testRuntimeStorageContractUsesSharedUiStorageHelper(): void
|
|
{
|
|
$files = [
|
|
'web/js/components/app-toggle-sidebar.js',
|
|
'web/js/components/app-toggle-aside-panels.js',
|
|
'web/js/components/app-toggle-details-aside.js',
|
|
'web/js/components/app-contrast-toggle.js',
|
|
'web/js/components/app-tabs.js',
|
|
'web/js/core/app-details-open-state.js',
|
|
'web/js/core/app-grid-factory.js',
|
|
];
|
|
|
|
foreach ($files as $file) {
|
|
$content = $this->readProjectFile($file);
|
|
$this->assertStringNotContainsString('window.localStorage', $content, $file);
|
|
$this->assertStringContainsString('createUiStorage', $content, $file);
|
|
}
|
|
}
|
|
|
|
public function testNoCustomWindowGlobalsRemainInWebJs(): void
|
|
{
|
|
$violations = $this->findPatternMatchesInFiles(
|
|
'web/js',
|
|
'/window\.(AppSidebar|AppAsidePanels|requestFsLightboxRefresh|__fsLightboxRefreshPending|APP_ASSET_BASE|APP_BASE)\b/',
|
|
['js']
|
|
);
|
|
|
|
$this->assertSame([], $violations, 'Custom window globals found in web/js: ' . implode(', ', $violations));
|
|
}
|
|
|
|
public function testHostBoundRuntimeComponentsAreRootStrictWithoutDocumentFallbackQuery(): void
|
|
{
|
|
$files = [
|
|
'web/js/components/app-global-search.js',
|
|
'modules/bookmarks/web/js/components/app-bookmark-panel.js',
|
|
'web/js/components/app-tabs.js',
|
|
];
|
|
|
|
foreach ($files as $file) {
|
|
$content = $this->readProjectFile($file);
|
|
$this->assertDoesNotMatchRegularExpression('/\|\|\s*document\.querySelector/', $content, $file);
|
|
}
|
|
}
|
|
|
|
public function testDomBindingUtilitiesExposeDestroyLifecycle(): void
|
|
{
|
|
$activeFilterChips = $this->readProjectFile('web/js/components/app-active-filter-chips.js');
|
|
$multiselectCascade = $this->readProjectFile('web/js/components/app-multiselect-cascade.js');
|
|
|
|
$this->assertStringContainsString('return { render, destroy };', $activeFilterChips);
|
|
$this->assertStringContainsString('return {', $multiselectCascade);
|
|
$this->assertStringContainsString('destroy: () => {', $multiselectCascade);
|
|
}
|
|
}
|