-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: introduce test that can route our pages
- Loading branch information
Showing
7 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
@RoutePage() | ||
class SailTestPage extends StatelessWidget { | ||
final Widget child; | ||
const SailTestPage({super.key, required this.child}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return child; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// all routes should be exported from this file! | ||
|
||
export 'package:sidesail/pages/home_page.dart'; | ||
export 'package:sidesail/pages/test_page.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:sidesail/storage/client_settings.dart'; | ||
|
||
class MockStore implements KeyValueStore { | ||
final _db = {}; | ||
|
||
@override | ||
Future<String?> getString(String key) async => _db[key]; | ||
|
||
@override | ||
Future<void> setString(String key, String value) async { | ||
_db[key] = value; | ||
} | ||
|
||
@override | ||
Future<void> delete(String key) async { | ||
_db[key] = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:sidesail/app.dart'; | ||
import 'package:sidesail/routing/router.dart'; | ||
import 'package:sidesail/storage/client_settings.dart'; | ||
|
||
import 'mocks/storage_mock.dart'; | ||
|
||
Future<void> _setDeviceSize() async { | ||
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); | ||
await binding.setSurfaceSize(const Size(1200, 720)); | ||
} | ||
|
||
Future<void> loadFonts() async { | ||
final sourceCodePro = rootBundle.load('fonts/SourceCodePro-Regular.ttf'); | ||
final fontLoader = FontLoader('SourceCodePro')..addFont(sourceCodePro); | ||
await fontLoader.load(); | ||
} | ||
|
||
extension TestExtension on WidgetTester { | ||
Future<void> pumpSailPage( | ||
Widget child, { | ||
bool requireIntensionKyc = false, | ||
bool requireKycLevel2 = false, | ||
}) async { | ||
await _setDeviceSize(); | ||
await loadFonts(); | ||
await registerTestDependencies(); | ||
|
||
await pumpWidget( | ||
SailApp( | ||
builder: (context, router) { | ||
final appRouter = GetIt.I.get<AppRouter>(); | ||
|
||
return MaterialApp.router( | ||
routerDelegate: appRouter.delegate( | ||
initialRoutes: [SailTestRoute(child: child)], | ||
), | ||
routeInformationParser: appRouter.defaultRouteParser(), | ||
title: 'SideSail', | ||
theme: ThemeData( | ||
fontFamily: 'SourceCodePro', | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
await pumpAndSettle(); | ||
} | ||
} | ||
|
||
Future<void> registerTestDependencies() async { | ||
if (!GetIt.I.isRegistered<AppRouter>()) { | ||
GetIt.I.registerLazySingleton<AppRouter>( | ||
() => AppRouter(), | ||
); | ||
} | ||
|
||
if (!GetIt.I.isRegistered<ClientSettings>()) { | ||
GetIt.I.registerLazySingleton<ClientSettings>( | ||
() => ClientSettings(store: MockStore()), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters