Files
bworld/tests/recipe_viewer_test.ts
T

45 lines
2.3 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 as recipe_inputs, outputs } from "../mods/recipe_viewer/scripts/client.ts";
import { tag_api } from "$/common/tags.ts";
import { test_game } from "./helpers.ts";
const ids = (ingredients: { ids: string[] }[]) => ingredients.map((i) => i.ids.join("|"));
// deno-lint-ignore no-explicit-any
const inputs = (recipe: any) => recipe_inputs(recipe, tag_api());
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 meals, coal is fuel and in the stove, potatoes are in cabbage rolls
const served_in_bowls = using("bworld:bowl").map((r) => outputs(r)[0].ids[0]);
assert(served_in_bowls.includes("farmersdelight:cooked_rice"));
assert(served_in_bowls.includes("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");
});