Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116import { beforeEach, vi } from "vitest";import { describe, expect, it } from "vitest";
// oxlint-disable typescript/unbound-methodimport type Entity from "../entity";import System from "../system";
function getFakeEntity() { return { id: Math.random(), addSystem: vi.fn(), removeSystem: vi.fn(), } as unknown as Entity;}
describe("System", () => { it("should initialize", () => { const system = new System(); expect(system).toBeTruthy(); });
describe("addEntity()", () => { let entity: Entity; let system: System;
beforeEach(() => { entity = getFakeEntity(); system = new System(); });
it("should add an entity to the system", () => { system.addEntity(entity);
expect(system.entities.size).toEqual(1); });
it("should add the system to entity systems", () => { system.addEntity(entity);
expect(entity.addSystem).toHaveBeenCalledWith(system); });
it("should call enter() on added entity", () => { system.enter = vi.fn();
system.addEntity(entity);
expect(system.enter).toHaveBeenCalledWith(entity); }); });
describe("removeEntity()", () => { let entity: Entity; let system: System; beforeEach(() => { entity = getFakeEntity(); system = new System();
system.addEntity(entity); });
it("should remove an entity from the system", () => { system.removeEntity(entity);
expect(system.entities.size).toEqual(0); });
it("should remove the system from entity systems", () => { system.removeEntity(entity);
expect(entity.removeSystem).toHaveBeenCalledWith(system); });
it("should call exit() on removed entity", () => { system.exit = vi.fn();
system.removeEntity(entity);
expect(system.exit).toHaveBeenCalledWith(entity); }); });
describe("updateAll()", () => { it("should call update() on each entity", () => { const entity1 = getFakeEntity(); const entity2 = getFakeEntity(); const system = new System(); system.update = vi.fn();
system.addEntity(entity1); system.addEntity(entity2); system.updateAll(0, 0);
expect(system.update).toHaveBeenCalledTimes(2); });
it("should call preUpdate()", () => { const system = new System(); system.preUpdate = vi.fn();
system.updateAll(0, 0);
expect(system.preUpdate).toHaveBeenCalled(); });
it("should call postUpdate()", () => { const system = new System(); system.postUpdate = vi.fn();
system.updateAll(0, 0);
expect(system.postUpdate).toHaveBeenCalled(); }); });});