Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
✅ fixed failing tests
  • Loading branch information
sarbagyastha committed Dec 26, 2022
commit 1fb3d2c45ea07f0249eaec43bff227ddd826e202
6 changes: 3 additions & 3 deletions packages/clean_framework/example/lib/demo_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class DemoRouter extends AppRouter<Routes> {
],
),
],
errorBuilder: (context, state) => _Page404(error: state.error),
errorBuilder: (context, state) => Page404(error: state.error),
);
}
}

class _Page404 extends StatelessWidget {
const _Page404({required this.error});
class Page404 extends StatelessWidget {
const Page404({required this.error});

final Exception? error;

Expand Down
1 change: 0 additions & 1 deletion packages/clean_framework/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:clean_framework/clean_framework.dart';
import 'package:clean_framework_example/asset_feature_provider.dart';
import 'package:clean_framework_example/demo_router.dart';
import 'package:clean_framework_example/providers.dart';
import 'package:clean_framework_example/routes.dart';
import 'package:clean_framework_router/clean_framework_router.dart';
import 'package:flutter/material.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:clean_framework/clean_framework.dart';
import 'package:clean_framework_example/demo_router.dart';
import 'package:clean_framework_example/features/country/presentation/country_ui.dart';
import 'package:clean_framework_example/providers.dart';
import 'package:clean_framework_example/routes.dart';
Expand All @@ -12,6 +13,8 @@ import '../../../home_page_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

final router = DemoRouter();

setupUITest(context: providersContext, router: router);

final gateway = countryGatewayProvider.getGateway(providersContext);
Expand Down Expand Up @@ -98,7 +101,7 @@ void main() {
child: child,
),
verify: (tester) async {
router.to(Routes.countries);
router.go(Routes.countries);
await tester.pumpAndSettle();

final listTileFinder = find.byType(ListTile);
Expand Down
18 changes: 9 additions & 9 deletions packages/clean_framework/example/test/home_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import 'package:clean_framework/clean_framework.dart';
import 'package:clean_framework/clean_framework_defaults.dart';
import 'package:clean_framework_example/demo_router.dart';
import 'package:clean_framework_example/features/country/presentation/country_ui.dart';
import 'package:clean_framework_example/features/last_login/presentation/last_login_ui.dart';
import 'package:clean_framework_example/features/random_cat/presentation/random_cat_ui.dart';
import 'package:clean_framework_example/home_page.dart';
import 'package:clean_framework_example/providers.dart';
import 'package:clean_framework_example/routes.dart';
import 'package:clean_framework_router/clean_framework_router.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
tearDown(() {
router.reset();
});

group('HomePage tests | ', () {
testWidgets(
'correct UI',
Expand Down Expand Up @@ -113,10 +110,13 @@ Widget buildWidget(Widget widget) {
child: AppProvidersContainer(
providersContext: providersContext,
onBuild: (_, __) {},
child: MaterialApp.router(
routeInformationParser: router.informationParser,
routerDelegate: router.delegate,
routeInformationProvider: router.informationProvider,
child: AppRouterScope(
create: () => DemoRouter(),
builder: (context) {
return MaterialApp.router(
routerConfig: context.router.config,
);
},
),
),
);
Expand Down
8 changes: 6 additions & 2 deletions packages/clean_framework/example/test/routes_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:clean_framework_example/demo_router.dart';
import 'package:clean_framework_example/home_page.dart';
import 'package:clean_framework_example/routes.dart';
import 'package:clean_framework_router/clean_framework_router.dart';
import 'package:flutter_test/flutter_test.dart';

import 'home_page_test.dart';
Expand All @@ -10,7 +11,10 @@ void main() {
(tester) async {
await tester.pumpWidget(buildWidget(HomePage()));

router.open('/non-existent');
final router =
AppRouterScope.of(tester.element(find.byType(HomePage))).router;

router.goLocation('/non-existent');
await tester.pumpAndSettle();

expect(find.byType(Page404), findsOneWidget);
Expand Down
15 changes: 10 additions & 5 deletions packages/clean_framework_router/lib/src/app_router_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ abstract class AppRouterBase<R extends Enum> {
RouterConfiguration configureRouter();

/// Navigates to the given [route] without respecting previous routes.
/// i.e. navigation stack is not maintained and previous routes might be cleared based on the composition of new [route].
/// i.e. navigation stack is not maintained and previous routes
/// might be cleared based on the composition of new [route].
void go(
R route, {
RouterParams params = const {},
RouterParams queryParams = const {},
Object? extra,
});

/// Navigates to the given [route] by pushing it at the top of the previous route.
/// Navigates to the given [route]
/// by pushing it at the top of the previous route.
/// i.e navigation stack is maintained and previous routes are preserved.
void push(
R route, {
Expand All @@ -39,7 +41,8 @@ abstract class AppRouterBase<R extends Enum> {
Object? extra,
});

/// Navigates to the given [location] by pushing it at the top of the previous route.
/// Navigates to the given [location]
/// by pushing it at the top of the previous route.
void pushLocation(
String location, {
Object? extra,
Expand All @@ -55,7 +58,8 @@ abstract class AppRouterBase<R extends Enum> {
/// Navigates the page back to the previous route if available.
void pop();

/// Constructs the full location of the given [route] with [params] and [queryParams].
/// Constructs the full location of the given [route]
/// with [params] and [queryParams].
String locationOf(
R route, {
RouterParams params = const {},
Expand All @@ -64,7 +68,8 @@ abstract class AppRouterBase<R extends Enum> {

/// Register a closure to be called when the navigation stack changes.
///
/// Adding a listener will provide a function which can be called off to remove the added listener.
/// Adding a listener will provide a function
/// which can be called off to remove the added listener.
///
/// ```dart
/// final removeListener = router.addListener(
Expand Down
13 changes: 9 additions & 4 deletions packages/clean_framework_test/lib/src/test_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,15 @@ void uiTest(
Widget child;
if (wrapWithMaterialApp) {
if (builder == null) {
child = MaterialApp.router(
routerConfig: resolvedRouter!.config,
localizationsDelegates: localizationDelegates,
builder: (context, child) => scopedChild(child!),
child = AppRouterScope(
create: () => resolvedRouter!,
builder: (context) {
return MaterialApp.router(
routerConfig: context.router.config,
localizationsDelegates: localizationDelegates,
builder: (context, child) => scopedChild(child!),
);
},
);
} else {
child = MaterialApp(
Expand Down