~repos /only-bible-app

#kotlin#android#ios

GIT_CONFIG_PARAMETERS="'http.version=HTTP/1.1'" git clone https://git.pyrossh.dev/only-bible-app.git
Discussions: https://groups.google.com/g/rust-embed-devs

The only bible app you will ever need. No ads. No in-app purchases. No distractions.



test/screenshot_test.dart



import "dart:io" as io;
import "package:async_redux/async_redux.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:flutter_test/flutter_test.dart";
import "package:go_router/go_router.dart";
import "package:golden_screenshot/golden_screenshot.dart";
import "package:only_bible_app/gen/bible.gen.dart";
import "package:only_bible_app/home.dart";
import "package:only_bible_app/store/app_navigator.dart";
import "package:only_bible_app/store/app_state.dart";
import "package:only_bible_app/theme.dart";
import "package:only_bible_app/utils.dart";
import "package:path/path.dart" as path;
Widget buildScreenshotApp({
required ScreenshotDevice device,
required Store<AppState> store,
required Widget home,
ThemeMode themeMode = ThemeMode.light,
}) {
final router = GoRouter(
initialLocation: "/",
routes: [
GoRoute(path: "/", builder: (_, __) => home),
GoRoute(path: "/chapter/:bookIndex/:chapterIndex", builder: (_, __) => home),
],
);
return StoreProvider<AppState>(
store: store,
child: AppRouterScope(
router: router,
child: ScreenshotApp(
device: device,
theme: lightTheme.copyWith(
textTheme: lightTheme.textTheme.apply(
fontFamily: "Roboto",
fontFamilyFallback: const ["NotoSansDevanagari"], // This is for the golden tests
),
),
darkTheme: darkTheme.copyWith(
textTheme: darkTheme.textTheme.apply(
fontFamily: "Roboto",
fontFamilyFallback: const ["NotoSansDevanagari"], // This is for the golden tests
),
),
themeMode: themeMode,
home: home,
),
),
);
}
Future<ByteData> _loadMaterialIcons() async {
final flutterRoot = io.Platform.environment['FLUTTER_ROOT']!;
final iconFont = io.File('$flutterRoot/bin/cache/artifacts/material_fonts/MaterialIcons-Regular.otf');
return iconFont.readAsBytesSync().buffer.asByteData();
}
Map<String, List<Future<ByteData>>> _loadFontsFromDir() {
final fontFamilyToData = <String, List<Future<ByteData>>>{};
final fontsDirectory = path.join(path.dirname(io.Platform.script.path), 'test/fonts');
for (final familyDir in io.Directory(fontsDirectory).listSync()) {
if (familyDir is io.Directory) {
final fontFamily = path.basename(familyDir.path);
for (final file in familyDir.listSync()) {
if (file is io.File) {
(fontFamilyToData[fontFamily] ??= []).add(file.readAsBytes().then((bytes) => ByteData.view(bytes.buffer)));
}
}
}
}
return fontFamilyToData;
}
void main() {
late Bible bible;
late Bible hindiBible;
setUpAll(() async {
TestWidgetsFlutterBinding.ensureInitialized();
// Load fonts from test/fonts/ directory
final fontFamilies = _loadFontsFromDir();
for (final entry in fontFamilies.entries) {
final loader = FontLoader(entry.key);
for (final fontData in entry.value) {
loader.addFont(fontData);
}
await loader.load();
}
// Load MaterialIcons font
final materialLoader = FontLoader('MaterialIcons')..addFont(_loadMaterialIcons());
await materialLoader.load();
bible = await loadBible("en_kjv");
hindiBible = await loadBible("hi");
});
final devices = [
GoldenScreenshotDevices.iphone,
GoldenScreenshotDevices.ipad,
GoldenScreenshotDevices.androidPhone,
];
for (final device in devices) {
void setFolder() {
if (device == GoldenScreenshotDevices.androidPhone) {
ScreenshotDevice.screenshotsFolder = '../android/fastlane/metadata/android/en-GB/images/';
} else {
ScreenshotDevice.screenshotsFolder = '../ios/fastlane/screenshots/en-US/';
}
}
testGoldens("${device.name} - home light", (tester) async {
setFolder();
final store = Store<AppState>(initialState: AppState(bible: bible));
await tester.pumpWidget(buildScreenshotApp(
device: device.device,
store: store,
home: const Home(bookIndex: 0, chapterIndex: 0),
));
await tester.loadAssets();
await tester.pump();
await tester.expectScreenshot(device.device, "home_light");
});
testGoldens("${device.name} - home dark", (tester) async {
final store = Store<AppState>(
initialState: AppState(bible: bible, darkMode: true),
);
await tester.pumpWidget(buildScreenshotApp(
device: device.device,
store: store,
home: const Home(bookIndex: 0, chapterIndex: 0),
themeMode: ThemeMode.dark,
));
await tester.loadAssets();
await tester.pump();
await tester.expectScreenshot(device.device, "home_dark");
});
testGoldens("${device.name} - book select", (tester) async {
final store = Store<AppState>(initialState: AppState(bible: bible));
await tester.pumpWidget(buildScreenshotApp(
device: device.device,
store: store,
home: const Home(bookIndex: 0, chapterIndex: 0),
));
await tester.loadAssets();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key("bookTitle")));
await tester.pumpAndSettle();
await tester.pump();
await tester.expectScreenshot(device.device, "book_select");
});
testGoldens("${device.name} - chapter select", (tester) async {
final store = Store<AppState>(initialState: AppState(bible: bible));
await tester.pumpWidget(buildScreenshotApp(
device: device.device,
store: store,
home: const Home(bookIndex: 0, chapterIndex: 0),
));
await tester.loadAssets();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key("chapterTitle")));
await tester.pumpAndSettle();
await tester.pump();
await tester.expectScreenshot(device.device, "chapter_select");
});
testGoldens("${device.name} - verse select", (tester) async {
final verses = bible.books![0].chapters![0].verses!;
final store = Store<AppState>(
initialState: AppState(
bible: bible,
selectedVerses: [verses[0], verses[1], verses[2]],
highlights: {
"0:0:3": 0,
"0:0:4": 1,
"0:0:5": 2,
"0:0:6": 3,
},
),
);
await tester.pumpWidget(buildScreenshotApp(
device: device.device,
store: store,
home: const Home(bookIndex: 0, chapterIndex: 0),
));
await tester.loadAssets();
await tester.pump();
await tester.expectScreenshot(device.device, "verse_select");
});
testGoldens("${device.name} - settings", (tester) async {
final store = Store<AppState>(initialState: AppState(bible: bible));
await tester.pumpWidget(buildScreenshotApp(
device: device.device,
store: store,
home: const Home(bookIndex: 0, chapterIndex: 0),
));
await tester.loadAssets();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key("settingsButton")));
await tester.pumpAndSettle();
await tester.pump();
await tester.expectScreenshot(device.device, "settings");
});
testGoldens("${device.name} - bible select", (tester) async {
final store = Store<AppState>(initialState: AppState(bible: bible));
await tester.pumpWidget(buildScreenshotApp(
device: device.device,
store: store,
home: const Home(bookIndex: 0, chapterIndex: 0),
));
await tester.loadAssets();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key("bible")));
await tester.pumpAndSettle();
await tester.pump();
await tester.expectScreenshot(device.device, "bible_select");
});
testGoldens("${device.name} - hindi home", (tester) async {
final store = Store<AppState>(initialState: AppState(bible: hindiBible));
await tester.pumpWidget(buildScreenshotApp(
device: device.device,
store: store,
home: const Home(bookIndex: 0, chapterIndex: 0),
));
await tester.loadAssets();
await tester.pump();
await tester.expectScreenshot(device.device, "hindi_home");
});
}
}