Files
eatvio-infra/tests/Feature/Recipe/EditTest.php

86 lines
3.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;
use Faker\Generator as Faker;
class RecipeEditTest extends TestCase
{
use RefreshDatabase;
public function can_update_recipe()
{
Storage::fake('public');
$faker = Factory::create('ru_RU');
$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', $faker->sentence(3))
->set('description', $faker->paragraph(2))
->set('cooking_time', $faker->numberBetween(10, 120))
->set('type', $faker->randomElement(['Main Dish', 'Dessert', 'Appetizer']))
->set('video_url', $faker->url)
->set('image', UploadedFile::fake()->image('new_image.jpg'))
->set('tags', [$tag1->id, $tag2->id])
->call('addIngredient')
->set('ingredients_name.0', $faker->word)
->set('ingredients_portion.0', $faker->numberBetween(1, 500))
->set('ingredients_unit.0', $faker->randomElement(['gr', 'ml', 'pcs']))
->call('addIngredient')
->set('ingredients_name.1', $faker->word)
->set('ingredients_portion.1', $faker->numberBetween(1, 500))
->set('ingredients_unit.1', $faker->randomElement(['gr', 'ml', 'pcs']))
->call('addIngredient')
->set('ingredients_name.2', $faker->word)
->set('ingredients_portion.2', $faker->numberBetween(1, 500))
->set('ingredients_unit.2', $faker->randomElement(['gr', 'ml', 'pcs']))
->call('addStep')
->set('steps.0.description', $faker->paragraph)
->set('steps.0.image', UploadedFile::fake()->image('new_step_image0.jpg'))
->call('addStep')
->set('steps.1.description', $faker->paragraph)
->set('steps.1.image', UploadedFile::fake()->image('new_step_image1.jpg'))
->call('addStep')
->set('steps.2.description', $faker->paragraph)
->set('steps.2.image', UploadedFile::fake()->image('new_step_image2.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('tags', [
'id' => $tag1->id,
]);
$this->assertDatabaseHas('tags', [
'id' => $tag2->id,
]);
Storage::disk('public')->assertExists('recipes/new_image.jpg');
Storage::disk('public')->assertExists('steps/new_step_image.jpg');
}
}