You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/DrawerMotionAssetsTest.php

67 lines
3.2 KiB
PHTML

<?php
$root = dirname(__DIR__);
$read = static function (string $path): string {
$contents = file_get_contents($path);
if (!is_string($contents)) {
throw new RuntimeException('Unable to read ' . $path);
}
return $contents;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$motion = $read($root . '/public/cloud/drawer-motion.js');
$assert(str_contains($motion, 'window.VenixDrawerMotion = Object.freeze')
&& str_contains($motion, 'requestAnimationFrame')
&& str_contains($motion, "event.propertyName === 'transform'")
&& str_contains($motion, "prefers-reduced-motion: reduce"),
'The shared drawer motion controller must coordinate entry, exit and reduced motion.');
foreach (['account-drawer.js', 'announcements.js', 'admin.js', 'admin-instances.js', 'admin-operations.js', 'admin-billing.js', 'admin-resources.js'] as $script) {
$source = $read($root . '/public/cloud/' . $script);
if ($script === 'admin-instances.js') {
$source .= "\n" . $read(
$root . '/public/cloud/admin-instance-detail.js'
);
$source .= "\n" . $read(
$root . '/public/cloud/admin-instance-backups.js'
);
}
$assert(str_contains($source, 'window.VenixDrawerMotion')
&& str_contains($source, 'openDrawerWithMotion')
&& str_contains($source, 'closeDrawerWithMotion'),
'Drawer runtime does not use the shared motion controller: ' . $script);
}
$accountDrawer = $read($root . '/public/cloud/account-drawer.js');
$assert(str_contains($accountDrawer, "event.key === 'Escape'")
&& str_contains($accountDrawer, "typeof drawer.showModal !== 'function'"),
'The account drawer must retain Escape support when native modal dialogs are unavailable.');
$adminBilling = $read($root . '/public/cloud/admin-billing.js');
$assert(str_contains($adminBilling, 'detailClosePromise')
&& str_contains($adminBilling, 'if (closing) await closing;'),
'Billing route restoration must wait for an in-flight drawer exit.');
$userShell = $read($root . '/resources/views/venix/user/panel_topbar.tpl');
$adminShell = $read($root . '/resources/views/venix/admin/static_header.tpl');
$assert(str_contains($userShell, '/cloud/drawer-motion.js?v={$venix_asset_version')
&& str_contains($adminShell, '/cloud/drawer-motion.js?v={$venix_asset_version}'),
'The shared drawer motion controller must use the common cache key on user and admin pages.');
$userCss = $read($root . '/public/cloud/client.css');
$adminCss = $read($root . '/public/theme/venix/css/admin-home.css');
$assert(str_contains($userCss, '.panel-announcements-drawer.is-drawer-visible')
&& str_contains($userCss, '.panel-account-drawer.is-drawer-visible')
&& str_contains($userCss, '@media (prefers-reduced-motion: reduce)'),
'User drawers must slide from the side and respect reduced motion.');
$assert(str_contains($adminCss, '[data-admin-instance-drawer].is-drawer-visible')
&& str_contains($adminCss, '@media (prefers-reduced-motion: reduce)'),
'Administrator drawers must slide from the side and respect reduced motion.');
echo "Shared user and administrator drawer motion checks passed.\n";