forked from eatvio/eatvio_app
syn with upstream (#985)
Co-authored-by: misha <mikhail_zakharov_15482356@mail.ru> Co-authored-by: misha <misha@noreply.localhost> Reviewed-on: eatvio/eatvio_app#985
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/widgets/bottom_nav_scope.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('BottomNavController', () {
|
||||
test('switchToRoute is a no-op until a callback is registered', () {
|
||||
final controller = BottomNavController();
|
||||
// Should not throw
|
||||
controller.switchToRoute('/home');
|
||||
controller.switchToRoute('/home', 'extra');
|
||||
});
|
||||
|
||||
test('switchToRoute forwards path and extra to registered callback', () {
|
||||
final controller = BottomNavController();
|
||||
String? receivedPath;
|
||||
Object? receivedExtra;
|
||||
controller.register((path, extra) {
|
||||
receivedPath = path;
|
||||
receivedExtra = extra;
|
||||
});
|
||||
|
||||
controller.switchToRoute('/feed', {'tab': 'recipes'});
|
||||
|
||||
expect(receivedPath, '/feed');
|
||||
expect(receivedExtra, {'tab': 'recipes'});
|
||||
});
|
||||
|
||||
test('switchToRoute passes null extra by default', () {
|
||||
final controller = BottomNavController();
|
||||
Object? receivedExtra = 'sentinel';
|
||||
controller.register((path, extra) {
|
||||
receivedExtra = extra;
|
||||
});
|
||||
|
||||
controller.switchToRoute('/profile');
|
||||
|
||||
expect(receivedExtra, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('BottomNavScope', () {
|
||||
testWidgets('maybeOf returns null when scope is not present', (tester) async {
|
||||
late BottomNavController? captured;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (ctx) {
|
||||
captured = BottomNavScope.maybeOf(ctx);
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(captured, isNull);
|
||||
});
|
||||
|
||||
testWidgets('of returns controller from ancestor scope', (tester) async {
|
||||
final controller = BottomNavController();
|
||||
late BottomNavController captured;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: BottomNavScope(
|
||||
controller: controller,
|
||||
child: Builder(
|
||||
builder: (ctx) {
|
||||
captured = BottomNavScope.of(ctx);
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(identical(captured, controller), isTrue);
|
||||
});
|
||||
|
||||
testWidgets('updateShouldNotify returns true when controller changes', (tester) async {
|
||||
final c1 = BottomNavController();
|
||||
final c2 = BottomNavController();
|
||||
const child = SizedBox.shrink();
|
||||
final widget1 = BottomNavScope(controller: c1, child: child);
|
||||
final widget2 = BottomNavScope(controller: c2, child: child);
|
||||
|
||||
expect(widget2.updateShouldNotify(widget1), isTrue);
|
||||
|
||||
final widget3 = BottomNavScope(controller: c1, child: child);
|
||||
expect(widget3.updateShouldNotify(widget1), isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user