# test.web/presentation/renderers/lesson.renderer.test.ts

> 41 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-web-presentation-renderers-lesson-renderer-test-ts
Source text: https://banes-lab.com/source/testing/test.web/presentation/renderers/lesson.renderer.test.ts.txt

Listed in [test.web/presentation/renderers](https://banes-lab.com/api/source/testing/test.web/presentation/renderers.md), after [test.web/presentation/renderers/learning.renderer.test.ts](https://banes-lab.com/source/testing/test.web/presentation/renderers/learning.renderer.test.ts.md) and before [test.web/presentation/renderers/markdown.renderer.test.ts](https://banes-lab.com/source/testing/test.web/presentation/renderers/markdown.renderer.test.ts.md).

## Contained in

- [test.web/presentation/renderers](https://banes-lab.com/anatomy/testing/folder-testing-test-web-presentation-renderers.md)

## Source

```typescript
import { describe, expect, it } from "vitest";
import type { LessonBlock } from "@banes-lab/web/types/block.types.ts";
import { renderBlock } from "@banes-lab/web/presentation/renderers/block.renderer.ts";
import { renderLesson } from "@banes-lab/web/presentation/renderers/lesson.renderer.ts";

const LESSON: LessonBlock = {
    application: "application <em>text</em>",
    cause: "cause",
    decision: "decision",
    failureMode: "failure mode",
    kind: "lesson",
    principle: "principle",
    problem: "problem",
    validation: "validation",
};

const paragraphsOf = function paragraphsOf(element: Element): string[] {
    return [...element.querySelectorAll("p")].map((paragraph) => paragraph.textContent);
};

describe("renderLesson", () => {
    it("flows the fields into three unlabeled paragraphs, the concrete situation before the principle", () => {
        const rendered = renderLesson(LESSON);
        expect(paragraphsOf(rendered)).toStrictEqual([
            "problem failure mode cause",
            "principle decision application text",
            "validation",
        ]);
        expect(rendered.querySelector("strong")).toBeNull();
        expect(rendered.querySelector("em")).not.toBeNull();
    });

    it("closes the last paragraph with the boundary only when the lesson declares one", () => {
        expect(paragraphsOf(renderLesson({ ...LESSON, boundary: "when not" })).at(-1)).toBe("validation when not");
        expect(paragraphsOf(renderLesson({ ...LESSON, boundary: "when not" }))).toHaveLength(3);
        expect(paragraphsOf(renderLesson(LESSON))).toHaveLength(3);
    });
});

describe("renderBlock with a lesson", () => {
    it("dispatches to the lesson renderer rather than the composite fallback", () => {
        const rendered = renderBlock(LESSON);
        expect(rendered.classList.contains("block-lesson")).toBe(true);
        expect(rendered.querySelectorAll("p")).toHaveLength(3);
    });
});
```
