Files
bitvid/tests/unit/embed_player_modal.test.mjs
google-labs-jules[bot] 981fac785a fix(embed): implement robust EmbedPlayerModal and guard resetTorrentStats
- Add `js/ui/components/EmbedPlayerModal.js` to implement the `VideoModal` interface for embed contexts (including `resetStats`).
- Update `js/ui/ModalManager.js` to detect embed mode and use `EmbedPlayerModal`.
- Clean up `js/embed.js` to remove local modal definition and add `postMessage` diagnostic logging.
- Update `js/app.js` `resetTorrentStats` log message and verify guard.
- Add unit tests for `EmbedPlayerModal` and `resetTorrentStats` logic.
- Add E2E reproduction script `tests/e2e/repro_issue.spec.ts`.
2026-01-24 22:09:03 +00:00

35 lines
1.4 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert';
import { EmbedPlayerModal } from '../../js/ui/components/EmbedPlayerModal.js';
// Polyfill EventTarget for Node < 16 if needed, but likely available
if (typeof EventTarget === 'undefined') {
global.EventTarget = class EventTarget {
constructor() { this.listeners = {}; }
addEventListener() {}
removeEventListener() {}
dispatchEvent() { return true; }
};
}
test('EmbedPlayerModal interface', async (t) => {
const modal = new EmbedPlayerModal();
await t.test('has expected methods', () => {
assert.strictEqual(typeof modal.load, 'function');
assert.strictEqual(typeof modal.getRoot, 'function');
assert.strictEqual(typeof modal.getVideoElement, 'function');
assert.strictEqual(typeof modal.setVideoElement, 'function');
assert.strictEqual(typeof modal.resetStats, 'function');
assert.strictEqual(typeof modal.updateStatus, 'function');
assert.strictEqual(typeof modal.setTorrentStatsVisibility, 'function');
assert.strictEqual(typeof modal.addEventListener, 'function');
assert.strictEqual(typeof modal.removeEventListener, 'function');
assert.strictEqual(typeof modal.dispatch, 'function');
});
await t.test('resetStats is no-op and does not throw', () => {
assert.doesNotThrow(() => modal.resetStats());
});
});