303 lines
8.7 KiB
Dart
303 lines
8.7 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:mobile_eda/presentation/widgets/toolbar_widget.dart';
|
|
import 'package:mobile_eda/presentation/widgets/property_panel_widget.dart';
|
|
import 'package:mobile_eda/presentation/widgets/component_library_panel.dart';
|
|
|
|
void main() {
|
|
group('Toolbar Widget Integration Tests', () {
|
|
testWidgets('ToolbarWidget should display all buttons', (WidgetTester tester) async {
|
|
var undoCalled = false;
|
|
var redoCalled = false;
|
|
var saveCalled = false;
|
|
|
|
await tester.pumpWidget(
|
|
const ProviderScope(
|
|
child: MaterialApp(
|
|
home: Scaffold(
|
|
body: ToolbarWidget(
|
|
showTopToolbar: true,
|
|
showBottomToolbar: true,
|
|
onUndo: null,
|
|
onRedo: null,
|
|
onSave: null,
|
|
onSettings: null,
|
|
onComponentLibrary: null,
|
|
onWireMode: null,
|
|
onSelectMode: null,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
// 验证工具栏显示
|
|
expect(find.byType(ToolbarWidget), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('ToolbarWidget callbacks should be invoked', (WidgetTester tester) async {
|
|
var undoCalled = false;
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
home: Scaffold(
|
|
body: ToolbarWidget(
|
|
showTopToolbar: true,
|
|
showBottomToolbar: true,
|
|
onUndo: () => undoCalled = true,
|
|
onRedo: () {},
|
|
onSave: () {},
|
|
onSettings: () {},
|
|
onComponentLibrary: () {},
|
|
onWireMode: () {},
|
|
onSelectMode: () {},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
// 找到撤销按钮并点击
|
|
final undoButton = find.byIcon(Icons.undo);
|
|
if (undoButton.evaluate().isNotEmpty) {
|
|
await tester.tap(undoButton);
|
|
await tester.pump();
|
|
expect(undoCalled, true);
|
|
}
|
|
});
|
|
});
|
|
|
|
group('Property Panel Integration Tests', () {
|
|
testWidgets('PropertyPanelWidget should display property fields', (WidgetTester tester) async {
|
|
final propertyData = PropertyData(
|
|
refDesignator: 'R1',
|
|
value: '10k',
|
|
footprint: '0805',
|
|
componentType: ComponentType.resistor,
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: PropertyPanelWidget(
|
|
propertyData: propertyData,
|
|
onPropertyChanged: (data) {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
// 验证属性字段显示
|
|
expect(find.byType(PropertyPanelWidget), findsOneWidget);
|
|
expect(find.text('R1'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('PropertyPanelWidget should validate ref designator', (WidgetTester tester) async {
|
|
final propertyData = PropertyData(
|
|
componentType: ComponentType.resistor,
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: PropertyPanelWidget(
|
|
propertyData: propertyData,
|
|
onPropertyChanged: (data) {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
// 输入无效位号
|
|
final refField = find.byType(TextFormField).first;
|
|
await tester.enterText(refField, 'invalid');
|
|
await tester.pump();
|
|
|
|
// 验证错误提示(如果有实现)
|
|
// expect(find.text('位号格式错误'), findsOneWidget);
|
|
});
|
|
});
|
|
|
|
group('Component Library Integration Tests', () {
|
|
testWidgets('ComponentLibraryPanel should display components', (WidgetTester tester) async {
|
|
final mockComponents = [
|
|
ComponentLibraryItem(
|
|
name: 'Resistor',
|
|
category: 'passive',
|
|
footprint: '0805',
|
|
),
|
|
ComponentLibraryItem(
|
|
name: 'Capacitor',
|
|
category: 'passive',
|
|
footprint: '0603',
|
|
),
|
|
];
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: ComponentLibraryPanel(
|
|
initialViewMode: LibraryViewMode.list,
|
|
components: mockComponents,
|
|
onComponentSelected: (item) {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
// 验证元件列表显示
|
|
expect(find.byType(ComponentLibraryPanel), findsOneWidget);
|
|
expect(find.text('Resistor'), findsOneWidget);
|
|
expect(find.text('Capacitor'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('ComponentLibraryPanel should filter by search', (WidgetTester tester) async {
|
|
final mockComponents = [
|
|
ComponentLibraryItem(
|
|
name: 'Resistor',
|
|
category: 'passive',
|
|
footprint: '0805',
|
|
),
|
|
ComponentLibraryItem(
|
|
name: 'Capacitor',
|
|
category: 'passive',
|
|
footprint: '0603',
|
|
),
|
|
];
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: ComponentLibraryPanel(
|
|
initialViewMode: LibraryViewMode.list,
|
|
components: mockComponents,
|
|
onComponentSelected: (item) {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
// 输入搜索内容
|
|
final searchField = find.byType(TextField).first;
|
|
await tester.enterText(searchField, 'Resistor');
|
|
await tester.pumpAndSettle();
|
|
|
|
// 验证搜索结果
|
|
expect(find.text('Resistor'), findsOneWidget);
|
|
// Capacitor 应该被过滤掉
|
|
// expect(find.text('Capacitor'), findsNothing);
|
|
});
|
|
|
|
testWidgets('ComponentLibraryPanel should switch view modes', (WidgetTester tester) async {
|
|
final mockComponents = [
|
|
ComponentLibraryItem(
|
|
name: 'Resistor',
|
|
category: 'passive',
|
|
footprint: '0805',
|
|
),
|
|
];
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: ComponentLibraryPanel(
|
|
initialViewMode: LibraryViewMode.list,
|
|
components: mockComponents,
|
|
onComponentSelected: (item) {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
// 验证列表视图
|
|
expect(find.byType(ListTile), findsWidgets);
|
|
|
|
// 切换到网格视图
|
|
final viewModeButton = find.byIcon(Icons.grid_view);
|
|
if (viewModeButton.evaluate().isNotEmpty) {
|
|
await tester.tap(viewModeButton);
|
|
await tester.pumpAndSettle();
|
|
|
|
// 验证网格视图
|
|
expect(find.byType(GridTile), findsWidgets);
|
|
}
|
|
});
|
|
});
|
|
|
|
group('End-to-End Workflow Tests', () {
|
|
testWidgets('Complete component placement workflow', (WidgetTester tester) async {
|
|
SchematicComponent? placedComponent;
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
child: MaterialApp(
|
|
home: Scaffold(
|
|
body: Column(
|
|
children: [
|
|
ToolbarWidget(
|
|
showTopToolbar: true,
|
|
showBottomToolbar: true,
|
|
onUndo: () {},
|
|
onRedo: () {},
|
|
onSave: () {},
|
|
onSettings: () {},
|
|
onComponentLibrary: () {},
|
|
onWireMode: () {},
|
|
onSelectMode: () {},
|
|
),
|
|
Expanded(
|
|
child: ComponentLibraryPanel(
|
|
initialViewMode: LibraryViewMode.list,
|
|
components: [
|
|
ComponentLibraryItem(
|
|
name: 'Resistor',
|
|
category: 'passive',
|
|
footprint: '0805',
|
|
),
|
|
],
|
|
onComponentSelected: (item) {
|
|
placedComponent = SchematicComponent(
|
|
ref: 'R1',
|
|
value: '10k',
|
|
footprint: '0805',
|
|
componentType: ComponentType.resistor,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
// 模拟元件选择
|
|
final resistorItem = find.text('Resistor');
|
|
await tester.tap(resistorItem);
|
|
await tester.pump();
|
|
|
|
// 验证元件被选择
|
|
expect(placedComponent, isNotNull);
|
|
expect(placedComponent!.ref, 'R1');
|
|
});
|
|
});
|
|
}
|
|
|
|
/// 模拟的原理图元件类(用于测试)
|
|
class SchematicComponent {
|
|
final String ref;
|
|
final String value;
|
|
final String footprint;
|
|
final ComponentType componentType;
|
|
|
|
SchematicComponent({
|
|
required this.ref,
|
|
required this.value,
|
|
required this.footprint,
|
|
required this.componentType,
|
|
});
|
|
}
|