update
This commit is contained in:
85
CLAUDE.md
85
CLAUDE.md
@@ -1926,94 +1926,9 @@ void main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Widget Tests
|
||||
```dart
|
||||
void main() {
|
||||
testWidgets('ProductCard displays product info', (tester) async {
|
||||
final product = Product(
|
||||
id: '1',
|
||||
name: 'Test Product',
|
||||
price: 100,
|
||||
images: ['https://example.com/image.jpg'],
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ProductCard(product: product),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Test Product'), findsOneWidget);
|
||||
expect(find.text('100,000 ₫'), findsOneWidget);
|
||||
expect(find.byType(CachedNetworkImage), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('OTPInputField auto-focuses next field', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: OTPInputField(onCompleted: (otp) {}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Enter first digit
|
||||
await tester.enterText(find.byType(TextField).first, '1');
|
||||
await tester.pump();
|
||||
|
||||
// Verify focus moved to second field
|
||||
expect(
|
||||
tester.widget<TextField>(find.byType(TextField).at(1)).focusNode?.hasFocus,
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
### Integration Tests
|
||||
```dart
|
||||
void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
testWidgets('Complete checkout flow', (tester) async {
|
||||
app.main();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Navigate to products
|
||||
await tester.tap(find.byIcon(Icons.shopping_bag));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Add product to cart
|
||||
await tester.tap(find.byType(ProductCard).first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Add to Cart'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Go to cart
|
||||
await tester.tap(find.byIcon(Icons.shopping_cart));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Proceed to checkout
|
||||
await tester.tap(find.text('Checkout'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Fill delivery info
|
||||
await tester.enterText(find.byKey(Key('recipient_name')), 'John Doe');
|
||||
await tester.enterText(find.byKey(Key('phone')), '0912345678');
|
||||
await tester.enterText(find.byKey(Key('address')), '123 Main St');
|
||||
|
||||
// Select payment method
|
||||
await tester.tap(find.text('Cash on Delivery'));
|
||||
|
||||
// Place order
|
||||
await tester.tap(find.text('Place Order'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify success
|
||||
expect(find.text('Order Successful'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user