Files
site-builder/craft/src/App.mobile-chrome.test.tsx
T
shadowdaoandClaude Opus 5.5 eb401cd979 fix(sections): inserting from the section library closes the mobile Blocks sheet
The section library now calls closeSheet() after inserting a section (or a
global section). It mounts in CanvasOverlays, beside EditorShell, so it could
not reach the MobileChromeProvider inside the shell; the provider moves up to
App around the shell and the overlays so both share one sheet state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 13:41:22 -07:00

41 lines
1.7 KiB
TypeScript

import { describe, test, expect, vi, afterEach } from 'vitest';
import React from 'react';
import { createRoot, Root } from 'react-dom/client';
import { act } from 'react-dom/test-utils';
import { useMobileChrome } from './state/MobileChromeContext';
import { ensureJsdomShims } from './test-utils/editorHarness';
/**
* The overlays (section library, command palette) mount NEXT TO the shell in
* App, so the mobile chrome state (open sheet) must be provided above both:
* otherwise the section library's closeSheet() after an insert hits the
* default no-op and the Blocks sheet stays open over the canvas.
*/
const seen: { shell?: ReturnType<typeof useMobileChrome>; overlays?: ReturnType<typeof useMobileChrome> } = {};
vi.mock('./editor/EditorShell', () => ({
EditorShell: () => { seen.shell = useMobileChrome(); return null; },
}));
vi.mock('./editor/CanvasOverlays', () => ({
CanvasOverlays: () => { seen.overlays = useMobileChrome(); return null; },
}));
import { App } from './App';
let root: Root;
let container: HTMLDivElement;
afterEach(() => { act(() => { root.unmount(); }); container.remove(); });
describe('App mobile chrome wiring', () => {
test('the shell and the overlays share one MobileChromeContext', () => {
ensureJsdomShims();
container = document.createElement('div');
document.body.appendChild(container);
act(() => { root = createRoot(container); root.render(<App whpConfig={null as any} />); });
act(() => seen.shell!.openSheet('blocks'));
expect(seen.shell!.activeSheet).toBe('blocks');
expect(seen.overlays!.activeSheet).toBe('blocks');
act(() => seen.overlays!.closeSheet());
expect(seen.shell!.activeSheet).toBeNull();
});
});