diff --git a/app/__tests__/components/install-card.test.ts b/app/__tests__/components/install-card.test.ts new file mode 100644 index 00000000..2fc6ba03 --- /dev/null +++ b/app/__tests__/components/install-card.test.ts @@ -0,0 +1,26 @@ +/** + * The site's install card stays off an open world view: the view's root says it is there (data-world-view), the card + * carries data-install-card, and one plain rule in globals.css hides the card while the page holds a world view. Nothing + * else decides the card (its visit count, its dismissal and its timer stay), so leaving the view shows it again. + */ +import fs from 'fs'; +import path from 'path'; + +const IP = fs.readFileSync(path.join(__dirname, '../../src/components/pwa/InstallPrompt.tsx'), 'utf8'); +const CSS = fs.readFileSync(path.join(__dirname, '../../src/app/globals.css'), 'utf8'); + +describe('the install card', () => { + it('the install card hides while a world view is open', () => { + expect(IP).toContain( + '
', + ); + expect(CSS).toMatch(/body:has\(\[data-world-view\]\) \[data-install-card\] \{\s*display: none;\s*\}/); + }); + + it('nothing else decides the card', () => { + expect(IP).toContain('if (getVisitCount() < 2) return;'); + expect(IP).toContain('if (isInstallDismissed()) return;'); + expect(IP.split('setTimeout(() => setVisible(true), 2000)').length).toBe(3); + expect(IP).not.toContain('usePathname'); + }); +}); diff --git a/app/__tests__/components/world-corners.test.ts b/app/__tests__/components/world-corners.test.ts index 46b24715..9548902f 100644 --- a/app/__tests__/components/world-corners.test.ts +++ b/app/__tests__/components/world-corners.test.ts @@ -102,8 +102,7 @@ describe('the corners of the world view', () => { for (const s of [ "inert={panelSize === 'hidden'}", 'ref={panelRef}', - 'ref={panelHideRef}', - 'aria-label="Hide block panel"', + 'hideRef={panelHideRef}', 'panelTabRef.current?.focus()', 'panelHideRef.current?.focus()', 'if (lastPanel.current === panelSize) return;', @@ -158,8 +157,6 @@ describe('the corners of the world view', () => { expect(PV).toContain( "{viewMode !== 'standard' && scene === 'ok' &&
", ); - expect(PV).toContain("const PANEL_SHEET_BELOW_MD = 'max-md:absolute "); - expect(PV).toContain(": 'max-md:hidden'}"); expect(PV).not.toContain('md:min-w-0'); }); }); diff --git a/app/__tests__/components/world-panel-frame.test.tsx b/app/__tests__/components/world-panel-frame.test.tsx new file mode 100644 index 00000000..39949972 --- /dev/null +++ b/app/__tests__/components/world-panel-frame.test.tsx @@ -0,0 +1,127 @@ +/** @jest-environment jsdom */ +/** + * The block panel's frame, pressed: an open panel is the side column from md up and the bottom sheet below it, the hide + * button hides it, the width buttons and the tabs do what they say, and below md the hide button shares the tab row. + * The view (ParcelView) keeps the state and wires these two modules as the harness component below does. + */ +import * as React from 'react'; +import { fireEvent, render, screen } from '@testing-library/react'; +import PanelBar from '@/components/nexus/world/PanelBar'; +import { panelRootClass, type PanelSize, type RightTab } from '@/components/nexus/world/panel-frame'; + +const TABS = [{ key: 'properties' as RightTab, label: 'PROPERTIES' }, { key: 'chat' as RightTab, label: 'CHAT' }]; +const OPEN: PanelSize[] = ['compact', 'quarter', 'third', 'half']; +const SHEET = ['max-md:absolute', 'max-md:inset-x-0', 'max-md:bottom-[calc(72px+env(safe-area-inset-bottom))]', + 'max-md:z-30', 'max-md:!w-full', 'max-md:h-[calc(45vh-72px)]', 'max-md:landscape:min-h-[min(224px,calc(100%-136px))]', + 'max-md:rounded-t-2xl', 'max-md:border-t', 'max-md:border-line-2']; +function Panel({ initial }: { initial: PanelSize }) { + const [size, setSize] = React.useState(initial); + const [tab, setTab] = React.useState('properties'); + const hide = React.useRef(null); + return ( +
+ +
+ ); +} +const classes = () => screen.getByTestId('root').className.split(/\s+/); +const split = (el: Element) => (el.getAttribute('class') || '').split(/\s+/); +const noop = () => undefined; + +describe("the block panel's frame", () => { + it('an open panel is the sheet below md and never hidden there; a hidden one leaves the flow below md', () => { + const widths: Record = { compact: 'w-80', quarter: 'w-96', third: 'w-[33vw]', half: 'w-[50vw]' }; + for (const s of OPEN) { + const c = panelRootClass(s).split(' '); + for (const k of [...SHEET, 'md:border-l', 'md:border-line-2', 'bp-dark', 'bg-bg-primary', 'flex-shrink-0', 'flex', + 'flex-col', 'overflow-hidden', 'transition-all', 'duration-300', 'motion-reduce:transition-none', widths[s]]) { + expect(c).toContain(k); + } + for (const k of ['max-md:hidden', 'max-md:bottom-0', 'max-md:h-[45vh]']) expect(c).not.toContain(k); + expect(c.some((k) => k.includes('100dvh'))).toBe(false); + } + const h = panelRootClass('hidden').split(' '); + for (const k of ['max-md:hidden', 'w-0', 'bp-dark', 'flex-shrink-0', 'motion-reduce:transition-none']) expect(h).toContain(k); + for (const k of ['max-md:absolute', 'md:border-l']) expect(h).not.toContain(k); + }); + + it('the hide button hides the panel, and the tab and the widths reopen and size it', () => { + render(); + expect(classes()).toContain('w-96'); + expect(classes()).toContain('max-md:absolute'); + fireEvent.click(screen.getByRole('button', { name: 'Hide block panel' })); + expect(screen.getByTestId('root').dataset.size).toBe('hidden'); + expect(classes()).toContain('w-0'); + expect(classes()).toContain('max-md:hidden'); + expect(classes()).not.toContain('max-md:absolute'); + fireEvent.click(screen.getByRole('button', { name: 'XL' })); + expect(screen.getByTestId('root').dataset.size).toBe('half'); + expect(classes()).toContain('w-[50vw]'); + expect(screen.getByRole('button', { name: 'XL' }).getAttribute('aria-pressed')).toBe('true'); + expect(screen.getByRole('button', { name: 'M' }).getAttribute('aria-pressed')).toBe('false'); + for (const [label, size] of [['S', 'compact'], ['L', 'third'], ['M', 'quarter']]) { + fireEvent.click(screen.getByRole('button', { name: label })); + expect(screen.getByTestId('root').dataset.size).toBe(size); + } + }); + + it('the widths are a named group of four lettered buttons, each with its plain title', () => { + render(); + const group = screen.getByRole('group', { name: 'Panel width' }); + const buttons = Array.from(group.querySelectorAll('button')); + expect(buttons.map((b) => b.textContent)).toEqual(['S', 'M', 'L', 'XL']); + expect(buttons.map((b) => b.getAttribute('title'))).toEqual(['Narrow', 'Default', 'One third', 'Half']); + for (const b of buttons) { + expect(b.hasAttribute('aria-label')).toBe(false); + for (const k of ['min-h-[44px]', 'min-w-[44px]', 'focus-visible:outline-2']) expect(split(b)).toContain(k); + } + const pressed = buttons.filter((b) => b.getAttribute('aria-pressed') === 'true'); + expect(pressed).toHaveLength(1); + expect(split(pressed[0])).toContain('bg-surface-3'); + expect(split(group)).toContain('hidden'); + expect(split(group)).toContain('md:flex'); + }); + + it('the hide button is 44 px, ringed, an icon with a label, and the ref the view focuses', () => { + const ref = React.createRef(); + render(); + const hide = screen.getByRole('button', { name: 'Hide block panel' }); + expect(ref.current).toBe(hide); + expect(hide.getAttribute('title')).toBe('Hide panel'); + for (const k of ['min-h-[44px]', 'min-w-[44px]', 'focus-visible:outline-2', 'order-2', 'mr-2']) expect(split(hide)).toContain(k); + expect(hide.textContent).toBe(''); + const svgs = hide.querySelectorAll('svg'); + expect(svgs).toHaveLength(1); + expect(svgs[0].getAttribute('aria-hidden')).toBe('true'); + expect(svgs[0].getAttribute('width')).toBe('18'); + }); + + it('the tabs press, say which is shown, and sit left of the hide button below md', () => { + const { container } = render(); + fireEvent.click(screen.getByRole('button', { name: 'CHAT' })); + const chat = screen.getByRole('button', { name: 'CHAT' }); + const props = screen.getByRole('button', { name: 'PROPERTIES' }); + expect(chat.getAttribute('aria-pressed')).toBe('true'); + expect(split(chat)).toContain('border-text-1'); + expect(split(chat)).toContain('text-text-1'); + expect(props.getAttribute('aria-pressed')).toBe('false'); + expect(split(props)).toContain('border-transparent'); + for (const b of [chat, props]) { + expect(split(b)).toContain('min-h-[44px]'); + expect(split(b)).toContain('focus-visible:outline-2'); + } + const bar = container.querySelector('[data-world-panel-head]') as HTMLElement; + expect(bar).not.toBeNull(); + for (const k of ['flex-wrap', 'border-b', 'border-line-2', 'max-md:pt-1']) expect(split(bar)).toContain(k); + const kids = Array.from(bar.children); + const group = screen.getByRole('group', { name: 'Panel width' }); + const hide = screen.getByRole('button', { name: 'Hide block panel' }); + const tabs = bar.querySelector('[data-world-panel-tabs]') as HTMLElement; + expect(tabs).not.toBeNull(); + expect(kids).toEqual([group, hide, tabs]); + for (const k of ['order-1', 'flex-1', 'min-w-0', 'md:order-3', 'md:basis-full', 'md:border-t']) expect(split(tabs)).toContain(k); + for (const k of ['md:order-1', 'md:flex-1', 'md:pl-2', 'md:py-1.5']) expect(split(group)).toContain(k); + expect(split(group)).not.toContain('md:px-2'); + for (const el of [bar, ...Array.from(bar.querySelectorAll('*'))]) expect(el.hasAttribute('style')).toBe(false); + }); +}); diff --git a/app/__tests__/components/world-panel.test.ts b/app/__tests__/components/world-panel.test.ts index c5e8a870..cdb998f7 100644 --- a/app/__tests__/components/world-panel.test.ts +++ b/app/__tests__/components/world-panel.test.ts @@ -2,6 +2,7 @@ * The block panel as a visitor meets it: an opaque panel on the site's tokens, a phone sheet that ends above the back * link and keeps a floor on a phone on its side, 44 px controls with the shared ring, and only what a visitor without a * wallet can read or use. Source is read here (no layout in jsdom); the browser probe measures the boxes. + * The frame's behaviour is pressed in world-panel-frame.test.tsx; this file pins how the view wires it. */ import fs from 'fs'; import path from 'path'; @@ -12,51 +13,23 @@ const between = (a: string, b: string) => { const i = PV.indexOf(a); const j = P const PICT = /\p{Extended_Pictographic}/u; const LIT = /#[0-9a-fA-F]{3,8}\b|rgba?\(/; describe('the block panel', () => { - it('the panel root is opaque, on tokens, and leaves the flow below md when hidden', () => { + it('the panel root is opaque and takes its classes from the frame', () => { const r = between('{/* ═══ Right Panel ═══ */}', '{/* Panel resize controls */}'); - for (const s of ['bp-dark', 'bg-bg-primary', '${PANEL_SHEET_BELOW_MD}', '${PANEL_EDGE_MD}', "'max-md:hidden'", - 'flex-shrink-0', 'ref={panelRef}', "inert={panelSize === 'hidden'}", 'data-world-panel']) { + for (const s of ['className={panelRootClass(panelSize)}', 'ref={panelRef}', "inert={panelSize === 'hidden'}", 'data-world-panel']) { expect(r).toContain(s); } expect(r).not.toContain('style='); expect(r).not.toMatch(LIT); }); - it("the sheet ends above the back link's row and keeps a floor on a phone on its side", () => { - const s = between("const PANEL_SHEET_BELOW_MD = '", "';"); - for (const c of ['max-md:absolute', 'max-md:inset-x-0', 'max-md:bottom-[calc(72px+env(safe-area-inset-bottom))]', - 'max-md:z-30', 'max-md:!w-full', 'max-md:h-[calc(45vh-72px)]', 'max-md:landscape:min-h-[min(224px,calc(100%-136px))]', - 'max-md:rounded-t-2xl', 'max-md:border-t', 'max-md:border-line-2']) { - expect(s).toContain(c); - } - for (const c of ['max-md:bottom-0', 'max-md:h-[45vh]', '100dvh']) expect(s).not.toContain(c); - const e = between("const PANEL_EDGE_MD = '", "';"); - expect(e).toMatch(/md:border-l[ ']/); - expect(e).toContain('md:border-line-2'); - }); - - it('the header has a 44 px hide button with the shared ring and named size buttons from md up', () => { - const h = between('{/* Panel resize controls */}', '{/* Tabs */}'); - for (const s of ['data-world-panel-head', 'aria-pressed={panelSize === s.size}', 'role="group" aria-label="Panel width"', 'title={s.name}', - 'title="Hide panel"', 'aria-label="Hide block panel"', 'ref={panelHideRef}', ' { + const h = between('{/* Panel resize controls */}', "{rightTab === 'properties' ? ("); + for (const s of [' { - const t = between('{/* Tabs */}', "{rightTab === 'properties' ? ("); - for (const s of ['border-b border-line-2', 'aria-pressed={rightTab === tab.key}', 'min-h-[44px]', 'border-text-1 text-text-1', - '${worldRing}']) { - expect(t).toContain(s); - } - expect(t).not.toContain('style='); - expect(t).not.toContain('#f7931a'); + expect(h).not.toContain(' { @@ -139,4 +112,21 @@ describe('the block panel', () => { expect(r).toContain('{label}'); expect(r).not.toContain("style={{ color: '#64748b' }}"); }); + + it("the properties tab's dim rows are on tokens and show no pictograph", () => { + for (const s of ['text-[10px] font-normal text-text-3">(child inscription)', 'GLOW', + 'tracking-wider mb-2 text-text-3">Height = BTC Value', 'justify-between text-[9px] text-text-3">Low', + '
', "${highlight ? 'text-bitcoin' : 'text-text-1'}", 'max-w-[60%]']) { + expect(PV).toContain(s); + } + for (const s of ["style={{ color: '#475569' }}>Height = BTC Value", "style={{ color: '#475569' }}>Low", + "style={{ color: '#475569' }}>(child inscription)", "style={{ color: '#64748b', fontSize: '11px' }}>GLOW", "maxWidth: '60%'", + "'\u{26CF} Coinbase'", '\u{1F3F0} ESTATE', '\u{26CF} Coinbase (glowing)', '\u{1F5B1} Drag to rotate']) { + expect(PV).not.toContain(s); + } + }); + + it("the view's root says a world view is open", () => { + expect(PV).toContain('
= { compact: 'w-80', quarter: 'w-96', third: 'w-[33vw]', half: 'w-[50vw]', hidden: 'w-0' }; -// Below md a side column would leave the treemap a sliver (QA 2026-10-22 #6), so -// the open panel becomes a bottom sheet over the scene instead, above the back link's row. Below md the hidden panel leaves the flow (max-md:hidden), so the scene column's min-w-0 holds at every width. -const PANEL_SHEET_BELOW_MD = 'max-md:absolute max-md:inset-x-0 max-md:bottom-[calc(72px+env(safe-area-inset-bottom))] max-md:z-30 max-md:!w-full max-md:h-[calc(45vh-72px)] max-md:landscape:min-h-[min(224px,calc(100%-136px))] max-md:rounded-t-2xl max-md:border-t max-md:border-line-2'; -const PANEL_EDGE_MD = 'md:border-l md:border-line-2'; const worldRing = 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent-cyan'; /* ─── Deterministic RNG ─── */ @@ -5771,7 +5766,7 @@ export default function ParcelView({ blockHeight, onBack, initialPanelHidden = f const fmtDim = (worldUnits: number) => metresOf(worldUnits); return ( -
+
{showWorldBuilder && (
{/* Panel resize controls */} -
-
- {([ - { size: 'compact' as PanelSize, label: 'S', name: 'Narrow' }, - { size: 'quarter' as PanelSize, label: 'M', name: 'Default' }, - { size: 'third' as PanelSize, label: 'L', name: 'One third' }, - { size: 'half' as PanelSize, label: 'XL', name: 'Half' }, - ]).map(s => ( - - ))} -
- -
- - {/* Tabs */} -
- {[ - { key: 'properties' as RightTab, label: 'PROPERTIES' }, - { key: 'chat' as RightTab, label: 'CHAT' }, - ...(gameElements.length > 0 ? [{ key: 'gaming' as RightTab, label: '🎮 GAMING' }] : []), - ].map(tab => ( - - ))} -
+ 0 ? [{ key: 'gaming' as RightTab, label: 'GAMING' }] : []), + ]} /> {rightTab === 'properties' ? (
@@ -6244,7 +6205,7 @@ export default function ParcelView({ blockHeight, onBack, initialPanelHidden = f
- Parcel (child inscription) + Parcel (child inscription)
parcels[i]?.heightMeters ?? 0)); return (
-
🏰 ESTATE
+
ESTATE
{estate.name}
@@ -6297,7 +6258,7 @@ export default function ParcelView({ blockHeight, onBack, initialPanelHidden = f
- GLOW + GLOW
{ownerLock !== 'connect' && ( @@ -6325,7 +6286,7 @@ export default function ParcelView({ blockHeight, onBack, initialPanelHidden = f )} - + @@ -6531,21 +6492,21 @@ export default function ParcelView({ blockHeight, onBack, initialPanelHidden = f )}
-
Height = BTC Value
+
Height = BTC Value
-
LowHigh
+
LowHigh
- ⛏ Coinbase (glowing) + Coinbase (glowing)
- Side = ⌈log10(output sats)⌉ − 5 (Bitmap) + Side = ⌈log10(output sats)⌉ − 5 (Bitmap)
-
- 🖱 Drag to rotate · Scroll to zoom · Click parcel to fly +
+ Drag to rotate · Scroll to zoom · Click parcel to fly
@@ -6839,7 +6800,7 @@ function PropRow({ label, value, highlight }: { label: string; value: React.Reac return (
{label} - {value} + {value}
); } \ No newline at end of file diff --git a/app/src/components/nexus/world/PanelBar.tsx b/app/src/components/nexus/world/PanelBar.tsx new file mode 100644 index 00000000..95434e42 --- /dev/null +++ b/app/src/components/nexus/world/PanelBar.tsx @@ -0,0 +1,56 @@ +'use client'; + +import type { Ref } from 'react'; +import { X } from 'lucide-react'; +import type { PanelSize, RightTab } from './panel-frame'; + +const ring = 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent-cyan'; + +const SIZES: { size: PanelSize; label: string; name: string }[] = [ + { size: 'compact', label: 'S', name: 'Narrow' }, + { size: 'quarter', label: 'M', name: 'Default' }, + { size: 'third', label: 'L', name: 'One third' }, + { size: 'half', label: 'XL', name: 'Half' }, +]; + +interface Props { + size: PanelSize; + onSize: (size: PanelSize) => void; + hideRef: Ref; + tabs: { key: RightTab; label: string }[]; + tab: RightTab; + onTab: (key: RightTab) => void; +} + +/** + * The block panel's top: the width buttons (from md up), the hide button and the tabs. From md up they sit in two rows + * as before (widths and hide, then the tabs); below md the width buttons are not shown and the hide button joins the tab + * row, so the sheet gives that row's height to the facts. + */ +export default function PanelBar({ size, onSize, hideRef, tabs, tab, onTab }: Props) { + return ( +
+
+ {SIZES.map(s => ( + + ))} +
+ +
+ {tabs.map(t => ( + + ))} +
+
+ ); +} diff --git a/app/src/components/nexus/world/panel-frame.ts b/app/src/components/nexus/world/panel-frame.ts new file mode 100644 index 00000000..111e3d82 --- /dev/null +++ b/app/src/components/nexus/world/panel-frame.ts @@ -0,0 +1,18 @@ +/** + * The block panel's frame: its widths, the bottom sheet it becomes below md, and its root's classes for each size. + * Plain strings, so a test reads what an open and a hidden panel get without a browser. + */ +export type RightTab = 'properties' | 'chat' | 'gaming'; +export type PanelSize = 'compact' | 'quarter' | 'third' | 'half' | 'hidden'; + +const PANEL_WIDTHS: Record = { compact: 'w-80', quarter: 'w-96', third: 'w-[33vw]', half: 'w-[50vw]', hidden: 'w-0' }; +// Below md a side column would leave the treemap a sliver (QA 2026-10-22 #6), so +// the open panel becomes a bottom sheet over the scene instead, above the back link's row. Below md the hidden panel leaves the flow (max-md:hidden), so the scene column's min-w-0 holds at every width. +const PANEL_SHEET_BELOW_MD = 'max-md:absolute max-md:inset-x-0 max-md:bottom-[calc(72px+env(safe-area-inset-bottom))] max-md:z-30 max-md:!w-full max-md:h-[calc(45vh-72px)] max-md:landscape:min-h-[min(224px,calc(100%-136px))] max-md:rounded-t-2xl max-md:border-t max-md:border-line-2'; +const PANEL_EDGE_MD = 'md:border-l md:border-line-2'; + +/** Open: the side column from md up, the sheet below it. Hidden: w-0 from md up, out of the flow below it. */ +export function panelRootClass(size: PanelSize): string { + const place = size !== 'hidden' ? `${PANEL_SHEET_BELOW_MD} ${PANEL_EDGE_MD}` : 'max-md:hidden'; + return `bp-dark bg-bg-primary ${PANEL_WIDTHS[size]} ${place} flex-shrink-0 flex flex-col transition-all duration-300 motion-reduce:transition-none overflow-hidden`; +} diff --git a/app/src/components/pwa/InstallPrompt.tsx b/app/src/components/pwa/InstallPrompt.tsx index cb2ca466..14daaf7b 100644 --- a/app/src/components/pwa/InstallPrompt.tsx +++ b/app/src/components/pwa/InstallPrompt.tsx @@ -71,7 +71,7 @@ export default function InstallPrompt() { if (!visible) return null; return ( -
+
{/* Accent bar */}