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.
89 lines
3.2 KiB
TypeScript
89 lines
3.2 KiB
TypeScript
// 提示气泡定位:优先在触发器上方,放不下翻到下方,水平居中并夹在视口内。
|
|
|
|
import { describe, expect, test } from 'bun:test';
|
|
import {
|
|
TOOLTIP_OFFSET,
|
|
TOOLTIP_VIEWPORT_MARGIN,
|
|
resolveTooltipPosition,
|
|
} from '@/components/ui/Tooltip/tooltipPosition';
|
|
|
|
const viewport = { width: 1024, height: 768 };
|
|
const rect = (left: number, top: number, width = 16, height = 16) => ({
|
|
left,
|
|
top,
|
|
width,
|
|
bottom: top + height,
|
|
});
|
|
const tooltip = { width: 200, height: 60 };
|
|
|
|
describe('resolveTooltipPosition', () => {
|
|
test('sits above the trigger, centred on it, when there is room', () => {
|
|
const trigger = rect(500, 400);
|
|
expect(resolveTooltipPosition(trigger, tooltip, viewport)).toEqual({
|
|
placement: 'top',
|
|
top: 400 - TOOLTIP_OFFSET - 60,
|
|
left: 508 - 100,
|
|
});
|
|
});
|
|
|
|
test('flips below when the tooltip does not fit above', () => {
|
|
const trigger = rect(500, 40);
|
|
expect(resolveTooltipPosition(trigger, tooltip, viewport)).toEqual({
|
|
placement: 'bottom',
|
|
top: 56 + TOOLTIP_OFFSET,
|
|
left: 408,
|
|
});
|
|
});
|
|
|
|
test('stays above at the exact fitting boundary', () => {
|
|
const top = TOOLTIP_VIEWPORT_MARGIN + TOOLTIP_OFFSET + tooltip.height;
|
|
const position = resolveTooltipPosition(rect(500, top), tooltip, viewport);
|
|
expect(position.placement).toBe('top');
|
|
expect(position.top).toBe(TOOLTIP_VIEWPORT_MARGIN);
|
|
});
|
|
|
|
test('takes the roomier side and clamps into the viewport when neither side fits', () => {
|
|
const short = { width: 1024, height: 120 };
|
|
const tall = { width: 200, height: 100 };
|
|
// 50px above, 50px below: neither fits; ties keep the preferred side, clamped to the margin.
|
|
const tied = resolveTooltipPosition(rect(500, 52), tall, short);
|
|
expect(tied.placement).toBe('top');
|
|
expect(tied.top).toBe(TOOLTIP_VIEWPORT_MARGIN);
|
|
// More room below: flips and is clamped so its bottom keeps the margin.
|
|
const lower = resolveTooltipPosition(rect(500, 30), tall, short);
|
|
expect(lower.placement).toBe('bottom');
|
|
expect(lower.top).toBe(120 - TOOLTIP_VIEWPORT_MARGIN - 100);
|
|
});
|
|
|
|
test('clamps to the left edge', () => {
|
|
const position = resolveTooltipPosition(rect(2, 400), tooltip, viewport);
|
|
expect(position.left).toBe(TOOLTIP_VIEWPORT_MARGIN);
|
|
expect(position.placement).toBe('top');
|
|
});
|
|
|
|
test('clamps to the right edge', () => {
|
|
const position = resolveTooltipPosition(rect(1010, 400), tooltip, viewport);
|
|
expect(position.left).toBe(1024 - TOOLTIP_VIEWPORT_MARGIN - 200);
|
|
});
|
|
|
|
test('centres on a trigger that is wider than the tooltip', () => {
|
|
const trigger = rect(100, 400, 600, 36);
|
|
const position = resolveTooltipPosition(trigger, tooltip, viewport);
|
|
expect(position.left).toBe(400 - 100);
|
|
expect(position.left).toBeGreaterThan(trigger.left);
|
|
expect(position.left + tooltip.width).toBeLessThan(trigger.left + trigger.width);
|
|
});
|
|
|
|
test('pins to the margin when the tooltip is wider than the viewport', () => {
|
|
const position = resolveTooltipPosition(
|
|
rect(100, 400),
|
|
{ width: 400, height: 40 },
|
|
{
|
|
width: 320,
|
|
height: 640,
|
|
}
|
|
);
|
|
expect(position.left).toBe(TOOLTIP_VIEWPORT_MARGIN);
|
|
});
|
|
});
|