aether-shards/test/units/Explorer.test.js

73 lines
2.4 KiB
JavaScript

import { expect } from "@esm-bundle/chai";
import { Explorer } from "../../src/units/Explorer.js";
// Mock Class Definitions
const CLASS_VANGUARD = {
id: "CLASS_VANGUARD",
base_stats: { health: 100, attack: 10, speed: 5 },
growth_rates: { health: 10, attack: 1 },
};
const CLASS_TINKER = {
id: "CLASS_TINKER",
base_stats: { health: 80, attack: 8, speed: 7 },
growth_rates: { health: 5, attack: 2 },
};
describe("Unit: Explorer Class Logic", () => {
it("CoA 1: Should initialize with base stats from definition", () => {
const hero = new Explorer("p1", "Hero", "CLASS_VANGUARD", CLASS_VANGUARD);
expect(hero.baseStats.health).to.equal(100);
expect(hero.baseStats.attack).to.equal(10);
expect(hero.classMastery["CLASS_VANGUARD"]).to.exist;
expect(hero.classMastery["CLASS_VANGUARD"].level).to.equal(1);
});
it("CoA 2: Should calculate stats based on Level Growth", () => {
const hero = new Explorer("p1", "Hero", "CLASS_VANGUARD", CLASS_VANGUARD);
// Manually level up to 3
hero.classMastery["CLASS_VANGUARD"].level = 3;
hero.recalculateBaseStats(CLASS_VANGUARD);
// Level 3 means 2 level-ups.
// Health: 100 + (10 * 2) = 120
// Attack: 10 + (1 * 2) = 12
expect(hero.baseStats.health).to.equal(120);
expect(hero.baseStats.attack).to.equal(12);
});
it("CoA 3: changeClass should switch stats and persist old progress", () => {
const hero = new Explorer("p1", "Hero", "CLASS_VANGUARD", CLASS_VANGUARD);
// Level up Vanguard
hero.classMastery["CLASS_VANGUARD"].level = 5;
hero.recalculateBaseStats(CLASS_VANGUARD);
expect(hero.baseStats.health).to.equal(140); // 100 + 40
// Switch to Tinker (New Job)
hero.changeClass("CLASS_TINKER", CLASS_TINKER);
// Should have Level 1 Tinker Stats
expect(hero.activeClassId).to.equal("CLASS_TINKER");
expect(hero.baseStats.health).to.equal(80); // Base Tinker
// Verify Vanguard history is saved
expect(hero.classMastery["CLASS_VANGUARD"].level).to.equal(5);
});
it("CoA 4: Switching BACK to old class should restore high stats", () => {
const hero = new Explorer("p1", "Hero", "CLASS_VANGUARD", CLASS_VANGUARD);
hero.classMastery["CLASS_VANGUARD"].level = 5;
// Switch Away
hero.changeClass("CLASS_TINKER", CLASS_TINKER);
// Switch Back
hero.changeClass("CLASS_VANGUARD", CLASS_VANGUARD);
// Should be back to Level 5 Stats
expect(hero.baseStats.health).to.equal(140);
});
});