-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: All recipes list page * chore: fix bad reference * Apply pint changes --------- Co-authored-by: IronSinew <[email protected]>
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Recipe; | ||
use Illuminate\Http\Request; | ||
use Inertia\Inertia; | ||
|
||
class AllRecipeListController extends Controller | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
$perPageAmount = 9; | ||
|
||
//@codeCoverageIgnoreStart | ||
if ($request->wantsJson()) { | ||
return Recipe::orderBy('id')->cursorPaginate($perPageAmount); | ||
} | ||
//@codeCoverageIgnoreEnd | ||
|
||
return Inertia::render('Recipe/RecipeList')->with([ | ||
'label' => fn () => collect(['name' => 'All Recipes']), | ||
'recipes' => fn () => Recipe::orderBy('id')->cursorPaginate($perPageAmount), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/Feature/Http/Controllers/AllRecipeListControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Http\Controllers; | ||
|
||
use App\Models\Recipe; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Inertia\Testing\AssertableInertia as Assert; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
|
||
/** | ||
* @see \App\Http\Controllers\AllRecipeListController | ||
*/ | ||
final class AllRecipeListControllerTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
#[Test] | ||
public function index_displays_view(): void | ||
{ | ||
Recipe::factory()->count(5)->create(); | ||
|
||
$response = $this->get(route('recipe.all')); | ||
|
||
$response->assertOk(); | ||
$response->assertInertia(fn (Assert $page) => $page | ||
->component('Recipe/RecipeList') | ||
->has('recipes.data', 5) | ||
); | ||
} | ||
} |