Files
eatvio-infra/tests/Feature/Plan/CreateTest.php
Anatoliy Poloz 92a54106ef analysators added
2023-12-18 14:36:32 +03:00

166 lines
6.1 KiB
PHP

<?php
namespace Tests\Feature\Plan;
use App\Livewire\Plan\Create;
use App\Models\Plan;
// use Livewire\WithFileUploads;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
class CreateTest extends TestCase
{
use RefreshDatabase;
private $image;
private $plan;
protected User $user;
public function setUp(): void
{
parent::setUp();
Storage::fake('plans');
$this->image = UploadedFile::fake()->image('plan.png');
$this->user = User::factory()->create(['is_consultant' => true]);
$this->plan = Plan::factory()->make();
}
public function test_show_form_create_plan()
{
$response = $this
->actingAs($this->user)
->get('/plan/create');
$response
->assertStatus(302);
// ->assertRedirect(route('home'));
}
public function test_publish_new_plan_success(): void
{
$this->actingAs($this->user);
// $this->assertEquals($this->plan->count(), $count = Plan::count());
Livewire::test(Create::class)
->set('name', $this->plan->name)
->assertSet('name', $this->plan->name)
->set('image', $this->image)
->set('duration', $this->plan->duration)
->assertSet('duration', $this->plan->duration)
->set('state', $this->plan->state)
->assertSet('state', $this->plan->state)
->set('type', $this->plan->type)
->assertSet('type', $this->plan->type)
->set('details', $this->plan->details)
->assertSet('details', $this->plan->details)
->set('packets_count', $this->plan->packets_count)
->assertSet('packets_count', $this->plan->packets_count)
->set('packet1_options', $this->plan->packet1_options)
->assertSet('packet1_options', $this->plan->packet1_options)
->set('packet2_options', $this->plan->packet2_options)
->assertSet('packet2_options', $this->plan->packet2_options)
->set('packet3_options', $this->plan->packet3_options)
->assertSet('packet3_options', $this->plan->packet3_options)
->call('publish')
->assertStatus(200)
->assertHasNoErrors(['name', 'image', 'duration', 'details']);
Storage::disk('public')->assertExists($this->plan->image);
// $this->assertEquals($count + 1, Plan::count());
}
public function test_to_draft_new_plan_success(): void
{
$this->actingAs($this->user);
$id = $this->plan->count();
Livewire::test(Create::class)
->set('name', $this->plan->name)
->assertSet('name', $this->plan->name)
->set('image', $this->image)
->set('duration', $this->plan->duration)
->assertSet('duration', $this->plan->duration)
->set('state', $this->plan->state)
->assertSet('state', $this->plan->state)
->set('type', $this->plan->type)
->assertSet('type', $this->plan->type)
->set('details', $this->plan->details)
->assertSet('details', $this->plan->details)
->set('packets_count', $this->plan->packets_count)
->assertSet('packets_count', $this->plan->packets_count)
->set('packet1_options', $this->plan->packet1_options)
->assertSet('packet1_options', $this->plan->packet1_options)
->set('packet2_options', $this->plan->packet2_options)
->assertSet('packet2_options', $this->plan->packet2_options)
->set('packet3_options', $this->plan->packet3_options)
->assertSet('packet3_options', $this->plan->packet3_options)
->call('addToDrafts')
->assertStatus(200)
->assertRedirect('plan/'.$id + 1)
->assertHasNoErrors(['name', 'image', 'duration', 'details']);
Storage::disk('public')->assertExists($this->plan->image);
}
public function test_to_preview_new_plan_success(): void
{
$this->actingAs($this->user);
Livewire::test(Create::class)
->set('name', $this->plan->name)
->assertSet('name', $this->plan->name)
->set('image', $this->image)
->set('duration', $this->plan->duration)
->assertSet('duration', $this->plan->duration)
->set('state', $this->plan->state)
->assertSet('state', $this->plan->state)
->set('type', $this->plan->type)
->assertSet('type', $this->plan->type)
->set('details', $this->plan->details)
->assertSet('details', $this->plan->details)
->set('packets_count', $this->plan->packets_count)
->assertSet('packets_count', $this->plan->packets_count)
->set('packet1_options', $this->plan->packet1_options)
->assertSet('packet1_options', $this->plan->packet1_options)
->set('packet2_options', $this->plan->packet2_options)
->assertSet('packet2_options', $this->plan->packet2_options)
->set('packet3_options', $this->plan->packet3_options)
->assertSet('packet3_options', $this->plan->packet3_options)
->call('showPreview')
->assertStatus(200)
->assertHasNoErrors(['name', 'image', 'duration', 'details']);
Storage::disk('public')->assertExists($this->plan->image);
}
public function test_set_empty_data(): void
{
$this->actingAs($this->user);
Livewire::test(Create::class)
->set('name', null)
->set('image', null)
->set('duration', null)
->set('state', null)
->set('type', null)
->set('details', null)
->set('packets_count', null)
->set('packet1_options', null)
->set('packet2_options', null)
->set('packet3_options', null)
->call('publish')
->assertHasErrors(['name', 'image', 'duration', 'details']);
}
}