Files
ytplayer/frontend/fullscreen-orientation.test.js
2026-10-06 04:12:25 +08:00

23 lines
1.2 KiB
JavaScript

const { test } = require('node:test');
const assert = require('node:assert/strict');
const { normalize, normalizeFit, rotation, coordinates } = require('./fullscreen-orientation');
test('fullscreen fit defaults safely to fill and accepts fit', () => {
assert.equal(normalizeFit(undefined), 'fill');
assert.equal(normalizeFit('fit'), 'fit');
assert.equal(normalizeFit('unexpected'), 'fill');
});
test('orientation defaults and only rotates mismatched viewports', () => {
assert.equal(normalize('invalid'), 'auto');
assert.equal(rotation('auto', 390, 844), 0);
assert.equal(rotation('landscape', 390, 844), 90);
assert.equal(rotation('landscape', 844, 390), 0);
assert.equal(rotation('portrait', 844, 390), -90);
});
test('rotated touch coordinates preserve local seek and swipe axes', () => {
const rect = { left: 10, top: 20, right: 400, bottom: 864, width: 390, height: 844 };
assert.deepEqual(coordinates(400, 20, rect, 90), { x: 0, y: 0, width: 844, height: 390 });
assert.deepEqual(coordinates(10, 864, rect, 90), { x: 844, y: 390, width: 844, height: 390 });
assert.deepEqual(coordinates(10, 864, rect, -90), { x: 0, y: 0, width: 844, height: 390 });
assert.deepEqual(coordinates(205, 442, rect), { x: 195, y: 422, width: 390, height: 844 });
});