fix: navigation is more consistant
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:kooltab2/l10n/app_localizations.dart';
|
||||
import 'package:kooltab2/models/product.dart';
|
||||
import 'package:kooltab2/views/widgets/product_tile.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('long-pressing a product tile returns to the bar after edit', (
|
||||
tester,
|
||||
) async {
|
||||
final product = Product(
|
||||
id: 'product-1',
|
||||
name: 'Cola',
|
||||
category: 'Drinks',
|
||||
stockQuantity: 5,
|
||||
lowStockThreshold: 1,
|
||||
priceInCents: 250,
|
||||
);
|
||||
|
||||
final router = GoRouter(
|
||||
initialLocation: '/bar',
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/bar',
|
||||
builder: (context, state) => Scaffold(
|
||||
body: ProductTile(
|
||||
product: product,
|
||||
enabled: false,
|
||||
onTap: () {},
|
||||
onLongPress: () => context.push('/products/${product.id}/edit'),
|
||||
),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/products',
|
||||
builder: (context, state) => const Scaffold(body: Text('Products')),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: ':id/edit',
|
||||
builder: (context, state) =>
|
||||
const Scaffold(body: Text('Edit product')),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp.router(
|
||||
routerConfig: router,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.longPress(find.byType(ProductTile));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Edit product'), findsOneWidget);
|
||||
|
||||
router.pop();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(ProductTile), findsOneWidget);
|
||||
expect(find.text('Edit product'), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user