import { describe, expect, it } from "bun:test"; import { getAST } from "@gram-lang/parser"; import { compile } from "@gram-lang/kitchen"; import { analyze } from "@gram-lang/analyzer"; import { getDictionary } from "@gram-lang/i18n"; import { toHTML } from "../src/index"; // The baker's percentage showed a help cursor in the shopping list and the // section's ingredients, but no tooltip: only the badge in a step's text // carried its `data-tooltip`, the class giving the cursor to all of them. describe("the baker's percentage badge", () => { for (const lang of ["en", "fr"]) { it(`explains itself wherever it is shown (${lang})`, () => { const source = "## Dough\n\nMix @*flour{500 g} with @water{325 g} and @salt{10 g}.\n"; const { result } = analyze(compile(getAST(source)), {}); const html = toHTML(result, { lang }); const badges = html.match(/]*>/g) ?? []; // In the step, the section's ingredients and the shopping list. expect(badges.length).toBeGreaterThanOrEqual(6); const tooltip = getDictionary(lang).renderer.bakersPercentage.replace( "'", "'", ); for (const badge of badges) { expect(badge).toContain(`data-tooltip="${tooltip}"`); } }); } });