import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:jiu_client/core/auth/auth_state.dart'; import 'package:jiu_client/models/session.dart'; import 'package:jiu_client/models/shop.dart'; import 'package:jiu_client/providers/session_provider.dart'; import 'package:jiu_client/providers/shop_provider.dart'; import 'package:jiu_client/screens/devices/device_management_screen.dart'; import '../support/golden_harness.dart'; import '../support/shell_harness.dart'; /// design-distill 阶段4:设备管理 golden × 三主题(回归闸 + 保真基准)。 /// 桌面版挂进真 AppShell,数据照抄原型 screens/devices.html 的 /// SESSIONS(4 行会话)与 DEVICES(5 台外设 → 店级 custom_fields.peripherals): /// node tools/fidelity.mjs devices /// 更新基准:flutter test --update-goldens test/golden/device_management_golden_test.dart // 原型 SESSIONS 4 行(时间 MM-DD HH:mm) final _sessions = [ DeviceSession( id: 1, userId: 1, username: '王经理', realName: '王经理', platform: 'macos', platformClass: 'desktop', deviceName: 'macos', ip: '192.168.1.20', createdAt: DateTime(2026, 6, 20, 11, 23), lastSeenAt: DateTime(2026, 6, 22, 17, 40), online: true, isCurrent: true), DeviceSession( id: 2, userId: 1, username: '王经理', realName: '王经理', platform: 'windows', platformClass: 'desktop', deviceName: 'windows', ip: '192.168.1.21', createdAt: DateTime(2026, 6, 20, 10, 47), lastSeenAt: DateTime(2026, 6, 22, 17, 40), online: true, isCurrent: false), DeviceSession( id: 3, userId: 2, username: '李采购', realName: '李采购', platform: 'windows', platformClass: 'desktop', deviceName: 'windows', ip: '192.168.1.35', createdAt: DateTime(2026, 6, 20, 9, 13), lastSeenAt: DateTime(2026, 6, 22, 17, 11), online: false, isCurrent: false), DeviceSession( id: 4, userId: 3, username: '张前台', realName: '张前台', platform: 'ios', platformClass: 'mobile', deviceName: 'ios', ip: '10.0.0.8', createdAt: DateTime(2026, 6, 21, 17, 9), lastSeenAt: DateTime(2026, 6, 22, 16, 32), online: false, isCurrent: false), ]; // 原型 DEVICES 5 台外设(登记式存档) const _peripherals = [ { 'name': '前台标签打印机', 'kind': '标签打印机', 'status': '在线', 'model': 'Zebra GK888t', 'conn': 'USB', 'last': '2 分钟前' }, { 'name': '收银台小票机', 'kind': '小票打印机', 'status': '在线', 'model': '佳博 GP-58MB', 'conn': '蓝牙', 'last': '刚刚' }, { 'name': '入库扫码枪', 'kind': '扫码枪', 'status': '在线', 'model': 'Honeywell 1900', 'conn': 'USB', 'last': '5 分钟前' }, { 'name': '仓库电子秤', 'kind': '电子秤', 'status': '离线', 'model': '香山 ACS-30', 'conn': 'WiFi 192.168.1.66', 'last': '昨天 17:42' }, { 'name': '备用标签机', 'kind': '标签打印机', 'status': '离线', 'model': 'Brother QL-820', 'conn': '网络 192.168.1.51', 'last': '3 天前' }, ]; const _shopWithPeripherals = ShopInfo( id: 1, code: 'DSJH-001', name: '鼎晟酒行', address: '浙江省杭州市拱墅区运河路 168 号 1 幢', phone: '0571-8888 6666', managerName: '王经理', wechatId: 'dingsheng-wine', customFields: {'peripherals': _peripherals}, ); class _FakeSessionNotifier extends SessionListNotifier { @override Future> build() async => _sessions; @override Future reload() async {} } List _overrides() => [ sessionListProvider.overrideWith(() => _FakeSessionNotifier()), shopInfoProvider.overrideWith((ref) => _shopWithPeripherals), isReadonlyProvider.overrideWithValue(false), ]; void main() { TestWidgetsFlutterBinding.ensureInitialized(); SharedPreferences.setMockInitialValues({}); // 桌面:外壳挂载整框,与原型整页同构 shellGoldenAcrossThemes( 'devices 整框(桌面)', path: '/devices', screen: (_) => const DeviceManagementScreen(), goldenPrefix: 'device_management', overrides: _overrides, logical: const Size(1280, 900), ); // 移动:窄屏卡片流 goldenAcrossThemes( 'devices 整屏(移动)', goldenPrefix: 'device_management_mobile', child: () => const Scaffold(body: DeviceManagementScreen()), overrides: _overrides, logical: const Size(390, 1400), ); }