forked from eatvio/eatvio-infra
135 lines
4.4 KiB
PHP
135 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Plan;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
// use Livewire\WithFileUploads;
|
|
use Livewire\Livewire;
|
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
// use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use App\Models\Plan;
|
|
use App\Models\User;
|
|
use App\Livewire\Plan\Create;
|
|
use Tests\TestCase;
|
|
|
|
class CreateTest extends TestCase
|
|
{
|
|
// use RefreshDatabase;
|
|
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('https://dev2.eatvio.com/ru');
|
|
}
|
|
|
|
public function test_publish_new_plan_success(): void
|
|
{
|
|
$countPlanBeforeCreated = $this->plan->count();
|
|
|
|
$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)
|
|
->set('state', $this->plan->state)
|
|
->set('type', $this->plan->type)
|
|
->set('details', $this->plan->details)
|
|
->set('packets_count', $this->plan->packets_count)
|
|
->set('packet1_options', $this->plan->packet1_options)
|
|
->set('packet2_options', $this->plan->packet2_options)
|
|
->set('packet3_options', $this->plan->packet3_options)
|
|
->call('publish')
|
|
// ->assertFileDownloaded('plan.png');
|
|
->assertStatus(200)
|
|
->assertRedirect('plan/'.$this->plan->count());
|
|
|
|
$countPlanAfterCreated = $this->plan->count();
|
|
|
|
|
|
$this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated);
|
|
}
|
|
//
|
|
public function test_to_draft_new_plan_success(): void
|
|
{
|
|
$countPlanBeforeCreated = $this->plan->count();
|
|
|
|
$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)
|
|
->set('state', $this->plan->state)
|
|
->set('type', $this->plan->type)
|
|
->set('details', $this->plan->details)
|
|
->set('packets_count', $this->plan->packets_count)
|
|
->set('packet1_options', $this->plan->packet1_options)
|
|
->set('packet2_options', $this->plan->packet2_options)
|
|
->set('packet3_options', $this->plan->packet3_options)
|
|
->call('addToDrafts')
|
|
// ->assertFileDownloaded('plan.png');
|
|
->assertStatus(200)
|
|
->assertRedirect('plan/'.$this->plan->count());
|
|
|
|
$countPlanAfterCreated = $this->plan->count();
|
|
|
|
$this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated);
|
|
}
|
|
//
|
|
public function test_to_preview_new_plan_success(): void
|
|
{
|
|
|
|
$countPlanBeforeCreated = $this->plan->count();
|
|
|
|
$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)
|
|
->set('state', $this->plan->state)
|
|
->set('type', $this->plan->type)
|
|
->set('details', $this->plan->details)
|
|
->set('packets_count', $this->plan->packets_count)
|
|
->set('packet1_options', $this->plan->packet1_options)
|
|
->set('packet2_options', $this->plan->packet2_options)
|
|
->set('packet3_options', $this->plan->packet3_options)
|
|
->call('showPreview')
|
|
// ->assertFileDownloaded('plan.png');
|
|
->assertStatus(200)
|
|
->assertRedirect('plan/'.$this->plan->count());
|
|
|
|
$countPlanAfterCreated = $this->plan->count();
|
|
|
|
$this->assertEquals($countPlanBeforeCreated + 1, $countPlanAfterCreated);
|
|
}
|
|
|
|
}
|