forked from eatvio/eatvio-infra
Merge pull request 'Добавить тесты для изменения рецептов' (#28) from alex_chevski/eatvio:recipe-tests into main
Reviewed-on: eatvio/eatvio#28
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Recipe;
|
||||
|
||||
use App\Models\Recipe;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EditFormTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $user;
|
||||
|
||||
private Recipe $recipe;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
|
||||
$this->recipe = Recipe::inRandomOrder()->first();
|
||||
}
|
||||
|
||||
public function test_edit_page_recipe_success(): void
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('recipe.edit', $this->recipe, false));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
192
tests/Feature/Recipe/EditTest.php
Normal file
192
tests/Feature/Recipe/EditTest.php
Normal file
@@ -0,0 +1,192 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Recipe;
|
||||
|
||||
use App\Livewire\Recipe\Edit;
|
||||
use App\Models\Recipe;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EditTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $user;
|
||||
|
||||
private Recipe $recipe;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
|
||||
$this->recipe = Recipe::inRandomOrder()->first();
|
||||
}
|
||||
|
||||
public function test_edit_page_recipe_success(): void
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('recipe.edit', $this->recipe, false));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function testUpdateRecipePublishSuccess(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$recipe = $this->recipe = Recipe::factory()->make();
|
||||
|
||||
$recipeUpdate = Livewire::test(Edit::class, [
|
||||
'recipe' => $this->recipe,
|
||||
])
|
||||
->set('title', $recipe->title)
|
||||
->assertSet('title', $recipe->title)
|
||||
->set('image', $recipe->image)
|
||||
->set('state', $recipe->state)
|
||||
->assertSet('state', $recipe->state)
|
||||
->set('cooking_time', $recipe->cooking_time)
|
||||
->assertSet('cooking_time', $recipe->cooking_time)
|
||||
->set('ingredients', $recipe->ingredients)
|
||||
->assertSet('ingredients', $recipe->ingredients)
|
||||
->set('type', $recipe->type)
|
||||
->assertSet('type', $recipe->type)
|
||||
->set('description', $recipe->description)
|
||||
->assertSet('description', $recipe->description)
|
||||
->set('video_url', $recipe->video_url)
|
||||
->assertSet('video_url', $recipe->video_url)
|
||||
->call('publish')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($recipe->title, $recipeUpdate->title);
|
||||
self::assertEquals($recipe->image, $recipeUpdate->image);
|
||||
self::assertEquals($recipe->state, $recipeUpdate->state);
|
||||
self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time);
|
||||
self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients);
|
||||
self::assertEquals($recipe->type, $recipeUpdate->type);
|
||||
self::assertEquals($recipe->description, $recipeUpdate->description);
|
||||
self::assertEquals($recipe->video_url, $recipeUpdate->video_url);
|
||||
}
|
||||
|
||||
|
||||
public function testUpdateRecipeDraftSuccess(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$recipe = $this->recipe = Recipe::factory()->make();
|
||||
|
||||
$recipeUpdate = Livewire::test(Edit::class, [
|
||||
'recipe' => $this->recipe,
|
||||
])
|
||||
->set('title', $recipe->title)
|
||||
->assertSet('title', $recipe->title)
|
||||
->set('image', $recipe->image)
|
||||
->set('state', $recipe->state)
|
||||
->assertSet('state', $recipe->state)
|
||||
->set('cooking_time', $recipe->cooking_time)
|
||||
->assertSet('cooking_time', $recipe->cooking_time)
|
||||
->set('ingredients', $recipe->ingredients)
|
||||
->assertSet('ingredients', $recipe->ingredients)
|
||||
->set('type', $recipe->type)
|
||||
->assertSet('type', $recipe->type)
|
||||
->set('description', $recipe->description)
|
||||
->assertSet('description', $recipe->description)
|
||||
->set('video_url', $recipe->video_url)
|
||||
->assertSet('video_url', $recipe->video_url)
|
||||
->call('draft')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($recipe->title, $recipeUpdate->title);
|
||||
self::assertEquals($recipe->image, $recipeUpdate->image);
|
||||
self::assertEquals('archived', $recipeUpdate->state);
|
||||
self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time);
|
||||
self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients);
|
||||
self::assertEquals($recipe->type, $recipeUpdate->type);
|
||||
self::assertEquals($recipe->description, $recipeUpdate->description);
|
||||
self::assertEquals($recipe->video_url, $recipeUpdate->video_url);
|
||||
}
|
||||
|
||||
|
||||
public function testUpdateRecipePreviewSuccess(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$recipe = $this->recipe = Recipe::factory()->make();
|
||||
|
||||
$recipeUpdate = Livewire::test(Edit::class, [
|
||||
'recipe' => $this->recipe,
|
||||
])
|
||||
->set('title', $recipe->title)
|
||||
->assertSet('title', $recipe->title)
|
||||
->set('image', $recipe->image)
|
||||
->set('state', $recipe->state)
|
||||
->assertSet('state', $recipe->state)
|
||||
->set('cooking_time', $recipe->cooking_time)
|
||||
->assertSet('cooking_time', $recipe->cooking_time)
|
||||
->set('ingredients', $recipe->ingredients)
|
||||
->assertSet('ingredients', $recipe->ingredients)
|
||||
->set('type', $recipe->type)
|
||||
->assertSet('type', $recipe->type)
|
||||
->set('description', $recipe->description)
|
||||
->assertSet('description', $recipe->description)
|
||||
->set('video_url', $recipe->video_url)
|
||||
->assertSet('video_url', $recipe->video_url)
|
||||
->call('preview')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($recipe->title, $recipeUpdate->title);
|
||||
self::assertEquals($recipe->image, $recipeUpdate->image);
|
||||
self::assertEquals('archived', $recipeUpdate->state);
|
||||
self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time);
|
||||
self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients);
|
||||
self::assertEquals($recipe->type, $recipeUpdate->type);
|
||||
self::assertEquals($recipe->description, $recipeUpdate->description);
|
||||
self::assertEquals($recipe->video_url, $recipeUpdate->video_url);
|
||||
}
|
||||
|
||||
|
||||
public function testNothingChange(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$recipeUpdate = Livewire::test(Edit::class, [
|
||||
'recipe' => $this->recipe,
|
||||
])
|
||||
->call('publish')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
Storage::disk('public')->assertExists($this->recipe->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($this->recipe->title, $recipeUpdate->title);
|
||||
self::assertEquals($this->recipe->image, $recipeUpdate->image);
|
||||
self::assertEquals($this->recipe->state, $recipeUpdate->state);
|
||||
self::assertEquals($this->recipe->cooking_time, $recipeUpdate->cooking_time);
|
||||
self::assertEquals($this->recipe->ingredients, $recipeUpdate->ingredients);
|
||||
self::assertEquals($this->recipe->type, $recipeUpdate->type);
|
||||
self::assertEquals($this->recipe->description, $recipeUpdate->description);
|
||||
self::assertEquals($this->recipe->video_url, $recipeUpdate->video_url);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user