@osobh/reactar
Version:
AR Library for React Native and Expo
45 lines (39 loc) • 1.57 kB
text/typescript
import { EnvironmentalDetection, Plane, Anchor } from '../src/sensors/EnvironmentalDetection';
describe('EnvironmentalDetection', () => {
let envDetection: EnvironmentalDetection;
beforeEach(() => {
envDetection = new EnvironmentalDetection();
});
it('should detect planes', async () => {
const planes: Plane[] = await envDetection.detectPlanes();
expect(Array.isArray(planes)).toBe(true);
expect(planes.length).toBeGreaterThan(0);
const plane = planes[0];
expect(plane).toHaveProperty('id');
expect(plane).toHaveProperty('center');
expect(plane).toHaveProperty('extent');
});
it('should perform hit testing and return a plane', async () => {
const hitPlane: Plane | null = await envDetection.hitTest(0.5, 0.5);
expect(hitPlane).not.toBeNull();
if (hitPlane) {
expect(hitPlane).toHaveProperty('id');
}
});
it('should return light estimation values', async () => {
const light = await envDetection.getLightEstimation();
expect(light).toHaveProperty('ambientIntensity');
expect(light).toHaveProperty('ambientColorTemperature');
});
it('should create an anchor with a given offset', () => {
const dummyPlane: Plane = {
id: 'plane-1',
center: { x: 0, y: 0, z: -1 },
extent: { width: 1, length: 1 },
};
const anchor: Anchor = envDetection.createAnchor(dummyPlane, { x: 0.5, y: 0, z: 0 });
expect(anchor).toHaveProperty('id');
expect(anchor.position.x).toBeCloseTo(dummyPlane.center.x + 0.5);
expect(anchor.planeId).toBe(dummyPlane.id);
});
});