Files
bworld/tests/recipe_viewer_test.ts
T
2026-09-27 01:25:47 -03:00

43 lines
2.1 KiB
TypeScript

// the recipe viewer mod reads every mod's recipes, its own types included
import { assert, assertEquals } from "@std/assert";
import { category_name, inputs, outputs } from "../mods/recipe_viewer/scripts/client.ts";
import { test_game } from "./helpers.ts";
const ids = (ingredients: { ids: string[] }[]) => ingredients.map((i) => i.ids.join("|"));
Deno.test("the recipe viewer finds what makes and uses an item, in any recipe type", async () => {
const { game } = await test_game("mods");
const all = game.recipes.all;
const making = (item: string) => all.filter((r) => outputs(r).some((o) => o.ids.includes(item)));
const using = (item: string) => all.filter((r) => inputs(r).some((i) => i.ids.includes(item)));
// a shaped recipe, with its count
const [bowl] = making("bworld:bowl");
assertEquals(bowl.type, "shaped");
assertEquals(outputs(bowl), [{ ids: ["bworld:bowl"], count: 4 }]);
// the cooking pot's own type: ingredients, alternatives, and the bowl it's served in
const [rolls] = making("farmersdelight:cabbage_rolls");
assertEquals(category_name(rolls.type), "Cooking");
assertEquals(ids(inputs(rolls)), [
"farmersdelight:cabbage",
"bworld:carrot|bworld:potato|farmersdelight:onion|farmersdelight:tomato",
]);
const [rice] = making("farmersdelight:cooked_rice");
assertEquals(ids(inputs(rice)), ["farmersdelight:rice", "bworld:bowl"]);
// uses: the bowl serves two meals, coal is fuel and in the stove, potatoes are in cabbage rolls
assertEquals(using("bworld:bowl").map((r) => outputs(r)[0].ids[0]).sort(), [
"farmersdelight:cooked_rice",
"farmersdelight:tomato_sauce",
]);
assert(using("bworld:coal").some((r) => r.type === "fuel"));
assert(using("bworld:coal").some((r) => r.type === "shaped" && outputs(r)[0].ids[0] === "farmersdelight:stove"));
assert(using("bworld:potato").includes(rolls));
// smelting and smithing
assertEquals(ids(making("bworld:iron_ingot").flatMap(inputs)), ["bworld:iron_ore"]);
assertEquals(ids(inputs(making("bworld:stone_pickaxe")[0])), ["bworld:wood_pickaxe", "bworld:stone"]);
assertEquals(category_name("smithing"), "Smithing");
});