+ it('should no longer call removed systems', () => {
+
+ const originalSystemLength = internals.context.engine.systems.length;
+ const originalRemoved = internals.context.engine.removeSystem(internals.context.lowPrioritySystem);
+ const intermediateSystemLength = internals.context.engine.systems.length;
+ const finalRemoved = internals.context.engine.removeSystem(internals.context.lowPrioritySystem);
+ const finalSystemLength = internals.context.engine.systems.length;
+ internals.context.engine.update(internals.delta);
+
+ // Check for return value
+ assert(originalRemoved);
+ assert(!finalRemoved);
+
+ // Confirm that only removed if found by checking length of systems
+ // array
+ assert(originalSystemLength > intermediateSystemLength);
+ assert.deepEqual(finalSystemLength, intermediateSystemLength);
+
+ // Ensure callback is sent
+ assert(!internals.context.regularSystem.removedCalled);
+ assert(!internals.context.highPrioritySystem.removedCalled);
+ assert(!!internals.context.lowPrioritySystem.removedCalled);
+
+ // Ensure update is no longer sent
+ assert(!!internals.context.regularSystem.updateCalled);
+ assert(!!internals.context.highPrioritySystem.updateCalled);
+ assert(!internals.context.lowPrioritySystem.updateCalled);
+ });
+
+ it('should only call nodes in selected node collections', () => {
+
+ internals.context.engine.update(internals.delta);
+
+ // Ensure component is called for each entity
+ assert(!!internals.context.firstEntity._components[0].called);
+ assert(!!internals.context.secondEntity._components[0].called);
+
+ // Ensure entity not in node collection not called
+ assert(!!internals.context.firstEntity.called);
+ assert(!!internals.context.secondEntity.called);
+ assert(!internals.context.emptyEntity.called);
+ });
+
+ it('should stop showing removed entities', () => {
+
+ internals.context.engine.removeEntity(internals.context.secondEntity);
+ internals.context.engine.update(internals.delta);
+
+ assert(!!internals.context.firstEntity._components[0].called);
+ assert(!internals.context.secondEntity._components[0].called);
+
+ assert(!!internals.context.firstEntity.called);
+ assert(!internals.context.secondEntity.called);
+ assert(!internals.context.emptyEntity.called);
+ });
+
+ it('should not add duplicate components to entities', () => {
+
+ const originalComponentsLength = internals.context.secondEntity._components.length;
+ const result = internals.context.secondEntity.addComponent(new internals.component());
+ const newComponentsLength = internals.context.secondEntity._components.length;
+
+ assert(!result);
+ assert.deepEqual(newComponentsLength, originalComponentsLength);
+ });
+
+ it('should allow access to components by class', () => {
+
+ const firstComponent = internals.context.firstEntity.getComponent(internals.component);
+ const emptyComponent = internals.context.emptyEntity.getComponent(internals.component);
+
+ assert(firstComponent instanceof internals.component);
+ assert.deepEqual(emptyComponent, undefined);
+ });
+
+ it('should not add duplicate entities', () => {
+
+ const originalEntitiesLength = internals.context.engine.entities.length;
+ const added = internals.context.engine.addEntity(internals.context.firstEntity);
+ const finalEntitiesLength = internals.context.engine.entities.length;
+
+ assert(!added);
+
+ assert.deepEqual(finalEntitiesLength, originalEntitiesLength);
+ });
+
+ it('should remove entities', () => {
+
+ const originalEntityLength = internals.context.engine.entities.length;
+ const originalRemoved = internals.context.engine.removeEntity(internals.context.firstEntity);
+ const intermediateEntityLength = internals.context.engine.entities.length;
+ const finalRemoved = internals.context.engine.removeEntity(internals.context.firstEntity);
+ const finalEntityLength = internals.context.engine.entities.length;
+ internals.context.engine.update(internals.delta);
+
+ // Check for return value
+ assert(originalRemoved);
+ assert(!finalRemoved);
+
+ // Confirm that only removed if found by checking length of systems
+ // array
+ assert(originalEntityLength > intermediateEntityLength);
+ assert.deepEqual(finalEntityLength, intermediateEntityLength);
+
+ // Ensure callback is sent
+ assert(!internals.context.firstEntity.called);
+ assert(!!internals.context.secondEntity.called);
+ });
+});