avocado/packages/entity/test/mobile.js

67 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-01-03 00:57:51 -06:00
import {resource} from '@avocado/resource';
import {Latus} from '@latus/core';
import {expect} from 'chai';
const {name} = require('../package.json');
describe(name, () => {
let latus;
let Entity;
2021-01-03 16:37:03 -06:00
let EntityList;
2021-01-03 00:57:51 -06:00
beforeEach(async () => {
latus = Latus.mock([
['@avocado/entity', `${__dirname}/../src`],
'@avocado/resource',
'@avocado/traits',
]);
await Promise.all(latus.invokeFlat('@latus/core/starting'));
2021-01-03 16:37:03 -06:00
({fromResourceType: {Entity, EntityList}} = resource(latus));
2021-01-03 00:57:51 -06:00
});
describe('Traits', () => {
describe('Mobile', () => {
2021-01-03 16:37:03 -06:00
let entity;
beforeEach(async () => {
entity = await Entity.load({
2021-01-03 00:57:51 -06:00
traits: {
Mobile: {},
2021-01-03 18:02:05 -06:00
Positioned: {},
2021-01-03 00:57:51 -06:00
},
});
2021-01-03 16:37:03 -06:00
});
it('exists', async () => {
2021-01-03 18:02:05 -06:00
expect(entity.is('Mobile')).to.be.true;
2021-01-03 00:57:51 -06:00
});
2021-01-03 16:37:03 -06:00
it('can request movement', async () => {
2021-01-03 18:02:05 -06:00
entity.speed = 100;
entity.requestMovement([1, 0]);
entity.tick(1);
expect(entity.position).to.deep.equal([100, 0]);
entity.tick(1);
expect(entity.position).to.deep.equal([100, 0]);
entity.isMobile = false;
entity.requestMovement([1, 0]);
entity.tick(1);
expect(entity.position).to.deep.equal([100, 0]);
2021-01-03 16:37:03 -06:00
});
it('can force movement', async () => {
2021-01-03 18:02:05 -06:00
expect(entity.speed).to.equal(0);
entity.forceMovement([10, 0]);
expect(entity.position).to.deep.equal([10, 0]);
2021-01-03 16:37:03 -06:00
});
it('can move for a time', async () => {
2021-01-03 18:02:05 -06:00
entity.speed = 10;
const tickingPromise = entity.moveFor([1, 0], 1);
entity.addTickingPromise(tickingPromise);
expect(entity.position).to.deep.equal([0, 0]);
entity.tick(0.25);
expect(entity.position).to.deep.equal([2.5, 0]);
entity.tick(0.25);
expect(entity.position).to.deep.equal([5, 0]);
entity.tick(0.5);
expect(entity.position).to.deep.equal([10, 0]);
return tickingPromise;
2021-01-03 16:37:03 -06:00
});
2021-01-03 00:57:51 -06:00
});
});
});