import test from 'node:test'; import assert from 'node:assert/strict'; import { MediaTextureManager } from '../vr180player/rendering/texture-manager.js'; function createTexture(name) { return { disposed: false, name, needsUpdate: false, dispose() { this.disposed = true; } }; } function createVideo({ paused = false, ended = false } = {}) { return { ended, paused }; } test('MediaTextureManager replaces the previous texture when creating a new one', () => { const created = []; const manager = new MediaTextureManager(createVideo(), () => { const texture = createTexture(`texture-${created.length}`); created.push(texture); return texture; }, () => true); const first = manager.create(); const second = manager.create(); assert.equal(first.disposed, true); assert.equal(second.disposed, false); assert.equal(manager.current, second); assert.equal(created.length, 2); }); test('MediaTextureManager assigns and clears material maps', () => { const material = { map: null, needsUpdate: false }; const manager = new MediaTextureManager(createVideo(), () => createTexture('assigned'), () => true); const texture = manager.assignToMaterial(material); assert.equal(material.map, texture); assert.equal(material.needsUpdate, true); assert.equal(manager.current, texture); material.needsUpdate = false; manager.clearMaterial(material); assert.equal(texture.disposed, true); assert.equal(material.map, null); assert.equal(material.needsUpdate, true); assert.equal(manager.current, null); }); test('MediaTextureManager only marks textures dirty when the update predicate allows it', () => { const video = createVideo(); const manager = new MediaTextureManager( video, () => createTexture('playing'), () => !video.paused && !video.ended ); const texture = manager.create(); manager.updateIfNeeded(); assert.equal(texture.needsUpdate, true); texture.needsUpdate = false; video.paused = true; manager.updateIfNeeded(); assert.equal(texture.needsUpdate, false); video.paused = false; video.ended = true; manager.updateIfNeeded(); assert.equal(texture.needsUpdate, false); });