BlueGit

timfa questward

Files

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

level-up-unlocks.test.js

level-up-unlocks.test.js 1.9 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("applySkillXp includes previousLevel on level-up", () =>
51{
52 const skills = normalizePlayerSkills(null);
53 const result = applySkillXp(skills, SkillId.strength, SKILL_XP_BASE);
54 assert.equal(result.levelUp?.level, 2);
55 assert.equal(result.levelUp?.previousLevel, 1);
56});