avocado/packages/entity/test/mobile.js
2021-01-22 17:58:45 -06:00

60 lines
1.7 KiB
JavaScript

import {Latus} from '@latus/core';
import {expect} from 'chai';
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'));
({Entity, EntityList} = latus.get('%resources'));
});
describe('Mobile', () => {
let entity;
beforeEach(async () => {
entity = await Entity.load({
traits: {
Mobile: {},
Positioned: {},
},
});
});
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;
});
});