telega/testing/render
Pure canonicalizers for snapshot testing.
Turns API-call recordings and keyboard markup into stable, human-readable
strings suitable for snapshot libraries like birdie. Nothing here depends
on a snapshot library — the functions just build strings, so bot authors
can use them with any testing setup.
import birdie
import telega/testing/mock
import telega/testing/render
let #(client, calls) = mock.message_client()
// ... drive your bot ...
mock.get_calls(calls)
|> render.calls_transcript
|> birdie.snap(title: "greeting:start_command")
Values
pub fn calls_transcript(
calls calls: List(mock.ApiCall),
) -> String
Render a transcript of recorded API calls: one entry per call with the method name and the canonical JSON body. The bot token never appears in the output. Non-JSON bodies are included verbatim.
pub fn canonical_json(input: String) -> Result(String, Nil)
Parse a JSON string and re-serialize it canonically: object keys sorted,
two-space indentation. Produces stable diffs regardless of encoder key
order. Returns Error(Nil) if the input is not valid JSON.
pub fn formatted_frame(
formatted formatted: format.FormattedText,
) -> String
Render formatted text as a “frame”: the parse mode header followed by the rendered text. Snapshot one frame per parse mode to pin down escaping.
pub fn keyboard_grid(
markup markup: types.InlineKeyboardMarkup,
) -> String
Render an inline keyboard as an ASCII grid, one row per line:
[ ○ English ](lang:en) | [ ● Русский ](lang:ru)
[ Docs ](url:https://example.com)
pub fn window_frame(
window window: types.RenderedWindow,
) -> String
Render the full visible “frame” of a dialog window: parse mode, media,
text, and button grid. This is the level-1 dialog snapshot —
window.render(state, ctx) is pure, so no network or actors are involved.