47 lines
1.8 KiB
Dart
47 lines
1.8 KiB
Dart
import 'package:cookit/src/recipes/decision.dart';
|
|||
|
|
import 'package:cookit/src/recipes/models/recipe.dart';
|
||
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
|
||
|
|
import '../support/fixtures.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
Recipe make(String id, {String? course, int? prep, int? cook}) => Recipe(
|
||
|
|
id: id,
|
||
|
|
name: id,
|
||
|
|
courseId: course,
|
||
|
|
prepMinutes: prep,
|
||
|
|
cookMinutes: cook,
|
||
|
|
createdAt: testTime,
|
||
|
|
updatedAt: testTime,
|
||
|
|
);
|
||
|
|
|
||
|
|
final quickPasta = make('quick pasta', course: 'main', prep: 10, cook: 15);
|
||
|
|
final roast = make('roast', course: 'main', prep: 30, cook: 90);
|
||
|
|
final cake = make('cake', course: 'dessert', prep: 20, cook: 40);
|
||
|
|
final noTime = make('no time', course: 'main');
|
||
|
|
final all = [quickPasta, roast, cake, noTime];
|
||
|
|
|
||
|
|
List<String> names(DecisionChoice c) => c.matching(all).map((r) => r.name).toList();
|
||
|
|
|
||
|
|
test('no answers match everything', () {
|
||
|
|
expect(names(const DecisionChoice()), ['quick pasta', 'roast', 'cake', 'no time']);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('several Courses can be chosen', () {
|
||
|
|
expect(names(const DecisionChoice(courseIds: {'dessert'})), ['cake']);
|
||
|
|
expect(names(const DecisionChoice(courseIds: {'dessert', 'main'})), hasLength(4));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('a time limit uses the total time and leaves out Recipes without one', () {
|
||
|
|
expect(names(const DecisionChoice(time: TimeLimit.upTo30)), ['quick pasta']);
|
||
|
|
expect(names(const DecisionChoice(time: TimeLimit.upTo60)), ['quick pasta', 'cake']);
|
||
|
|
expect(names(const DecisionChoice(time: TimeLimit.any)), contains('no time'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('answers combine, and can be loosened one at a time', () {
|
||
|
|
const choice = DecisionChoice(courseIds: {'main'}, time: TimeLimit.upTo60);
|
||
|
|
expect(names(choice), ['quick pasta']);
|
||
|
|
expect(names(choice.withoutTimeLimit()), ['quick pasta', 'roast', 'no time']);
|
||
|
|
expect(names(choice.withAllCourses()), ['quick pasta', 'cake']);
|
||
|
|
});
|
||
|
|
}
|