The markdown overlay shared the wrapper's inset-0 box with the transparent-text textarea, but its inner div added a 1px transparent border while the textarea is border-0, shrinking its text width by ~2px; Firefox/Safari classic scrollbars reserve another ~15px inside the scrolled textarea that the overflow-hidden overlay never sees. Either gutter makes long unbreakable tokens (e.g. image markdown URLs) wrap differently between the two layers, so the overlay text drifts vertically under the caret/click math and editing feels like it's one or more lines off right after inserting an image. Compose both layers' classes from a shared WIKI_EDITOR_METRICS constant, drop the overlay border, hide the textarea scrollbar so its content width matches the overlay in every browser, and lock class parity with a jsdom RTL spec. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
79 lines
2.8 KiB
TypeScript
79 lines
2.8 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { createElement, createRef } from "react";
|
|
import { cleanup, render } from "@testing-library/react";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { WikiEditorBody } from "@/components/frontend/wiki/WikiEditorBody";
|
|
import { WIKI_EDITOR_METRICS, WIKI_EDITOR_SCROLLBAR_NONE } from "@/components/frontend/wiki/editorMetrics";
|
|
|
|
vi.mock("@/app/(frontend)/wiki/actions", () => ({
|
|
uploadWikiImage: vi.fn(),
|
|
}));
|
|
|
|
afterEach(cleanup);
|
|
|
|
function tokens(className: string | null): Set<string> {
|
|
return new Set((className ?? "").trim().split(/\s+/).filter(Boolean));
|
|
}
|
|
|
|
describe("wiki editor overlay/textarea parity", () => {
|
|
const body = "# Heading\n\nSome long line ".repeat(10);
|
|
|
|
function renderEditor() {
|
|
const ref = createRef<HTMLTextAreaElement>();
|
|
const { container } = render(
|
|
createElement(WikiEditorBody, {
|
|
body,
|
|
bodyRef: ref,
|
|
existingPages: [],
|
|
linkDialogOpen: false,
|
|
onBodyChange: () => {},
|
|
onLinkDialogChange: () => {},
|
|
pending: false,
|
|
templates: {},
|
|
}),
|
|
);
|
|
const textarea = container.querySelector("textarea#wiki-body");
|
|
const overlayInner = container.querySelector("div.pointer-events-none > div");
|
|
return { textarea, overlayInner };
|
|
}
|
|
|
|
it("renders both layers", () => {
|
|
const { textarea, overlayInner } = renderEditor();
|
|
expect(textarea).not.toBeNull();
|
|
expect(overlayInner).not.toBeNull();
|
|
});
|
|
|
|
it("shares identical padding/typography classes between textarea and overlay", () => {
|
|
const { textarea, overlayInner } = renderEditor();
|
|
const shared = tokens(WIKI_EDITOR_METRICS);
|
|
expect(shared.size).toBeGreaterThan(0);
|
|
for (const layer of [textarea, overlayInner]) {
|
|
const cls = tokens(layer?.className ?? null);
|
|
for (const metric of shared) {
|
|
expect(cls.has(metric), `${layer?.id ?? "overlay"} missing "${metric}"`).toBe(true);
|
|
}
|
|
}
|
|
});
|
|
|
|
it("keeps the overlay borderless (a border shrinks its width and desyncs wrapping)", () => {
|
|
const { overlayInner } = renderEditor();
|
|
const cls = tokens(overlayInner?.className ?? "");
|
|
for (const clsName of cls) expect(clsName).not.toMatch(/^border/);
|
|
});
|
|
|
|
it("hides the textarea scrollbar so its gutter never shrinks the content width", () => {
|
|
const { textarea } = renderEditor();
|
|
const cls = tokens(textarea?.className ?? "");
|
|
for (const token of tokens(WIKI_EDITOR_SCROLLBAR_NONE)) {
|
|
expect(cls.has(token), `textarea missing "${token}"`).toBe(true);
|
|
}
|
|
});
|
|
|
|
it("keeps the textarea flush and borderless inside the shared wrapper", () => {
|
|
const { textarea } = renderEditor();
|
|
const cls = tokens(textarea?.className ?? "");
|
|
for (const clsName of ["absolute", "inset-0", "border-0"]) {
|
|
expect(cls.has(clsName), `textarea missing "${clsName}"`).toBe(true);
|
|
}
|
|
});
|
|
});
|