avocado/packages/entity/test/mobile.js

61 lines
1.7 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';
2021-01-05 11:25:37 -06:00
let latus;
let Entity;
let EntityList;
beforeEach(async () => {
latus = Latus.mock({
'@avocado/entity': require('../src'),
'@avocado/resource': require('@avocado/resource'),
'@avocado/traits': require('@avocado/traits'),
});
await Promise.all(latus.invokeFlat('@latus/core/starting'));
({fromResourceType: {Entity, EntityList}} = resource(latus));
});
describe('Mobile', () => {
let entity;
2021-01-03 00:57:51 -06:00
beforeEach(async () => {
2021-01-05 11:25:37 -06:00
entity = await Entity.load({
traits: {
Mobile: {},
Positioned: {},
},
2021-01-05 02:47:30 -06:00
});
2021-01-03 00:57:51 -06:00
});
2021-01-05 11:25:37 -06:00
it('exists', async () => {
expect(entity.is('Mobile')).to.be.true;
});
it('can request movement', async () => {
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]);
});
it('can force movement', async () => {
expect(entity.speed).to.equal(0);
entity.forceMovement([10, 0]);
expect(entity.position).to.deep.equal([10, 0]);
});
it('can move for a time', async () => {
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 00:57:51 -06:00
});
});