nandi/oripublic Fork 0
ca7e020cbb6442f047e0002eb9831ba29f8a17af
Commits
Clone
git clone https://git.rickub.com/nandi/ori.git
git clone ssh://git@rickub.com/nandi/ori.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

forked from bots-garden/ori

InlineText.test.tsx · 34 lines · 1.3 KBTypeScript Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { InlineText } from "./InlineText";

describe("InlineText", () => {
	it("wraps backtick spans in monospace code elements", () => {
		const { container } = render(<InlineText text="Run `ls .memory/` now" />);

		const code = container.querySelector("code.inline-code");
		expect(code?.textContent).toBe("ls .memory/");
		expect(container.textContent).toBe("Run ls .memory/ now");
	});

	it("handles several code spans", () => {
		const { container } = render(<InlineText text="`a` puis `b`" />);
		const codes = container.querySelectorAll("code.inline-code");
		expect(codes).toHaveLength(2);
		expect(codes[0].textContent).toBe("a");
		expect(codes[1].textContent).toBe("b");
	});

	it("renders plain text untouched", () => {
		const { container } = render(<InlineText text="no code here" />);
		expect(container.querySelector("code")).toBeNull();
		expect(screen.getByText("no code here")).toBeDefined();
	});

	it("leaves an unpaired backtick's tail as plain text", () => {
		const { container } = render(<InlineText text="odd `tick" />);
		// "tick" follows an unclosed backtick: rendered as a code span is
		// acceptable, but the full text must survive.
		expect(container.textContent).toBe("odd tick");
	});
});