Skip to content

Commit

Permalink
Merge branch 'testing-501-recipe-preview-ct-solution' into testing-50…
Browse files Browse the repository at this point in the history
…2-recipe-filter-ct-starter
  • Loading branch information
yjaaidi committed Oct 8, 2024
2 parents c2c33a0 + 017475a commit 0b9e546
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@cypress/webpack-dev-server": "3.9.0",
"@jscutlery/cypress-harness": "0.7.1",
"@jscutlery/operators": "2.1.3",
"@jscutlery/playwright-ct-angular": "0.8.1",
"@jscutlery/playwright-ct-angular": "0.9.0",
"@jscutlery/rx-computed": "0.5.0",
"@jscutlery/swc-angular": "0.14.2",
"@jscutlery/swc-angular-plugin": "0.14.2",
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0b9e546

Please sign in to comment.