BlueGit

timfa questward

Files

questward / server / tests / dye-tailor.test.js

dye-tailor.test.js

dye-tailor.test.js 1.9 KiB Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import { ItemId } from "../../shared/definitions/items.js";
4import { dyeColorKey } from "../../shared/definitions/dyes.js";
5import { emptySlots } from "../../shared/items/inventory.js";
6import { canCraftFitInventory } from "../../shared/crafting/recipes.js";
7import {
8 listDyePickerChoices,
9 pickEmptiestDyeSlot
10} from "../../shared/crafting/dye.js";
11import { sweaterItemId } from "../../shared/definitions/clothItems.js";
12import { ClothTier } from "../../shared/definitions/materialTiers.js";
13import { yarnItemId } from "../../shared/definitions/clothItems.js";
14
15const red = { r: 0.9, g: 0.1, b: 0.1 };
16
17function dyeStack (color, fillLevel, quantity = 1)
18{
19 return {
20 itemId: ItemId.dye,
21 quantity,
22 instance: { kind: "dye", color, fillLevel }
23 };
24}
25
26test("dye picker shows one fullest bottle per colour", () =>
27{
28 const slots = emptySlots();
29 slots[0] = dyeStack(red, 1);
30 slots[1] = dyeStack(red, 4);
31 slots[2] = dyeStack({ r: 0.1, g: 0.2, b: 0.9 }, 3);
32 const choices = listDyePickerChoices(slots);
33 assert.equal(choices.length, 2);
34 const redChoice = choices.find((entry) => entry.displayIndex === 1);
35 assert.ok(redChoice);
36 assert.equal(redChoice.fill, 4);
37});
38
39test("tailor crafts consume the emptiest bottle of the chosen colour", () =>
40{
41 const slots = emptySlots();
42 const yarn = yarnItemId(ClothTier.cotton);
43 slots[0] = { itemId: yarn, quantity: 3 };
44 slots[1] = dyeStack(red, 4);
45 slots[2] = dyeStack(red, 1);
46 for (let i = 3; i < slots.length; i++)
47 { slots[i] = { itemId: ItemId.apple, quantity: 1 }; }
48 const colorKey = dyeColorKey({ kind: "dye", color: red, fillLevel: 4 });
49 assert.equal(pickEmptiestDyeSlot(slots, colorKey), 2);
50 const recipe = {
51 output: { itemId: sweaterItemId(ClothTier.cotton), quantity: 1 },
52 inputs: [{ itemId: yarn, quantity: 3 }],
53 consumeDye: true,
54 dyeColor: red
55 };
56 assert.equal(canCraftFitInventory(slots, recipe, { dyeColorKey: colorKey }), true);
57});