Skip to content

Commit

Permalink
Merge branch 'testing-303-recipe-search-shallow-solution-test-bed' in…
Browse files Browse the repository at this point in the history
…to testing-303-recipe-search-shallow-solution-testing-library
  • Loading branch information
yjaaidi committed Sep 21, 2024
2 parents 1e36d14 + a56726b commit 3dfa411
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions apps/whiskmate/src/app/recipe/recipe-repository.fake.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, Provider } from '@angular/core';
import { RecipeFilter } from './recipe-filter';
import { Observable, of } from 'rxjs';
import { defer, Observable, of } from 'rxjs';
import { Recipe } from './recipe';
import {
RecipeRepository,
Expand All @@ -18,25 +18,26 @@ export class RecipeRepositoryFake implements RecipeRepositoryDef {
maxIngredientCount,
maxStepCount,
}: RecipeFilter = {}): Observable<Recipe[]> {
const recipes = this._recipes.filter((recipe) => {
const conditions = [
/* Filter by keywords. */
() => (keywords ? recipe.name.includes(keywords) : true),
/* Filter by max ingredients. */
() =>
maxIngredientCount != null
? recipe.ingredients.length <= maxIngredientCount
: true,
/* Filter by max steps. */
() =>
maxStepCount != null ? recipe.steps.length <= maxStepCount : true,
];
return defer(() => {
const recipes = this._recipes.filter((recipe) => {
const conditions = [
/* Filter by keywords. */
() => (keywords ? recipe.name.includes(keywords) : true),
/* Filter by max ingredients. */
() =>
maxIngredientCount != null
? recipe.ingredients.length <= maxIngredientCount
: true,
/* Filter by max steps. */
() =>
maxStepCount != null ? recipe.steps.length <= maxStepCount : true,
];

/* Return true if all conditions are true. */
return conditions.every((condition) => condition());
/* Return true if all conditions are true. */
return conditions.every((condition) => condition());
});
return of(recipes);
});

return of(recipes);
}

setRecipes(recipes: Recipe[]) {
Expand Down

0 comments on commit 3dfa411

Please sign in to comment.