Files
CookIT/test/recipes/recipe_draft_test.dart
T
2026-10-28 22:55:09 +01:00

83 lines
3.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:cookit/src/recipes/models/recipe.dart';
import 'package:cookit/src/recipes/recipe_draft.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/date_symbol_data_local.dart';
void main() {
setUpAll(() => initializeDateFormatting('de'));
group('ingredients', () {
const groups = [
IngredientGroup(
lines: [
IngredientLine(amount: 300, unitKey: 'gram', name: 'Mehl'),
IngredientLine(amount: 2, amountMax: 3, unitKey: 'tablespoon', name: 'Öl', remark: 'gutes'),
],
),
IngredientGroup(lines: [IngredientLine(name: 'Salz')]),
IngredientGroup(
name: 'Topping',
lines: [IngredientLine(amount: 0.5, unitKey: 'pinch', name: 'Rosmarin')],
),
];
test('the first unnamed group has no heading; later groups get one', () {
final entries = ingredientEntriesFrom(groups);
expect(entries.map((e) => e.runtimeType), [LineEntry, LineEntry, GroupEntry, LineEntry, GroupEntry, LineEntry]);
expect((entries[1] as LineEntry).amount.text, '2–3');
expect((entries[5] as LineEntry).amount.text, '½');
});
test('round-trips', () {
final back = ingredientGroupsFrom(ingredientEntriesFrom(groups));
expect([for (final g in back) g.toJson()], [for (final g in groups) g.toJson()]);
});
test('lines without a name and empty groups are dropped', () {
final entries = [
GroupEntry('Leer'),
LineEntry()..name.text = ' ',
GroupEntry(' Sauce '),
LineEntry()
..amount.text = '1,5'
..name.text = 'Sahne',
];
final groups = ingredientGroupsFrom(entries);
expect(groups, hasLength(1));
expect(groups.single.name, 'Sauce');
expect(groups.single.lines.single.amount, 1.5);
});
test('a heading with an empty name becomes an unnamed group', () {
final entries = [LineEntry()..name.text = 'Mehl', GroupEntry(''), LineEntry()..name.text = 'Zucker'];
expect(ingredientGroupsFrom(entries).map((g) => g.name), [null, null]);
});
});
group('steps', () {
test('round-trips sections', () {
const sections = [
StepSection(steps: ['Ofen vorheizen.']),
StepSection(title: 'Teig', steps: ['Kneten.', 'Ruhen lassen.']),
];
final back = stepSectionsFrom(stepEntriesFrom(sections));
expect([for (final s in back) s.toJson()], [for (final s in sections) s.toJson()]);
});
test('empty steps are dropped', () {
final entries = [StepTextEntry(' '), SectionEntry('Soße'), StepTextEntry('Rühren.')];
final sections = stepSectionsFrom(entries);
expect(sections.single.title, 'Soße');
expect(sections.single.steps, ['Rühren.']);
});
});
test('tagsFrom trims and removes duplicates ignoring case', () {
expect(tagsFrom('vegan, schnell , Vegan,,'), ['vegan', 'schnell']);
});
test('linesFrom', () {
expect(linesFrom(' https://a.de \n\nhttps://b.de'), ['https://a.de', 'https://b.de']);
});
}