Files
KVideo/verification/tests/regression/floating-button-position.test.ts
kuekhaoyang 3771b63332 feat: add self-contained strict verification chain
Keep every post-59948b5 change inside verification/. The verifier owns its npm working directory and sanitized Docker context, so no release metadata or root Docker configuration is modified.
2026-08-02 06:11:13 +08:00

65 lines
1.6 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
getDefaultFloatingButtonPosition,
getFloatingButtonRatios,
getPositionFromFloatingButtonRatios,
} from '../../../lib/utils/floating-button-position';
// GH-ISSUE: 220; GH-PR: 221
const buttonSize = 56;
const margin = 16;
test('default right-anchored buttons follow the right edge after a viewport resize', () => {
const initial = getDefaultFloatingButtonPosition(
{ width: 1280, height: 720 },
'right',
0.5,
buttonSize,
margin,
);
const resized = getDefaultFloatingButtonPosition(
{ width: 1920, height: 720 },
'right',
0.5,
buttonSize,
margin,
);
assert.equal(initial.x, 1208);
assert.equal(resized.x, 1848);
assert.equal(1280 - initial.x - buttonSize, margin);
assert.equal(1920 - resized.x - buttonSize, margin);
});
test('default left-anchored buttons remain attached to the left edge', () => {
const resized = getDefaultFloatingButtonPosition(
{ width: 1920, height: 900 },
'left',
0.5,
buttonSize,
margin,
);
assert.equal(resized.x, margin);
assert.equal(resized.y, 422);
});
test('custom positions preserve their relative draggable-area placement on resize', () => {
const initialViewport = { width: 1280, height: 720 };
const initialPosition = { x: 1208, y: 332 };
const ratios = getFloatingButtonRatios(initialPosition, initialViewport, buttonSize, margin);
const resized = getPositionFromFloatingButtonRatios(
ratios,
{ width: 1920, height: 900 },
buttonSize,
margin,
);
assert.equal(ratios.xRatio, 1);
assert.equal(resized.x, 1848);
assert.equal(resized.y, 422);
});