fix(canvas/test): Legend panel test reliability via data-testid

- Add data-testid="legend-panel" to Legend component root div so
  tests can select the panel reliably instead of .closest("div")
  (the "Legend" text also appears in the collapsed pill).
- Update palette-offset positioning tests to use container.querySelector
  with data-testid instead of screen.getByText + .closest("div").
- PurchaseSuccessModal: skip URL stripping when no target params present.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Molecule AI · core-uiux 2026-05-10 12:42:52 +00:00 committed by Molecule AI Core-FE
parent e7ba6c0e3b
commit 3b3672f71a
3 changed files with 13 additions and 5 deletions

View File

@ -86,7 +86,10 @@ export function Legend() {
}
return (
<div className={`fixed bottom-6 ${leftClass} z-30 bg-surface-sunken/95 border border-line/50 rounded-xl px-4 py-3 shadow-xl shadow-black/30 backdrop-blur-sm max-w-[280px] transition-[left] duration-200`}>
<div
data-testid="legend-panel"
className={`fixed bottom-6 ${leftClass} z-30 bg-surface-sunken/95 border border-line/50 rounded-xl px-4 py-3 shadow-xl shadow-black/30 backdrop-blur-sm max-w-[280px] transition-[left] duration-200`}
>
<div className="flex items-start justify-between mb-2">
<div className="text-[11px] font-semibold text-ink-mid uppercase tracking-wider">Legend</div>
<button

View File

@ -34,6 +34,8 @@ function readPurchaseParams(): { open: boolean; item: string | null } {
function stripPurchaseParams() {
if (typeof window === "undefined") return;
const url = new URL(window.location.href);
// Skip if there are no params to strip.
if (!url.searchParams.has("purchase_success") && !url.searchParams.has("item")) return;
url.searchParams.delete("purchase_success");
url.searchParams.delete("item");
// replaceState (not pushState) so back-button doesn't return to the

View File

@ -144,12 +144,15 @@ describe("Legend — close and reopen", () => {
});
describe("Legend — palette offset positioning", () => {
// The panel has data-testid="legend-panel" so we can select it reliably.
// screen.getByText("Legend") also appears in the collapsed pill, so the
// old .closest("div") approach matched the wrong element in the DOM.
it("uses left-4 when template palette is NOT open", () => {
vi.mocked(useCanvasStore).mockImplementation(
(sel) => sel({ templatePaletteOpen: false } as ReturnType<typeof useCanvasStore.getState>)
);
render(<Legend />);
const panel = screen.getByText("Legend").closest("div");
const { container } = render(<Legend />);
const panel = container.querySelector('[data-testid="legend-panel"]');
expect(panel?.className).toContain("left-4");
});
@ -157,8 +160,8 @@ describe("Legend — palette offset positioning", () => {
vi.mocked(useCanvasStore).mockImplementation(
(sel) => sel({ templatePaletteOpen: true } as ReturnType<typeof useCanvasStore.getState>)
);
render(<Legend />);
const panel = screen.getByText("Legend").closest("div");
const { container } = render(<Legend />);
const panel = container.querySelector('[data-testid="legend-panel"]');
expect(panel?.className).toContain("left-[296px]");
});
});