story-kit: merge 195_story_preserve_newlines_in_chat_message_submission

This commit is contained in:
Dave
2026-02-25 18:16:46 +00:00
parent 4e0b6b143b
commit 9f469068fc
2 changed files with 20 additions and 1 deletions

View File

@@ -59,6 +59,24 @@ describe("MessageItem component (Story 178 AC3)", () => {
expect(screen.getByText("Read(src/main.rs)")).toBeInTheDocument(); expect(screen.getByText("Read(src/main.rs)")).toBeInTheDocument();
}); });
it("user messages use pre-wrap whitespace to preserve newlines (Story 195)", () => {
const { container } = render(
<MessageItem
msg={{ role: "user", content: "First line\nSecond line" }}
/>,
);
// The bubble div wrapping user text must have white-space: pre-wrap
// so newlines are rendered as visual line breaks
const divs = Array.from(container.querySelectorAll("div"));
const bubble = divs.find(
(div) =>
div.style.whiteSpace === "pre-wrap" &&
div.textContent?.includes("First line"),
);
expect(bubble).toBeDefined();
});
it("is wrapped in React.memo (has displayName or $$typeof memo)", () => { it("is wrapped in React.memo (has displayName or $$typeof memo)", () => {
// React.memo wraps the component — verify the export is memoized // React.memo wraps the component — verify the export is memoized
// by checking that the component has a memo wrapper // by checking that the component has a memo wrapper

View File

@@ -53,7 +53,8 @@ function MessageItemInner({ msg }: MessageItemProps) {
fontFamily: msg.role === "tool" ? "monospace" : "inherit", fontFamily: msg.role === "tool" ? "monospace" : "inherit",
fontSize: msg.role === "tool" ? "0.85em" : "1em", fontSize: msg.role === "tool" ? "0.85em" : "1em",
fontWeight: "500", fontWeight: "500",
whiteSpace: msg.role === "tool" ? "pre-wrap" : "normal", whiteSpace:
msg.role === "tool" || msg.role === "user" ? "pre-wrap" : "normal",
lineHeight: "1.6", lineHeight: "1.6",
}} }}
> >