1
0
Files
VR-Web-Player/tests/texture-manager.test.mjs
Aiden 481ca9fc47
All checks were successful
Test / test (push) Successful in 9m26s
more refactor
2026-06-10 12:27:12 +10:00

74 lines
2.0 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { VideoTextureManager } 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('VideoTextureManager replaces the previous texture when creating a new one', () => {
const created = [];
const manager = new VideoTextureManager(createVideo(), () => {
const texture = createTexture(`texture-${created.length}`);
created.push(texture);
return texture;
});
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('VideoTextureManager assigns and clears material maps', () => {
const material = { map: null, needsUpdate: false };
const manager = new VideoTextureManager(createVideo(), () => createTexture('assigned'));
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('VideoTextureManager only marks textures dirty while playback is active', () => {
const video = createVideo();
const manager = new VideoTextureManager(video, () => createTexture('playing'));
const texture = manager.create();
manager.updateIfPlaying();
assert.equal(texture.needsUpdate, true);
texture.needsUpdate = false;
video.paused = true;
manager.updateIfPlaying();
assert.equal(texture.needsUpdate, false);
video.paused = false;
video.ended = true;
manager.updateIfPlaying();
assert.equal(texture.needsUpdate, false);
});