Skip to content

Commit

Permalink
Add back widget tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro-FA committed Oct 29, 2024
1 parent 5f013b8 commit 9babc5a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 61 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
48 changes: 23 additions & 25 deletions test/better_link_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
36 changes: 36 additions & 0 deletions test/overflow_test.dart
Original file line number Diff line number Diff line change
@@ -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();
});
}
44 changes: 9 additions & 35 deletions test/responsive_test.dart.bak → test/responsive_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

0 comments on commit 9babc5a

Please sign in to comment.