ViewTest.php
1 <?php 2 3 namespace Tests\Feature\Livewire\Users; 4 5 use App\Http\Livewire\Users\View; 6 use App\Models\EvaluatorSkill; 7 use App\Models\User; 8 use Livewire\Livewire; 9 use Tests\TestCase; 10 11 class ViewTest extends TestCase 12 { 13 private User $admin; 14 15 private User $worker; 16 17 private User $user; 18 19 private EvaluatorSkill $skill; 20 21 public function setUp(): void 22 { 23 parent::setUp(); 24 $this->admin = $this->getAdminUser(); 25 $this->worker = $this->getWorkerUser(); 26 $this->user = User::factory()->create()->assignRole('worker'); 27 $this->skill = EvaluatorSkill::factory()->create([ 28 'evaluator_id' => $this->user->id, 29 ]); 30 } 31 32 /** @test */ 33 public function can_see_the_details_of_a_user() 34 { 35 //GIVEN: A user with the role root and a user created 36 $this->actingAs($this->admin); 37 38 //WHEN: The user call the component 39 $component = Livewire::test(View::class, [ 40 'user' => $this->user, 41 ]); 42 43 //THEN: The details of the user are displayed 44 $component->assertSeeInOrder([$this->user->name, $this->user->email]); 45 } 46 47 /** @test */ 48 public function can_see_the_skill_of_a_user() 49 { 50 //GIVEN: A user with the role root and a user created 51 $this->actingAs($this->admin); 52 53 //WHEN: The user call the component 54 $component = Livewire::test(View::class, [ 55 'user' => $this->user, 56 ]) 57 ->set('readyToLoad', true) 58 ->call('getSkillsProperty'); 59 60 //THEN: The details of the user are displayed 61 $component->assertSee($this->skill->normScope->name); 62 } 63 }