forked from eatvio/eatvio-infra
65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Livewire\MealForm;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class MealFormTest extends TestCase
|
|
{
|
|
/** @test */
|
|
public function diary_creation_page_contains_livewire_component()
|
|
{
|
|
$this->refreshApplicationWithLocale('en');
|
|
|
|
$this->actingAs($this->user);
|
|
|
|
$response = $this->followingRedirects()->get(route('diary.index'));
|
|
$response->assertSeeLivewire('meal-form');
|
|
}
|
|
|
|
/** @test */
|
|
public function meal_form_productName_is_required()
|
|
{
|
|
$this->refreshApplicationWithLocale('en');
|
|
|
|
$this->actingAs($this->user);
|
|
$testDiary = $this->user->diaries->first();
|
|
|
|
Livewire::test(MealForm::class, ['diaryId' => $testDiary->id])
|
|
->set('product_name', '')
|
|
->call('addPortion')
|
|
->assertHasErrors(['product_name' => 'required']);
|
|
|
|
Livewire::test(MealForm::class, ['diaryId' => $testDiary->id])
|
|
->set('quantity', '')
|
|
->call('addPortion')
|
|
->assertHasErrors(['quantity' => 'required']);
|
|
|
|
Livewire::test(MealForm::class, ['diaryId' => $testDiary->id])
|
|
->set('portion', '')
|
|
->call('addPortion')
|
|
->assertHasErrors(['portion' => 'required']);
|
|
}
|
|
|
|
/** @test */
|
|
public function meal_form_add_portion()
|
|
{
|
|
$this->refreshApplicationWithLocale('en');
|
|
|
|
$this->actingAs($this->user);
|
|
$testDiary = $this->user->diaries->first();
|
|
|
|
Livewire::test(
|
|
MealForm::class,
|
|
['diaryId' => $testDiary->id]
|
|
)
|
|
->set('product_name', 'test product')
|
|
->set('quantity', '2')
|
|
->set('portion', 'pcs')
|
|
->call('addPortion')
|
|
->assertCount('portions', 1);
|
|
}
|
|
}
|