diff --git a/lib/react/GenericSolverDebugger.tsx b/lib/react/GenericSolverDebugger.tsx index 4e46d8c..aa0255e 100644 --- a/lib/react/GenericSolverDebugger.tsx +++ b/lib/react/GenericSolverDebugger.tsx @@ -81,7 +81,9 @@ export const GenericSolverDebugger = ({ (visualization.rects?.length || 0) === 0 && (visualization.lines?.length || 0) === 0 && (visualization.points?.length || 0) === 0 && - (visualization.circles?.length || 0) === 0, + (visualization.circles?.length || 0) === 0 && + (visualization.texts?.length || 0) === 0 && + (visualization.arrows?.length || 0) === 0, [visualization], ) diff --git a/tests/nonempty-graphics.test.tsx b/tests/nonempty-graphics.test.tsx new file mode 100644 index 0000000..7ea0565 --- /dev/null +++ b/tests/nonempty-graphics.test.tsx @@ -0,0 +1,78 @@ +import { afterAll, beforeAll, expect, test } from "bun:test" +import type { GraphicsObject } from "graphics-debug" +import type { ReactElement } from "react" +import { BaseSolver } from "../lib/BaseSolver" +import { GenericSolverDebugger } from "../lib/react/GenericSolverDebugger" + +const { + renderToStaticMarkup, +}: { + renderToStaticMarkup: (element: ReactElement) => string +} = require("react-dom/server") + +const originalWindow = Object.getOwnPropertyDescriptor(globalThis, "window") +beforeAll(() => { + // The interactive renderer reads browser settings during its initial render. + Object.defineProperty(globalThis, "window", { + configurable: true, + value: { + location: { pathname: "/", search: "" }, + localStorage: { getItem: () => null }, + addEventListener: () => {}, + removeEventListener: () => {}, + ResizeObserver: class { + observe() {} + unobserve() {} + disconnect() {} + }, + }, + }) +}) +afterAll(() => { + if (originalWindow) + Object.defineProperty(globalThis, "window", originalWindow) + else Reflect.deleteProperty(globalThis, "window") +}) + +class VisualSolver extends BaseSolver { + constructor(private graphics: GraphicsObject) { + super() + } + + override visualize() { + return this.graphics + } +} + +test("the debugger displays graphics containing only text", () => { + const solver = new VisualSolver({ + texts: [{ x: 0, y: 0, text: "Route complete" }], + }) + const html = renderToStaticMarkup() + + expect(html).not.toContain("No Graphics Yet") + expect(html).toContain("Route complete") +}) + +test("the debugger still shows its placeholder for empty graphics", () => { + const solver = new VisualSolver({ + points: [], + lines: [], + rects: [], + circles: [], + texts: [], + }) + const html = renderToStaticMarkup() + + expect(html).toContain("No Graphics Yet") +}) + +test("the debugger displays graphics containing only arrows", () => { + const solver = new VisualSolver({ + arrows: [{ start: { x: 0, y: 0 }, end: { x: 10, y: 5 } }], + }) + const html = renderToStaticMarkup() + + expect(html).not.toContain("No Graphics Yet") + expect(html).toContain("