mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-01 20:55:16 +09:00
Button: the disabledReason description now sits beside the button instead of inside it, so the accessible name stays the label and the reason is only the description. Controls test asserts both (text and icon buttons). disabledReason added to: backup schedule Save, job progress Close, service Settings attach domain (x2), DNS Add record, New service Connect GitHub, shared variable groups (Create group, Add, Attach), .htaccess Convert, deploy console prev/next match, DataTable sort direction, Cron job form, Recipes Start, filter drawer Clear all, saved view Save, ChangeBar Undo/Redo/Save, log viewer Refresh/Download, server Packages Uninstall, grid Column menu (move left/right, clear filter), File manager Up, grid Tools scope, grid view Create, OAuth Connect, DB table Next page, DB console Export, DB import dump, Operations dock Continue, Notifications Reset, integrity Baseline/Check, AI composer Send, Terminal journal toolbar (remote), and the page primary action / phone header "+".
70 lines
4.8 KiB
JavaScript
70 lines
4.8 KiB
JavaScript
// Verify that shared-control adoption preserves custom SCSS and native form,
|
|
// disabled, keyboard, ref and asChild behavior. No application backend required.
|
|
import assert from 'node:assert/strict';
|
|
import { createServer } from 'vite';
|
|
import { chromium } from 'playwright';
|
|
|
|
const server = await createServer({ server: { host: '127.0.0.1', port: 0, strictPort: false, open: false } });
|
|
let browser;
|
|
try {
|
|
await server.listen();
|
|
browser = await chromium.launch({ headless: true });
|
|
const page = await browser.newPage();
|
|
const errors = [];
|
|
page.on('pageerror', (error) => errors.push(error.message));
|
|
await page.goto(`${server.resolvedUrls.local[0]}tests/browser/controls.html`);
|
|
await page.locator('#shared-submit').waitFor();
|
|
for (const theme of ['dark', 'light']) {
|
|
await page.evaluate((value) => { document.documentElement.dataset.theme = value; }, theme);
|
|
for (const suffix of ['submit', 'custom', 'disabled', 'card', 'header', 'content']) {
|
|
const pair = await page.evaluate((name) => {
|
|
const props = ['display', 'height', 'minWidth', 'padding', 'margin', 'border', 'borderRadius',
|
|
'backgroundColor', 'backgroundImage', 'color', 'fontFamily', 'fontSize', 'fontWeight',
|
|
'opacity', 'cursor', 'pointerEvents', 'boxShadow', 'gap'];
|
|
return ['native', 'shared'].map((prefix) => {
|
|
const element = document.getElementById(`${prefix}-${name}`);
|
|
const css = getComputedStyle(element);
|
|
return { tag: element.tagName, classes: [...new Set(element.classList)].sort(),
|
|
css: Object.fromEntries(props.map((property) => [property, css[property]])) };
|
|
});
|
|
}, suffix);
|
|
assert.deepEqual(pair[1], pair[0], `${theme}: ${suffix} changed its DOM/CSS contract`);
|
|
}
|
|
}
|
|
assert.equal(await page.evaluate(() => window.controlRef === document.getElementById('shared-custom')), true);
|
|
await page.locator('#shared-custom').click();
|
|
assert.deepEqual(await page.evaluate(() => window.controlEvents), { submits: 0, clicks: 1 });
|
|
await page.locator('#shared-custom').press('Enter');
|
|
assert.deepEqual(await page.evaluate(() => window.controlEvents), { submits: 0, clicks: 2 });
|
|
await page.locator('#shared-submit').click();
|
|
await page.locator('#native-submit').click();
|
|
assert.equal(await page.evaluate(() => window.controlEvents.submits), 2, 'implicit submit behavior changed');
|
|
await page.locator('#shared-disabled').evaluate((node) => node.click());
|
|
assert.equal(await page.evaluate(() => window.controlEvents.clicks), 2, 'disabled button fired');
|
|
// disabledReason: aria-disabled (not native), focusable, inert on click/Enter (no click, no
|
|
// implicit submit), reason in the accessible description and tooltip on focus and on tap.
|
|
const reason = page.locator('#shared-reason');
|
|
assert.equal(await reason.getAttribute('aria-disabled'), 'true');
|
|
assert.equal(await reason.getAttribute('disabled'), null);
|
|
await reason.focus();
|
|
assert.equal(await page.evaluate(() => document.activeElement.id), 'shared-reason', 'reasoned button must be focusable');
|
|
await page.locator('[role="tooltip"]', { hasText: 'Install it first' }).first().waitFor();
|
|
await page.keyboard.press('Escape');
|
|
await reason.click({ force: true });
|
|
await reason.press('Enter');
|
|
assert.deepEqual(await page.evaluate(() => window.controlEvents), { submits: 2, clicks: 2 }, 'reasoned button fired or submitted');
|
|
assert.equal(await reason.evaluate((node) => document.getElementById(node.getAttribute('aria-describedby').split(' ').pop()).textContent), 'Install it first');
|
|
// The reason is the accessible DESCRIPTION only: the name stays the label (or the icon button's title).
|
|
assert.equal(await page.getByRole('button', { name: 'Reasoned', exact: true }).count(), 1, 'reason must be the description, not part of the name');
|
|
assert.equal(await page.locator('#shared-reason-icon').evaluate((node) => document.getElementById(node.getAttribute('aria-describedby')).textContent), 'Go back: Nothing to go back to');
|
|
assert.equal(await page.getByRole('button', { name: 'Go back', exact: true }).count(), 1, 'icon button: name = label, description = reason');
|
|
await page.locator('[role="tooltip"]', { hasText: 'Install it first' }).first().waitFor();
|
|
assert.equal(await page.locator('#shared-link').evaluate((node) => node.tagName), 'A');
|
|
assert.equal(await page.locator('#shared-link').getAttribute('href'), '#destination');
|
|
assert.deepEqual(errors, []);
|
|
console.log('Controls: dark/light CSS equivalence, refs, form submission, keyboard, disabled and asChild contracts passed.');
|
|
} finally {
|
|
await browser?.close();
|
|
await server.close();
|
|
}
|