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/core/theme/themes.dart'; import 'package:jiu_client/models/product_option.dart'; import 'package:jiu_client/models/warehouse.dart'; import 'package:jiu_client/providers/warehouse_provider.dart'; import 'package:jiu_client/providers/product_option_provider.dart'; import 'package:jiu_client/screens/stock_in/stock_in_form_screen.dart'; class _FakeWarehouses extends WarehouseListNotifier { @override Future> build() async => const [Warehouse(id: 1, name: '主仓', isDefault: true)]; } class _FakeNames extends ProductNameListNotifier { @override Future> build() async => const [ ProductNameOption(id: 10, name: '茅台飞天', code: 'P001'), ProductNameOption(id: 11, name: '五粮液', code: 'P002'), ]; } class _FakeSeries extends ProductSeriesListNotifier { @override Future> build() async => const [ ProductSeriesOption(id: 20, name: '53度'), ]; } class _FakeSpecs extends ProductSpecListNotifier { @override Future> build() async => const [ ProductSpecOption(id: 30, name: '500ml'), ]; } void main() { TestWidgetsFlutterBinding.ensureInitialized(); SharedPreferences.setMockInitialValues({}); testWidgets('stock-in form: picking 商品名称 fills the cell', (tester) async { tester.view.physicalSize = const Size(1400, 1000); tester.view.devicePixelRatio = 1.0; addTearDown(tester.view.resetPhysicalSize); await tester.pumpWidget(ProviderScope( overrides: [ warehouseListProvider.overrideWith(() => _FakeWarehouses()), productNameListProvider.overrideWith(() => _FakeNames()), productSeriesListProvider.overrideWith(() => _FakeSeries()), productSpecListProvider.overrideWith(() => _FakeSpecs()), isReadonlyProvider.overrideWithValue(false), ], child: MaterialApp( theme: buildTheme('a'), home: const Scaffold(body: StockInFormScreen()), ), )); await tester.pump(); await tester.pump(const Duration(milliseconds: 100)); // Tap the 商品名称 cell to focus/open its popup. final nameCell = find.text('选择商品名称'); expect(nameCell, findsWidgets); await tester.tap(nameCell.first); await tester.pump(); await tester.pump(const Duration(milliseconds: 100)); // The option list should appear. expect(find.text('五粮液'), findsWidgets, reason: 'popup list should show options'); // Tap the option. await tester.tap(find.text('五粮液').last); await tester.pump(); await tester.pump(const Duration(milliseconds: 100)); // After picking, the cell should display 五粮液 and the hint should be gone. expect(find.text('五粮液'), findsOneWidget, reason: 'cell should show the picked name'); expect(find.text('选择商品名称'), findsNothing, reason: 'hint should be replaced by the picked name'); }); }