gram/packages/renderer/tests/bakers-badge-tooltip.test.ts
abiwab 6142d252f4
All checks were successful
CI / Build & Test (pull_request) Successful in 5m47s
fix(renderer): explain the baker's percentage in a tooltip and drop its frame
2026-11-30 19:49:12 +01:00

30 lines
1.2 KiB
TypeScript

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(/<span class="bakers-badge"[^>]*>/g) ?? [];
// In the step, the section's ingredients and the shopping list.
expect(badges.length).toBeGreaterThanOrEqual(6);
const tooltip = getDictionary(lang).renderer.bakersPercentage.replace(
"'",
"&#039;",
);
for (const badge of badges) {
expect(badge).toContain(`data-tooltip="${tooltip}"`);
}
});
}
});