feat(screenshots): localize sample variety & market names per shot language

This commit is contained in:
vjrj 2026-07-15 17:48:44 +02:00
parent ff7e7e120f
commit 991785821f
39 changed files with 68 additions and 39 deletions

View file

@ -45,13 +45,11 @@ void main() {
late AppDatabase db;
late VarietyRepository repo;
late SpeciesRepository species;
late SeededInventory seeded;
setUp(() async {
db = newTestDatabase();
repo = newTestRepository(db);
species = newTestSpeciesRepository(db);
seeded = await seedShowcase(db, repo);
});
tearDown(() => db.close());
@ -79,45 +77,52 @@ void main() {
// A POPULATED market: a seeded OffersCubit (no transport) feeding MarketBody,
// so the offer list renders with no live discovery stream to hang
// pumpAndSettle. (Live discovery is exercised by offers_cubit_test.dart; see
// the note in market_screen_test.dart on why we don't drive it via widgets.)
Future<Widget> market() async => Builder(
// pumpAndSettle. Offer names are localized. (Live discovery is exercised by
// offers_cubit_test.dart; see market_screen_test.dart on why not via widgets.)
Widget marketWidget(AppLocale locale) => Builder(
builder: (context) => Scaffold(
appBar: AppBar(
title: Text(context.t.market.title),
actions: [IconButton(icon: const Icon(Icons.tune), onPressed: () {})],
),
body: BlocProvider<OffersCubit>(
create: (_) => _SeededOffersCubit(_sampleOffers()),
create: (_) => _SeededOffersCubit(_sampleOffers(locale)),
child: MarketBody(onConfigure: () {}),
),
),
);
/// Each entry renders one screen; the runner re-seeds and re-locales per shot.
final screens = <String, Future<Widget> Function()>{
'home': () async => const HomeScreen(marketEnabled: true),
'inventory': () async => const InventoryListScreen(),
'market': market,
'calendar': () async => const CalendarScreen(initialMonth: 4),
'detail': () async => BlocProvider(
create: (_) => VarietyDetailCubit(repo, seeded.heroVarietyId),
child: const VarietyDetailScreen(),
),
};
const screenNames = ['home', 'inventory', 'market', 'calendar', 'detail'];
for (final locale in screenshotLocales) {
for (final entry in screens.entries) {
testWidgets('${locale.languageCode}/${entry.key}', (tester) async {
for (final name in screenNames) {
testWidgets('${locale.languageCode}/$name', (tester) async {
// Re-seed per shot so the sample variety names are in the shot's
// language. Drift writes must run in REAL async (runAsync), not the
// testWidgets fake clock, or they hang.
late final SeededInventory seeded;
await tester.runAsync(() async {
seeded = await seedShowcase(db, repo, locale);
});
final child = switch (name) {
'home' => const HomeScreen(marketEnabled: true),
'inventory' => const InventoryListScreen(),
'market' => marketWidget(locale),
'calendar' => const CalendarScreen(initialMonth: 4),
_ => BlocProvider(
create: (_) => VarietyDetailCubit(repo, seeded.heroVarietyId),
child: const VarietyDetailScreen(),
),
};
await tester.pumpWidget(
screenshotApp(
repository: repo,
species: species,
locale: locale,
child: await entry.value(),
child: child,
),
);
await capture(tester, locale.languageCode, entry.key);
await capture(tester, locale.languageCode, name);
});
}
}
@ -125,6 +130,7 @@ void main() {
// RTL layout demo: base (English) strings, forced right-to-left, so the
// mirrored inventory proves the design is RTL-safe. Not a translated locale.
testWidgets('rtl/inventory', (tester) async {
await tester.runAsync(() => seedShowcase(db, repo, AppLocale.en));
await tester.pumpWidget(
screenshotApp(
repository: repo,
@ -159,12 +165,12 @@ class _NoopOfferTransport implements OfferTransport {
Future<void> close() async {}
}
/// A small, internationally-neutral set of nearby offers across gift / swap /
/// sale and colour-coded botanical families.
List<Offer> _sampleOffers() => [
Offer(id: 'o1', authorPubkeyHex: 'a1' * 32, summary: 'Cherry tomato', type: OfferType.gift, category: 'Solanaceae', approxGeohash: 'sp3e9', isOrganic: true),
Offer(id: 'o2', authorPubkeyHex: 'a2' * 32, summary: 'Climbing bean', type: OfferType.exchange, category: 'Fabaceae', approxGeohash: 'sp3e8'),
Offer(id: 'o3', authorPubkeyHex: 'a3' * 32, summary: 'Sunflower', type: OfferType.sale, category: 'Asteraceae', approxGeohash: 'sp3ec', priceAmount: 2, priceCurrency: ''),
Offer(id: 'o4', authorPubkeyHex: 'a4' * 32, summary: 'Sweet basil', type: OfferType.gift, category: 'Lamiaceae', approxGeohash: 'sp3e2', isOrganic: true),
Offer(id: 'o5', authorPubkeyHex: 'a5' * 32, summary: 'Purple carrot', type: OfferType.exchange, category: 'Apiaceae', approxGeohash: 'sp3ef'),
/// A small set of nearby offers across gift / swap / sale and colour-coded
/// botanical families, with names localized to [l].
List<Offer> _sampleOffers(AppLocale l) => [
Offer(id: 'o1', authorPubkeyHex: 'a1' * 32, summary: labelFor('cherryTomato', l), type: OfferType.gift, category: 'Solanaceae', approxGeohash: 'sp3e9', isOrganic: true),
Offer(id: 'o2', authorPubkeyHex: 'a2' * 32, summary: labelFor('bean', l), type: OfferType.exchange, category: 'Fabaceae', approxGeohash: 'sp3e8'),
Offer(id: 'o3', authorPubkeyHex: 'a3' * 32, summary: labelFor('sunflower', l), type: OfferType.sale, category: 'Asteraceae', approxGeohash: 'sp3ec', priceAmount: 2, priceCurrency: ''),
Offer(id: 'o4', authorPubkeyHex: 'a4' * 32, summary: labelFor('basil', l), type: OfferType.gift, category: 'Lamiaceae', approxGeohash: 'sp3e2', isOrganic: true),
Offer(id: 'o5', authorPubkeyHex: 'a5' * 32, summary: labelFor('carrot', l), type: OfferType.exchange, category: 'Apiaceae', approxGeohash: 'sp3ef'),
];