forked from eatvio/eatvio-infra
68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Plan;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
use App\Models\Recipe;
|
|
use App\Models\User;
|
|
use App\Livewire\Recipe\Edit;
|
|
use Tests\TestCase;
|
|
|
|
class RecipeEditTest extends TestCase
|
|
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function can_update_recipe()
|
|
{
|
|
Storage::fake('public');
|
|
$user = User::factory()->create();
|
|
$recipe = Recipe::factory()->create([
|
|
'steps' => [],
|
|
'ingredients' => [],
|
|
]);
|
|
$tag1 = Tag::factory()->create();
|
|
$tag2 = Tag::factory()->create();
|
|
|
|
Livewire::actingAs($user)
|
|
->test('recipe.edit', ['recipe' => $recipe])
|
|
->set('title', 'New Title')
|
|
->set('description', 'New Description')
|
|
->set('cooking_time', '30')
|
|
->set('type', 'Main Dish')
|
|
->set('video_url', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ')
|
|
->set('image', UploadedFile::fake()->image('new_image.jpg'))
|
|
->set('tags', [$tag1->id, $tag2->id])
|
|
->call('addIngredient')
|
|
->set('ingredients_name.0', 'New Ingredient')
|
|
->set('ingredients_portion.0', '100')
|
|
->call('addStep')
|
|
->set('steps.0.description', 'New Step Description')
|
|
->set('steps.0.image', UploadedFile::fake()->image('new_step_image.jpg'))
|
|
->call('publish');
|
|
|
|
$this->assertDatabaseHas('recipes', [
|
|
'title' => 'New Title',
|
|
'description' => 'New Description',
|
|
'cooking_time' => 30,
|
|
'type' => 'Main Dish',
|
|
'video_url' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
|
'image' => 'recipes/new_image.jpg',
|
|
'state' => 'active',
|
|
]);
|
|
|
|
$this->assertDatabaseHas('recipe_tag', [
|
|
'id' => $tag1->id,
|
|
]);
|
|
$this->assertDatabaseHas('recipe_tag', [
|
|
'id' => $tag2->id,
|
|
]);
|
|
|
|
Storage::disk('public')->assertExists('recipes/new_image.jpg');
|
|
Storage::disk('public')->assertExists('steps/new_step_image.jpg');
|
|
}
|
|
}
|