Files
CookIT/test/planning/ingredient_totals_test.dart
T

56 lines
1.9 KiB
Dart
Raw Normal View History

import 'package:cookit/src/planning/ingredient_totals.dart';
import 'package:cookit/src/recipes/models/recipe.dart';
import 'package:flutter_test/flutter_test.dart';
import '../support/fixtures.dart';
void main() {
Recipe withLines(String id, List<IngredientLine> lines) => recipe(
id: id,
ingredientGroups: [IngredientGroup(lines: lines)],
);
test('lines with the same name and Unit are added up, others stay apart', () {
final totals = ingredientTotals([
withLines('a', const [
IngredientLine(amount: 200, unitKey: 'gram', name: 'Butter'),
IngredientLine(amount: 2, name: 'Eier'),
IngredientLine(name: 'Salz'),
]),
withLines('b', const [
IngredientLine(amount: 200, unitKey: 'gram', name: 'butter '),
IngredientLine(amount: 1, unitKey: 'tablespoon', name: 'Butter'),
IngredientLine(amount: 1, amountMax: 2, name: 'Eier'),
IngredientLine(name: 'Salz'),
]),
]);
expect(
[for (final l in totals) (l.amount, l.amountMax, l.unitKey, l.name)],
[
(400.0, null, 'gram', 'Butter'),
(3.0, 4.0, null, 'Eier'),
(null, null, null, 'Salz'),
(1.0, null, 'tablespoon', 'Butter'),
],
);
});
test('a remark survives only when every line agrees', () {
final totals = ingredientTotals([
withLines('a', const [
IngredientLine(amount: 1, name: 'Zitrone', remark: 'bio'),
IngredientLine(amount: 1, name: 'Ei', remark: 'groß'),
]),
withLines('b', const [
IngredientLine(amount: 1, name: 'Zitrone', remark: 'bio'),
IngredientLine(amount: 1, name: 'Ei'),
]),
]);
expect([for (final l in totals) l.remark], ['bio', null]);
});
test('the same Recipe planned twice counts twice', () {
final r = withLines('a', const [IngredientLine(amount: 100, unitKey: 'gram', name: 'Mehl')]);
expect(ingredientTotals([r, r]).single.amount, 200);
});
}