avocado/packages/entity/test/positioned.js
2022-03-27 02:33:55 -05:00

53 lines
1.5 KiB
JavaScript

/* eslint-disable global-require */
import {Flecks} from '@flecks/core';
import {expect} from 'chai';
let flecks;
let Entity;
beforeEach(async () => {
flecks = new Flecks({
flecks: {
'@avocado/entity': require('@avocado/entity'),
'@avocado/graphics': require('@avocado/graphics'),
'@avocado/resource': require('@avocado/resource'),
'@avocado/traits': require('@avocado/traits'),
'@flecks/core': require('@flecks/core'),
'@flecks/react': require('@flecks/react'),
'@flecks/socket': require('@flecks/socket'),
},
});
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
({Entity} = flecks.get('$avocado/resource.resources'));
});
afterEach(() => {
flecks.destroy();
});
describe('Positioned', () => {
let entity;
beforeEach(async () => {
entity = await Entity.load({
traits: {
Positioned: {},
},
});
});
it('exists', async () => {
expect(entity.is('Positioned')).to.be.true;
});
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
it('generates and accepts movement packets', async () => {
entity.setPosition([1, 1]);
const packets = entity.trait('Positioned').packetsFor();
expect(packets).to.have.lengthOf(1);
expect(packets[0][0]).to.equal('TraitUpdatePositionedPosition');
expect(packets[0][1]).to.deep.equal([1, 1]);
const entity2 = await Entity.load({
traits: {
Positioned: {},
},
});
expect(entity2.position).to.deep.equal([0, 0]);
});
}
});