53 lines
1.8 KiB
Dart
53 lines
1.8 KiB
Dart
import 'package:cookit/src/cooking_mode/cooking_session.dart';
|
||
import 'package:cookit/src/recipes/models/recipe.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
import '../support/fixtures.dart';
|
||
|
||
void main() {
|
||
test('steps run through all Step Sections with continuous numbers', () {
|
||
final session = CookingSession(
|
||
recipe(
|
||
stepSections: const [
|
||
StepSection(steps: ['Ofen vorheizen.']),
|
||
StepSection(title: 'Teig', steps: ['Kneten.', 'Ruhen lassen.']),
|
||
],
|
||
),
|
||
);
|
||
expect(
|
||
[for (final s in session.steps) (s.number, s.section, s.text)],
|
||
[(1, null, 'Ofen vorheizen.'), (2, 'Teig', 'Kneten.'), (3, 'Teig', 'Ruhen lassen.')],
|
||
);
|
||
});
|
||
|
||
test('more servings scale every amount', () {
|
||
final session = CookingSession(recipe()); // 4 servings: 300 g Mehl, 2–3 EL Öl
|
||
expect(session.factor, 1);
|
||
session
|
||
..moreServings()
|
||
..moreServings();
|
||
expect(session.servings, 6);
|
||
final lines = session.ingredientGroups.first.lines;
|
||
expect(lines[0].amount, 450);
|
||
expect((lines[1].amount, lines[1].amountMax), (3, 4.5));
|
||
});
|
||
|
||
test('servings never go below one and fractional servings step to whole numbers', () {
|
||
final session = CookingSession(Recipe(id: 'x', name: 'x', servings: 2.5, createdAt: testTime, updatedAt: testTime));
|
||
session.fewerServings();
|
||
expect(session.servings, 2);
|
||
session
|
||
..fewerServings()
|
||
..fewerServings();
|
||
expect(session.servings, 1);
|
||
session.moreServings();
|
||
expect(session.servings, 2);
|
||
});
|
||
|
||
test('a Recipe without Servings is not scaled', () {
|
||
final session = CookingSession(Recipe(id: 'x', name: 'x', createdAt: testTime, updatedAt: testTime));
|
||
expect(session.canScale, isFalse);
|
||
expect(session.factor, 1);
|
||
});
|
||
}
|