feat: add Flutter quality checks and tests for category chips in inventory and pantry screens
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / flutter-quality (push) Has been cancelled

This commit is contained in:
Nils-Johan Gynther
2026-05-12 16:13:10 +02:00
parent 08d14bf9e6
commit d645d3ad9d
8 changed files with 328 additions and 14 deletions
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:recipe_flutter/features/inventory/domain/inventory_item.dart';
import 'package:recipe_flutter/features/inventory/presentation/swipeable_inventory_tile.dart';
Widget _wrap(Widget child) {
return ProviderScope(
child: MaterialApp(
home: Scaffold(body: child),
),
);
}
void main() {
testWidgets('shows deepest category in chip and full path in tooltip', (
tester,
) async {
const item = InventoryItem(
id: 1,
productId: 99,
productName: 'Jordgubbssylt',
productCanonicalName: 'Jordgubbssylt',
categoryPath: 'Skafferi > Sylt, mos & marmelad > Sylt',
quantity: 1,
unit: 'st',
opened: false,
);
await tester.pumpWidget(_wrap(const SwipeableInventoryTile(item: item)));
expect(find.text('Sylt'), findsOneWidget);
final tooltipFinder = find.ancestor(
of: find.byType(Chip).first,
matching: find.byType(Tooltip),
);
final tooltip = tester.widget<Tooltip>(tooltipFinder);
expect(tooltip.message, 'Skafferi > Sylt, mos & marmelad > Sylt');
});
testWidgets('falls back to L1 when category path is missing', (tester) async {
const item = InventoryItem(
id: 2,
productId: 100,
productName: 'Okategoriserad vara',
productCanonicalName: 'Okategoriserad vara',
categoryPath: null,
quantity: 2,
unit: 'st',
opened: false,
);
await tester.pumpWidget(_wrap(const SwipeableInventoryTile(item: item)));
expect(find.text('Övrigt'), findsOneWidget);
final tooltipFinder = find.ancestor(
of: find.byType(Chip).first,
matching: find.byType(Tooltip),
);
final tooltip = tester.widget<Tooltip>(tooltipFinder);
expect(tooltip.message, 'Övrigt');
});
}