136 lines
4.3 KiB
JavaScript
136 lines
4.3 KiB
JavaScript
|
|
import { expect } from "@esm-bundle/chai";
|
||
|
|
import { RosterManager } from "../../src/managers/RosterManager.js";
|
||
|
|
|
||
|
|
describe("Manager: RosterManager", () => {
|
||
|
|
let manager;
|
||
|
|
|
||
|
|
beforeEach(() => {
|
||
|
|
manager = new RosterManager();
|
||
|
|
});
|
||
|
|
|
||
|
|
it("CoA 1: Should initialize with empty roster and graveyard", () => {
|
||
|
|
expect(manager.roster).to.be.an("array").that.is.empty;
|
||
|
|
expect(manager.graveyard).to.be.an("array").that.is.empty;
|
||
|
|
expect(manager.rosterLimit).to.equal(12);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("CoA 2: recruitUnit should add unit to roster with generated ID", () => {
|
||
|
|
const unitData = {
|
||
|
|
class: "CLASS_VANGUARD",
|
||
|
|
name: "Test Unit",
|
||
|
|
stats: { hp: 100 },
|
||
|
|
};
|
||
|
|
|
||
|
|
const newUnit = manager.recruitUnit(unitData);
|
||
|
|
|
||
|
|
expect(newUnit).to.exist;
|
||
|
|
expect(newUnit.id).to.match(/^UNIT_\d+_\d+$/);
|
||
|
|
expect(newUnit.class).to.equal("CLASS_VANGUARD");
|
||
|
|
expect(newUnit.name).to.equal("Test Unit");
|
||
|
|
expect(newUnit.status).to.equal("READY");
|
||
|
|
expect(newUnit.history).to.deep.equal({ missions: 0, kills: 0 });
|
||
|
|
expect(manager.roster).to.have.length(1);
|
||
|
|
expect(manager.roster[0]).to.equal(newUnit);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("CoA 3: recruitUnit should return false when roster is full", () => {
|
||
|
|
// Fill roster to limit
|
||
|
|
for (let i = 0; i < manager.rosterLimit; i++) {
|
||
|
|
manager.recruitUnit({ class: "CLASS_VANGUARD", name: `Unit ${i}` });
|
||
|
|
}
|
||
|
|
|
||
|
|
const result = manager.recruitUnit({ class: "CLASS_VANGUARD", name: "Extra" });
|
||
|
|
|
||
|
|
expect(result).to.be.false;
|
||
|
|
expect(manager.roster).to.have.length(manager.rosterLimit);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("CoA 4: handleUnitDeath should move unit to graveyard and remove from roster", () => {
|
||
|
|
const unit = manager.recruitUnit({
|
||
|
|
class: "CLASS_VANGUARD",
|
||
|
|
name: "Test Unit",
|
||
|
|
});
|
||
|
|
const unitId = unit.id;
|
||
|
|
|
||
|
|
manager.handleUnitDeath(unitId);
|
||
|
|
|
||
|
|
expect(manager.roster).to.be.empty;
|
||
|
|
expect(manager.graveyard).to.have.length(1);
|
||
|
|
expect(manager.graveyard[0].id).to.equal(unitId);
|
||
|
|
expect(manager.graveyard[0].status).to.equal("DEAD");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("CoA 5: handleUnitDeath should do nothing if unit not found", () => {
|
||
|
|
manager.recruitUnit({ class: "CLASS_VANGUARD", name: "Unit 1" });
|
||
|
|
|
||
|
|
manager.handleUnitDeath("NONEXISTENT_ID");
|
||
|
|
|
||
|
|
expect(manager.roster).to.have.length(1);
|
||
|
|
expect(manager.graveyard).to.be.empty;
|
||
|
|
});
|
||
|
|
|
||
|
|
it("CoA 6: getDeployableUnits should return only READY units", () => {
|
||
|
|
const ready1 = manager.recruitUnit({
|
||
|
|
class: "CLASS_VANGUARD",
|
||
|
|
name: "Ready 1",
|
||
|
|
});
|
||
|
|
const ready2 = manager.recruitUnit({
|
||
|
|
class: "CLASS_TINKER",
|
||
|
|
name: "Ready 2",
|
||
|
|
});
|
||
|
|
|
||
|
|
// Manually set a unit to INJURED
|
||
|
|
manager.roster[0].status = "INJURED";
|
||
|
|
|
||
|
|
const deployable = manager.getDeployableUnits();
|
||
|
|
|
||
|
|
expect(deployable).to.have.length(1);
|
||
|
|
expect(deployable[0].id).to.equal(ready2.id);
|
||
|
|
expect(deployable[0].status).to.equal("READY");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("CoA 7: load should restore roster and graveyard from save data", () => {
|
||
|
|
const saveData = {
|
||
|
|
roster: [
|
||
|
|
{ id: "UNIT_1", class: "CLASS_VANGUARD", status: "READY" },
|
||
|
|
{ id: "UNIT_2", class: "CLASS_TINKER", status: "INJURED" },
|
||
|
|
],
|
||
|
|
graveyard: [{ id: "UNIT_3", class: "CLASS_VANGUARD", status: "DEAD" }],
|
||
|
|
};
|
||
|
|
|
||
|
|
manager.load(saveData);
|
||
|
|
|
||
|
|
expect(manager.roster).to.have.length(2);
|
||
|
|
expect(manager.graveyard).to.have.length(1);
|
||
|
|
expect(manager.roster[0].id).to.equal("UNIT_1");
|
||
|
|
expect(manager.graveyard[0].id).to.equal("UNIT_3");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("CoA 8: save should serialize roster and graveyard", () => {
|
||
|
|
manager.recruitUnit({ class: "CLASS_VANGUARD", name: "Unit 1" });
|
||
|
|
manager.recruitUnit({ class: "CLASS_TINKER", name: "Unit 2" });
|
||
|
|
const unitId = manager.roster[0].id;
|
||
|
|
manager.handleUnitDeath(unitId);
|
||
|
|
|
||
|
|
const saved = manager.save();
|
||
|
|
|
||
|
|
expect(saved).to.have.property("roster");
|
||
|
|
expect(saved).to.have.property("graveyard");
|
||
|
|
expect(saved.roster).to.have.length(1);
|
||
|
|
expect(saved.graveyard).to.have.length(1);
|
||
|
|
expect(saved.roster[0].name).to.equal("Unit 2");
|
||
|
|
expect(saved.graveyard[0].id).to.equal(unitId);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("CoA 9: clear should reset roster and graveyard", () => {
|
||
|
|
manager.recruitUnit({ class: "CLASS_VANGUARD", name: "Unit 1" });
|
||
|
|
manager.handleUnitDeath(manager.roster[0].id);
|
||
|
|
|
||
|
|
manager.clear();
|
||
|
|
|
||
|
|
expect(manager.roster).to.be.empty;
|
||
|
|
expect(manager.graveyard).to.be.empty;
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|