Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

5.6 KB
Raw Blame
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';

const readTextLf = (...args: Parameters<typeof readFileSync>): string =>
  String(readFileSync(...args)).replace(/\r\n/g, '\n');

/**
 * 宽屏任务列表抽屉的设计与行为门(与 sessionHeaderDesktopFirst 同款源码字符串门):
 * 此处锁住视觉与手势约定;订阅更新另由 sessionListDrawerUpdates.test.tsx 验证。
 */
describe('mobile session list drawer', () => {
  const source = () =>
    readTextLf(resolve(process.cwd(), 'src/session/SessionListDrawer.tsx'), 'utf8');

  it('keeps the drawer on design-system tokens with zero shadows and binary radii', () => {
    const text = source();
    // 零阴影 + 无硬编码色(dark 模式红线);圆角只允许 token(pill / container)。
    expect(text).not.toMatch(/shadow[A-Z]/);
    expect(text).not.toContain('elevation:');
    expect(text).not.toMatch(/#[0-9a-fA-F]{3,8}\b/);
    expect(text).not.toMatch(/borderRadius:\s*\d/);
    // 主题接入模式:模块级 makeStyles + useThemedStyles,不用静态色。
    expect(text).toContain('const makeStyles = (colors: ThemeColors) =>');
    expect(text).toContain('useThemedStyles(makeStyles)');
  });

  it('respects the reduce-motion convention (only animate when explicitly false)', () => {
    const text = source();
    expect(text).toContain("import { useReduceMotionEnabled } from '@/hooks/useReduceMotion';");
    expect(text).toContain('reduceMotion === false');
  });

  it('drives all motion through the shared motion tokens (no hardcoded durations)', () => {
    const text = source();
    // 动效全走 motionDuration/motionEasing 档位(review #1328):入场 enter+out、
    // 退场 exit+in、回弹 fast+move、spinner 走 spinnerCycle 语义例外档。
    expect(text).toContain('duration: motionDuration.enter');
    expect(text).toContain('duration: motionDuration.exit');
    expect(text).toContain('duration: motionDuration.fast');
    expect(text).toContain('Easing.bezier(...motionEasing.out)');
    expect(text).toContain('Easing.bezier(...motionEasing.in)');
    expect(text).toContain('Easing.bezier(...motionEasing.move)');
    expect(text).not.toMatch(/duration:\s*\d/);
  });

  it('closes on Android hardware back and folds drag offset into the timing animation', () => {
    const text = source();
    expect(text).toContain("BackHandler.addEventListener('hardwareBackPress', () => {");
    // 多处除以 panelWidth,宽度必须有正下限(除零保险,不寄托在调用方身上)。
    expect(text).toContain('Math.max(1, width + insets.left)');
    // 手势位移并回 progress:关闭动画从当前视觉位置继续,不跳帧。
    expect(text).toContain('progress.value + dragX.value / panelWidth');
    // A cancelled left swipe must animate the merged visual position back to
    // the fully open state, even if a render/layout update interrupts dragX.
    expect(text).toContain('const effective = Math.max(0, Math.min(1, progress.value + dragX.value / panelWidth));');
    expect(text).toContain('progress.value = withTiming(1, {');
    // 拖拽关闭只认「向左」意图:右拖 16pt 判失败,纵向 16pt 先到滚动优先(review #1328)。
    expect(text).toContain('.activeOffsetX(-16)');
    expect(text).toContain('.failOffsetX(16)');
    expect(text).toContain('.failOffsetY([-16, 16])');
    // 关闭动画期间 overlay 恒拦截,不放行点击穿透半透明 scrim(review #1328)。
    expect(text).toContain('pointerEvents="auto"');
    // 临时面板不再有重复主页底栏;左上角与常驻列一样是系统菜单,关闭走遮罩、左滑与系统返回。
    expect(text).not.toContain('sessionDrawer.home');
    expect(text).not.toContain('onDismiss');
    expect(text).toContain('newSessionInHeader={!persistent}');
  });

  it('uses the actual Home instead of maintaining a second list or data controller', () => {
    const text = source();
    const route = readTextLf(resolve(process.cwd(), 'app/devices/index.tsx'), 'utf8');
    const home = readTextLf(resolve(process.cwd(), 'src/session/HomeSurface.tsx'), 'utf8');
    expect(route).toContain("<MobileHome />");
    expect(route).toContain("@/session/HomeSurface");
    expect(text).toContain("import { MobileHome } from './HomeSurface'");
    expect(text).toContain('<MobileHome');
    expect(text).not.toMatch(/<SectionList|DrawerSessionRow|buildMobileHomePresentation|useRemoteSessions/);
    expect(home).toContain('<SectionList');
    expect(home).toContain('renderItem={renderHomeRow}');
    expect(home).toContain('onSelectSession(item)');
    expect(home).toContain('!embedded && usesNativeStackHeader()');
  });

  it('exposes stable testIDs and modal accessibility semantics', () => {
    const text = source();
    for (const testId of [
      'sessionDrawer.overlay',
      'sessionDrawer.scrim',
      'sessionDrawer.panel',
    ]) {
      expect(text).toContain(`testID="${testId}"`);
    }
    expect(text).toContain('accessibilityViewIsModal={mounted && !persistent}');
    expect(text).toContain('if (!open || persistent) return;');
    expect(text).toContain("t('home.drawer.closeA11y')");
    // 打开时把读屏焦点移到面板首控件;关闭后的背景焦点归还由父级在解除
    // accessibility 隔离后的 commit effect 负责。
    expect(text).toContain('AccessibilityInfo.setAccessibilityFocus(node)');
    expect(text).toContain('ref={homeContentRef}');
    // 导航动作必须等 overlay 的 mounted=false commit 后执行,不能与 Android 原生换屏同帧。
    expect(text).toContain('onClosedRef.current?.();');
    expect(text).not.toContain('returnFocusRef');
  });
});