beadboard/tests/hooks/use-responsive.test.ts
zenchantlive ce8fdd0d4c feat(ui): complete shell layout components (bb-ui2.6, .7, .8, .9, .27)
STORY:
Phase 1 of the Unified UX epic required a complete 3-panel shell layout
with responsive behavior across mobile, tablet, and desktop breakpoints.
The existing page structure was fragmented - we needed a cohesive shell.

COLLABORATION:
Three agents (bb-5am, bb-dwz, bb-3dv) worked in parallel on:
- TopBar: View tabs (Social/Graph/Swarm) with active states, filter input
- LeftPanel: Channel tree navigation with epic filtering, responsive collapse
- RightPanel: Detail strip with sidebar (desktop) / drawer (tablet/mobile) modes

We encountered a hydration mismatch error on mobile/tablet because
useResponsive was returning different values on server vs client.
Fixed by defaulting to desktop on server and only updating after mount.

Mobile navigation (bb-ui2.27) added:
- Hamburger menu for left panel access on mobile/tablet
- Bottom tab bar for thumb-friendly view switching

DELIVERABLES:
- src/components/shared/top-bar.tsx: TopBar with view tabs + hamburger
- src/components/shared/left-panel.tsx: Epic tree with expand/collapse
- src/components/shared/right-panel.tsx: Responsive sidebar/drawer
- src/components/shared/unified-shell.tsx: Main 3-panel grid layout
- src/components/shared/mobile-nav.tsx: Bottom tab bar for mobile
- src/hooks/use-responsive.ts: Breakpoint detection (mobile/tablet/desktop)
- Tests for all components

VERIFICATION:
- npm run typecheck: PASS
- npm run lint: PASS
- npm run test: PASS

CLOSES: bb-ui2.6, bb-ui2.7, bb-ui2.8, bb-ui2.9, bb-ui2.27
2026-02-15 23:19:52 -08:00

87 lines
2.6 KiB
TypeScript

import { describe, it, beforeEach, afterEach } from 'node:test';
import assert from 'node:assert';
describe('useResponsive Hook', () => {
const originalInnerWidth = global.innerWidth;
beforeEach(() => {
Object.defineProperty(window, 'innerWidth', {
writable: true,
configurable: true,
value: 1024,
});
});
afterEach(() => {
Object.defineProperty(window, 'innerWidth', {
writable: true,
configurable: true,
value: originalInnerWidth,
});
});
describe('module import', () => {
it('should load the module without error', async () => {
try {
await import('../../src/hooks/use-responsive');
assert.ok(true, 'Module loaded');
} catch (err) {
assert.fail(err as Error);
}
});
});
describe('ResponsiveState interface', () => {
it('exports useResponsive hook', async () => {
const mod = await import('../../src/hooks/use-responsive');
assert.ok(mod.useResponsive, 'useResponsive should be exported');
assert.equal(typeof mod.useResponsive, 'function', 'useResponsive should be a function');
});
it('exports ResponsiveState type via type export', async () => {
const mod = await import('../../src/hooks/use-responsive');
assert.ok(mod.useResponsive, 'useResponsive hook should be exported');
});
});
describe('breakpoint detection', () => {
it('detects mobile breakpoint (<768px)', async () => {
Object.defineProperty(window, 'innerWidth', {
writable: true,
configurable: true,
value: 390,
});
const mod = await import('../../src/hooks/use-responsive');
const { useResponsive } = mod;
assert.ok(typeof useResponsive === 'function', 'useResponsive is a function');
});
it('detects tablet breakpoint (768-1024px)', async () => {
Object.defineProperty(window, 'innerWidth', {
writable: true,
configurable: true,
value: 768,
});
const mod = await import('../../src/hooks/use-responsive');
const { useResponsive } = mod;
assert.ok(typeof useResponsive === 'function', 'useResponsive is a function');
});
it('detects desktop breakpoint (>=1024px)', async () => {
Object.defineProperty(window, 'innerWidth', {
writable: true,
configurable: true,
value: 1440,
});
const mod = await import('../../src/hooks/use-responsive');
const { useResponsive } = mod;
assert.ok(typeof useResponsive === 'function', 'useResponsive is a function');
});
});
});