mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-11-22 16:37:49 +08:00
- Updated `providerErrorRulesUi.test.ts` to ensure controls are disabled while saving or disconnected, and added tests for InfoTips related to regex conditions and rule-order hints. - Created `providerFormHints.test.ts` to validate the transformation of notes into InfoTips, ensuring accessibility and proper descriptions for various form elements. - Enhanced `providerModelOptions.test.ts` to confirm that field notes are represented as InfoTips and that existing thinking JSON adds preservation notes. - Added tests in `quotaBodyRendering.test.ts` for Antigravity and Plugin quota groups to ensure descriptions are displayed as InfoTips. - Implemented `quotaTimelineRendering.test.ts` to verify InfoTip functionality in the QuotaTimeline component. - Updated `routingPage.test.ts` to check that policy explanations are presented as InfoTips and that the preview caveat is correctly positioned. - Introduced `tooltipMarkup.test.ts` to validate the structure and behavior of InfoTips and Tooltips, ensuring proper accessibility attributes. - Added `tooltipPosition.test.ts` to test the positioning logic of tooltips within the viewport. - Fixed Turkish locale test to ensure correct hint extraction from the configuration.
118 lines
4.6 KiB
TypeScript
118 lines
4.6 KiB
TypeScript
// Plugin config sheet: plugin-declared field descriptions are explained the same way as the
|
|
// built-in config page, through an InfoTip after the field name, and every control stays
|
|
// described for assistive tech. Static markup only (closed tooltips); hover, focus and tap
|
|
// behaviour need a browser.
|
|
|
|
import { afterAll, describe, expect, test } from 'bun:test';
|
|
import { createElement } from 'react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import i18n from '../src/i18n/index';
|
|
import { PluginConfigSheet } from '../src/features/plugins/components/PluginConfigSheet';
|
|
import { buildPluginConfigDraft } from '../src/features/plugins/pluginConfigDraft';
|
|
import type { PluginConfigField, PluginListEntry } from '../src/types';
|
|
|
|
const FIELDS: PluginConfigField[] = [
|
|
{ name: 'verbose', type: 'boolean', enumValues: [], description: 'Log every request body' },
|
|
{ name: 'mode', type: 'enum', enumValues: ['fast', 'safe'], description: 'Which pipeline runs' },
|
|
{ name: 'headers', type: 'object', enumValues: [], description: 'Extra upstream headers' },
|
|
{ name: 'endpoint', type: 'string', enumValues: [], description: 'Upstream base URL' },
|
|
{ name: 'quiet', type: 'boolean', enumValues: [], description: '' },
|
|
];
|
|
|
|
const PLUGIN: PluginListEntry = {
|
|
id: 'example.plugin',
|
|
path: '/plugins/example.so',
|
|
configured: true,
|
|
registered: true,
|
|
enabled: true,
|
|
effectiveEnabled: true,
|
|
supportsOAuth: false,
|
|
supportsQuota: false,
|
|
logo: '',
|
|
configFields: FIELDS,
|
|
menus: [],
|
|
metadata: null,
|
|
};
|
|
|
|
const initialLanguage = i18n.language;
|
|
afterAll(async () => {
|
|
await i18n.changeLanguage(initialLanguage);
|
|
});
|
|
|
|
const renderSheet = () =>
|
|
renderToStaticMarkup(
|
|
createElement(PluginConfigSheet, {
|
|
plugin: PLUGIN,
|
|
draft: buildPluginConfigDraft(PLUGIN, {}),
|
|
saving: false,
|
|
onClose: () => {},
|
|
onSave: () => {},
|
|
onDraftChange: () => {},
|
|
})
|
|
);
|
|
|
|
const infoTips = (html: string) => html.match(/<button\b[^>]*data-info-tip=""[^>]*>/g) ?? [];
|
|
const attr = (tag: string, name: string) => tag.match(new RegExp(`\\b${name}="([^"]*)"`))?.[1];
|
|
/** Text of the element carrying `id`, whatever its tag. */
|
|
const textOf = (html: string, id: string) =>
|
|
html.match(new RegExp(`id="${id}"[^>]*>([^<]*)<`))?.[1] ?? null;
|
|
|
|
describe('plugin config sheet field descriptions', () => {
|
|
test('every described field gets one InfoTip named after the field', async () => {
|
|
await i18n.changeLanguage('en');
|
|
const html = renderSheet();
|
|
const names = infoTips(html).map((tip) => attr(tip, 'aria-label'));
|
|
expect(names).toEqual([
|
|
'More information about Enabled',
|
|
'More information about verbose',
|
|
'More information about mode',
|
|
'More information about headers',
|
|
'More information about endpoint',
|
|
]);
|
|
});
|
|
|
|
test('descriptions are not printed as visible lines', async () => {
|
|
await i18n.changeLanguage('en');
|
|
const html = renderSheet();
|
|
for (const text of [
|
|
'Log every request body',
|
|
'Which pipeline runs',
|
|
'Extra upstream headers',
|
|
i18n.t('plugin_management.enabled_hint'),
|
|
]) {
|
|
// Only the hidden copy the control and the InfoTip point at.
|
|
const occurrences = html.split(text).length - 1;
|
|
expect(occurrences).toBe(1);
|
|
expect(html).toMatch(new RegExp(`<span id="[^"]+-desc" hidden="">${text}</span>`));
|
|
}
|
|
// The string field goes through the shared Input: its hint is visually hidden.
|
|
expect(html).toContain('class="hint visually-hidden-focusable">Upstream base URL</div>');
|
|
});
|
|
|
|
test('each control is described by its field description', async () => {
|
|
await i18n.changeLanguage('en');
|
|
const html = renderSheet();
|
|
const control = (id: string) =>
|
|
html.match(new RegExp(`<(?:input|textarea|button)\\b[^>]*id="${id}"[^>]*>`))?.[0] ?? '';
|
|
|
|
const cases: Array<[string, string]> = [
|
|
['plugin-config-enabled', i18n.t('plugin_management.enabled_hint')],
|
|
['plugin-field-verbose', 'Log every request body'],
|
|
['plugin-field-mode', 'Which pipeline runs'],
|
|
['plugin-field-headers', 'Extra upstream headers'],
|
|
['plugin-field-endpoint', 'Upstream base URL'],
|
|
];
|
|
for (const [id, text] of cases) {
|
|
const describedBy = attr(control(id), 'aria-describedby') ?? '';
|
|
expect(describedBy.split(' ').some((ref) => textOf(html, ref) === text)).toBe(true);
|
|
}
|
|
// No description declared: no InfoTip and no dangling reference.
|
|
expect(attr(control('plugin-field-quiet'), 'aria-describedby')).toBeUndefined();
|
|
});
|
|
|
|
test('the plugin id stays visible as the sheet description', async () => {
|
|
await i18n.changeLanguage('en');
|
|
expect(renderSheet()).toContain('>example.plugin</span>');
|
|
});
|
|
});
|