Files
bitvid/tests/unit/app_guard_logic.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

52 lines
1.7 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert';
/**
* Validates the logic used in Application.resetTorrentStats.
* Note: We test the function logic in isolation because importing the full Application class
* triggers side effects (network, webtorrent) that are difficult to mock in this unit test environment.
*/
function resetTorrentStats(context, logger) {
// Exact logic from js/app.js
if (context.videoModal) {
if (typeof context.videoModal.resetStats === "function") {
context.videoModal.resetStats();
} else {
logger.info(
"[Application] resetTorrentStats: videoModal.resetStats not available — skipping."
);
}
}
}
test('Application.resetTorrentStats logic', async (t) => {
const logger = {
info: () => {},
warn: () => {}
};
await t.test('does not throw when videoModal is null', () => {
const context = { videoModal: null };
assert.doesNotThrow(() => resetTorrentStats(context, logger));
});
await t.test('does not throw when videoModal is undefined', () => {
const context = { videoModal: undefined };
assert.doesNotThrow(() => resetTorrentStats(context, logger));
});
await t.test('does not throw when videoModal lacks resetStats', () => {
const context = { videoModal: { other: 1 } };
assert.doesNotThrow(() => resetTorrentStats(context, logger));
});
await t.test('calls resetStats when available', () => {
let called = false;
const context = {
videoModal: { resetStats: () => { called = true; } }
};
resetTorrentStats(context, logger);
assert.strictEqual(called, true);
});
});