Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/__tests__/components/install-card.test.ts
Original file line number Diff line number Diff line change
@@ -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(
'<div data-install-card className="fixed bottom-20 left-4 right-4 z-50 mx-auto max-w-md md:bottom-6 md:left-auto md:right-6">',
);
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');
});
});
5 changes: 1 addition & 4 deletions app/__tests__/components/world-corners.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;',
Expand Down Expand Up @@ -158,8 +157,6 @@ describe('the corners of the world view', () => {
expect(PV).toContain(
"{viewMode !== 'standard' && scene === 'ok' && <div className=\"flex-1 min-w-0 relative\" data-world-scene>",
);
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');
});
});
127 changes: 127 additions & 0 deletions app/__tests__/components/world-panel-frame.test.tsx
Original file line number Diff line number Diff line change
@@ -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<PanelSize>(initial);
const [tab, setTab] = React.useState<RightTab>('properties');
const hide = React.useRef<HTMLButtonElement>(null);
return (
<div data-testid="root" data-size={size} className={panelRootClass(size)}>
<PanelBar size={size} onSize={setSize} hideRef={hide} tabs={TABS} tab={tab} onTab={setTab} />
</div>
);
}
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<string, string> = { 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(<Panel initial="quarter" />);
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(<Panel initial="quarter" />);
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<HTMLButtonElement>();
render(<PanelBar size="quarter" onSize={noop} hideRef={ref} tabs={TABS} tab="properties" onTab={noop} />);
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(<Panel initial="quarter" />);
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);
});
});
62 changes: 26 additions & 36 deletions app/__tests__/components/world-panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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}', '<X size={18}']) {
it("the panel's top comes from the frame", () => {
const h = between('{/* Panel resize controls */}', "{rightTab === 'properties' ? (");
for (const s of ['<PanelBar', 'size={panelSize}', 'onSize={setPanelSize}', 'hideRef={panelHideRef}', 'tab={rightTab}',
'onTab={setRightTab}', "label: 'PROPERTIES'", "label: 'CHAT'", "label: 'GAMING'"]) {
expect(h).toContain(s);
}
expect(h).toMatch(/className="[^"]*\bhidden\b[^"]*\bmd:flex\b[^"]*"/);
expect(h).not.toContain('aria-label={`Panel width');
expect(h.split('min-h-[44px] min-w-[44px]').length).toBe(3);
expect(h.split('${worldRing}').length).toBe(3);
for (const s of ['style=', 'min-h-[36px]', 'w-6 h-6', 'w-7 h-7', '▶', '▐', '◧']) expect(h).not.toContain(s);
expect(h).not.toMatch(LIT);
});

it('the tabs are on tokens, 44 px, with a pressed state', () => {
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('<button');
expect(h).not.toMatch(PICT);
});

it('the owner row claims no check, and the fact rows print only what is known', () => {
Expand Down Expand Up @@ -139,4 +112,21 @@ describe('the block panel', () => {
expect(r).toContain('<span className="text-xs text-text-3">{label}</span>');
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)', '<span className="text-[11px] text-text-3">GLOW</span>',
'tracking-wider mb-2 text-text-3">Height = BTC Value', 'justify-between text-[9px] text-text-3"><span>Low</span>',
'<div className="mt-3 text-[9px] text-text-3">', "${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' }}><span>Low</span>",
"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('<div ref={containerRef} data-world-view className="relative w-full h-full flex"');
});
});
5 changes: 5 additions & 0 deletions app/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ html {
}
}

/* The site's install card stays off an open world view: the view's root says it is there (bg98b3c). */
body:has([data-world-view]) [data-install-card] {
display: none;
}

/* Haptic-style active state for buttons */
@media (hover: none) and (pointer: coarse) {
button, a, [role="button"] {
Expand Down
Loading
Loading