BlueGit

timfa questward

Files

questward / server / tests / level-up-unlocks.test.js

level-up-unlocks.test.js

level-up-unlocks.test.js 2.5 KiB Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import { SkillId } from "../../shared/definitions/skills.js";
4import
5 {
6 skillUnlockMessages,
7 skillLevelUpToastText
8 } from "../../shared/skills/levelUpUnlocks.js";
9import { applySkillXp, normalizePlayerSkills } from "../../shared/skills/state.js";
10import { SKILL_XP_BASE } from "../../shared/skills/progression.js";
11
12test("defence 9→10 unlocks iron armour wear", () =>
13{
14 const lines = skillUnlockMessages(SkillId.defence, 9, 10);
15 assert.ok(lines.some((line) => /wear Iron armour/i.test(line)));
16});
17
18test("archery 9→10 unlocks birch bows", () =>
19{
20 const lines = skillUnlockMessages(SkillId.archery, 9, 10);
21 assert.ok(lines.some((line) => /Birch bows and Iron arrows/i.test(line)));
22});
23
24test("mining gather unlock for mithril", () =>
25{
26 const lines = skillUnlockMessages(SkillId.mining, 17, 18);
27 assert.ok(lines.some((line) => /mine Mithril ore/i.test(line)));
28});
29
30test("smithing craft unlock for adamantium", () =>
31{
32 const lines = skillUnlockMessages(SkillId.smithing, 37, 38);
33 assert.ok(lines.some((line) => /smith Adamantium items/i.test(line)));
34});
35
36test("toast text includes title and unlock line", () =>
37{
38 const text = skillLevelUpToastText(SkillId.defence, 10, 9);
39 assert.match(text, /Your Defence leveled up to 10!/);
40 assert.match(text, /You can now wear Iron armour\./);
41});
42
43test("multi-level jump reports unlocks for every crossed gate", () =>
44{
45 const lines = skillUnlockMessages(SkillId.woodcutting, 4, 10);
46 assert.ok(lines.some((line) => /chop Birch trees/i.test(line)));
47 assert.ok(lines.some((line) => /equip Iron axes/i.test(line)));
48});
49
50test("magic unlocks use tier skill gates, not every level", () =>
51{
52 assert.deepEqual(skillUnlockMessages(SkillId.magic, 2, 3), []);
53 const atTen = skillUnlockMessages(SkillId.magic, 9, 10);
54 assert.ok(atTen.some((line) => /cast Dark/i.test(line) || /Magic Missile/i.test(line) || /Birch staves/i.test(line)));
55 assert.ok(atTen.some((line) => /Magic Missile/i.test(line)));
56 const atTwenty = skillUnlockMessages(SkillId.magic, 19, 20);
57 assert.ok(atTwenty.some((line) => /tier 3|Firebolt|Poison|Tinders/i.test(line)));
58 assert.equal(skillUnlockMessages(SkillId.magic, 3, 4).filter((l) => /cast/i.test(l)).length, 0);
59});
60
61test("applySkillXp includes previousLevel on level-up", () =>
62{
63 const skills = normalizePlayerSkills(null);
64 const result = applySkillXp(skills, SkillId.strength, SKILL_XP_BASE);
65 assert.equal(result.levelUp?.level, 2);
66 assert.equal(result.levelUp?.previousLevel, 1);
67});