Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golden test fonts #2562

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions testing_app/flutter_test_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'dart:async';

import 'package:golden_toolkit/golden_toolkit.dart';

Future<void> testExecutable(FutureOr<void> Function() testMain) async {
await loadAppFonts();
return testMain();
}
Binary file added testing_app/fonts/Raleway-Italic.ttf
Binary file not shown.
Binary file added testing_app/fonts/Raleway-Regular.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions testing_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class TestingApp extends StatelessWidget {
child: MaterialApp.router(
title: 'Testing Sample',
theme: ThemeData(
fontFamily: 'Raleway',
colorSchemeSeed: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
Expand Down
2 changes: 1 addition & 1 deletion testing_app/lib/screens/favorites.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FavoritesPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Favorites'),
title: const Text('Favorites W'),
),
body: Consumer<Favorites>(
builder: (context, value, child) => value.items.isNotEmpty
Expand Down
8 changes: 8 additions & 0 deletions testing_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ environment:
dependencies:
flutter:
sdk: flutter
golden_toolkit: ^0.15.0


cupertino_icons: ^1.0.3
provider: ^6.0.2
Expand All @@ -24,4 +26,10 @@ dev_dependencies:
test: ^1.16.8

flutter:
fonts:
- family: Raleway
fonts:
- asset: fonts/Raleway-Regular.ttf
- asset: fonts/Raleway-Italic.ttf
style: italic
uses-material-design: true
72 changes: 72 additions & 0 deletions testing_app/test/favorites_page_golden_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
import 'package:testing_app/models/favorites.dart';
import 'package:testing_app/screens/favorites.dart';

Future<void> loadFonts() async {
TestWidgetsFlutterBinding.ensureInitialized();
await Future.wait([
rootBundle.load('fonts/Raleway-Regular.ttf').then((fontData) {
final loader = FontLoader('Raleway')..addFont(Future.value(fontData));
return loader.load();
}),
rootBundle.load('fonts/Raleway-Italic.ttf').then((fontData) {
final loader = FontLoader('Raleway')..addFont(Future.value(fontData));
return loader.load();
}),
]);
}

void main() {
setUpAll(() async {
await loadFonts();
});

group('Golden Test for FavoritesPage', () {
testWidgets('FavoritesPage with no favorites', (WidgetTester tester) async {
// Create a Favorites model with no items
await tester.pumpWidget(
ChangeNotifierProvider<Favorites>(
create: (_) => Favorites(),
child: const MaterialApp(
home: FavoritesPage(),
),
),
);

// Capture a golden image
await expectLater(
find.byType(FavoritesPage),
matchesGoldenFile('golden_images/favorites_page_empty.png'),
);
});

testWidgets('FavoritesPage with some favorites', (WidgetTester tester) async {
// Create a Favorites model with some items
await tester.pumpWidget(
ChangeNotifierProvider<Favorites>(
create: (_) {
final favorites = Favorites();
favorites.add(1);
favorites.add(2);
favorites.add(3);
return favorites;
},
child: const MaterialApp(
home: FavoritesPage(),
),
),
);

// Capture a golden image
await expectLater(
find.byType(FavoritesPage),
matchesGoldenFile('golden_images/favorites_page_with_items.png'),
);
});
});
}
53 changes: 53 additions & 0 deletions testing_app/test/favorites_page_golden_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
import 'package:testing_app/models/favorites.dart';
import 'package:testing_app/screens/favorites.dart';


void main() {

group('Golden Test for FavoritesPage', () {
testWidgets('FavoritesPage with no favorites', (WidgetTester tester) async {
// Create a Favorites model with no items
await tester.pumpWidget(
ChangeNotifierProvider<Favorites>(
create: (_) => Favorites(),
child: const MaterialApp(
home: FavoritesPage(),
),
),
);

// Capture a golden image
await expectLater(
find.byType(FavoritesPage),
matchesGoldenFile('golden_images/favorites_page_empty.png'),
);
});

testWidgets('FavoritesPage with some favorites', (WidgetTester tester) async {
// Create a Favorites model with some items
await tester.pumpWidget(
ChangeNotifierProvider<Favorites>(
create: (_) {
final favorites = Favorites();
favorites.add(1);
favorites.add(2);
favorites.add(3);
return favorites;
},
child: const MaterialApp(
home: FavoritesPage(),
),
),
);

// Capture a golden image
await expectLater(
find.byType(FavoritesPage),
matchesGoldenFile('golden_images/favorites_page_with_items.png'),
);
});
});
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.