diff --git a/package.json b/package.json index db56932..e1d6973 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "lint:dart": "flutter analyze --no-pub && dart run custom_lint", "lint:ts": "tsc && eslint scripts", "lint": "npm run lint:shell && npm run lint:dart && npm run lint:ts", - "test": "flutter test --no-pub", + "test": "flutter test --no-pub -r expanded --platform chrome", "build:auto": "flutter build web --no-pub --release --no-web-resources-cdn --web-renderer auto", "build:wasm": "flutter build web --no-pub --release --no-web-resources-cdn --wasm", "build": "npm run build:${BUILD_RENDERER:-wasm}", diff --git a/test/better_link_test.dart b/test/better_link_test.dart index 75f28d9..3361838 100644 --- a/test/better_link_test.dart +++ b/test/better_link_test.dart @@ -2,34 +2,32 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:portfolio/widgets/better_link.dart'; void main() { - group('Application routes are properly identified:', () { - test('localhost is not detected as a route', () { - final uri = Uri.parse('localhost:8080/research'); - expect(BetterLink.isRoute(uri), false); - }); + test('localhost is not detected as a route', () { + final uri = Uri.parse('localhost:8080/research'); + expect(BetterLink.isRoute(uri), false); + }); - test('full url is not detected as a route', () { - final uri = Uri.https('flutter.dev'); - expect(BetterLink.isRoute(uri), false); - }); + test('full url is not detected as a route', () { + final uri = Uri.https('flutter.dev'); + expect(BetterLink.isRoute(uri), false); + }); - test('full url with path is not detected as a route', () { - final uri = Uri.https('flutter.dev', 'cookbook'); - expect(BetterLink.isRoute(uri), false); - }); + test('full url with path is not detected as a route', () { + final uri = Uri.https('flutter.dev', 'cookbook'); + expect(BetterLink.isRoute(uri), false); + }); - test('route is detected as a route', () { - final uri = Uri.parse('/projects'); - final rootUri = Uri.parse('/'); - expect(BetterLink.isRoute(uri), true); - expect(BetterLink.isRoute(rootUri), true); - }); + test('route is detected as a route', () { + final uri = Uri.parse('/projects'); + final rootUri = Uri.parse('/'); + expect(BetterLink.isRoute(uri), true); + expect(BetterLink.isRoute(rootUri), true); + }); - test('route with query parameters is detected as a route', () { - final uri = Uri.parse('/projects?lang=es'); - final rootUri = Uri.parse('/?lang=es'); - expect(BetterLink.isRoute(uri), true); - expect(BetterLink.isRoute(rootUri), true); - }); + test('route with query parameters is detected as a route', () { + final uri = Uri.parse('/projects?lang=es'); + final rootUri = Uri.parse('/?lang=es'); + expect(BetterLink.isRoute(uri), true); + expect(BetterLink.isRoute(rootUri), true); }); } diff --git a/test/overflow_test.dart b/test/overflow_test.dart new file mode 100644 index 0000000..0e927c7 --- /dev/null +++ b/test/overflow_test.dart @@ -0,0 +1,36 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +@TestOn('browser') +library; + +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:portfolio/main.dart'; +import 'package:portfolio/navigation/router.dart'; +import 'package:portfolio/widgets/language_toggle_button.dart'; + +void main() { + testWidgets('App bar does not overflow in neither language', (tester) async { + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(840, 600); + + // Change if nothing overflows in the default language + await tester.pumpWidget( + ProviderScope(child: MyApp(router: AppRouter())), + ); + await tester.pumpAndSettle(); + + // Change language and check if nothing overflows + final languageButton = find.byType(LanguageToggleButton); + expect(languageButton, findsOne); + await tester.tap(languageButton); + await tester.pumpAndSettle(); + }); +} diff --git a/test/responsive_test.dart.bak b/test/responsive_test.dart similarity index 52% rename from test/responsive_test.dart.bak rename to test/responsive_test.dart index 21f45ec..5dafff7 100644 --- a/test/responsive_test.dart.bak +++ b/test/responsive_test.dart @@ -5,60 +5,34 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. +@TestOn('browser') +library; + import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:portfolio/models/route_data.dart'; -import 'package:portfolio/widgets/sliver_app_bar.dart'; - -const routesEnglish = [ - RouteData( - name: 'Research', - path: '/research', - icon: Icons.article, - ), - RouteData( - name: 'Projects', - path: '/projects', - icon: Icons.terminal, - ), - RouteData( - name: 'Curriculum Vitae', - path: '/cv', - icon: Icons.school, - ), -]; +import 'package:portfolio/main.dart'; +import 'package:portfolio/navigation/router.dart'; void main() { - testWidgets('ResponsiveAppBar adapts based on screen width', (tester) async { + testWidgets('App bar adapts based on screen width', (tester) async { tester.view.devicePixelRatio = 1.0; - const appTitle = 'Alejandro'; // Build our app and trigger a frame. - // Build our app with English top bar and trigger a frame. await tester.pumpWidget( - const MaterialApp( - home: Scaffold( - body: CustomScrollView( - physics: BouncingScrollPhysics(), - slivers: [ - MySliverAppBar(menuRoutes: routesEnglish), - ], - ), - ), - ), + ProviderScope(child: MyApp(router: AppRouter())), ); + await tester.pumpAndSettle(); // Test actions visibility when screen width is greater than the breakpoint tester.view.physicalSize = const Size(840, 600); await tester.pump(); expect(find.byIcon(Icons.menu), findsNothing); - expect(find.text(appTitle), findsOneWidget); // Test actions visibility when screen width is less than the breakpoint tester.view.physicalSize = const Size(839, 600); await tester.pump(); expect(find.byIcon(Icons.menu), findsOneWidget); - expect(find.text(appTitle), findsOneWidget); }); }