NormsGroupTest.php
1 <?php 2 3 namespace Tests\Feature\Livewire\Norms; 4 5 use App\Models\User; 6 use App\Http\Livewire\Norms\Group\Index; 7 use App\Http\Livewire\Norms\Group\Update; 8 use App\Models\NormGroup; 9 use Illuminate\Foundation\Testing\WithFaker; 10 use Livewire\Livewire; 11 use Tests\TestCase; 12 13 class NormsGroupTest extends TestCase 14 { 15 use WithFaker; 16 17 public User $admin; 18 public User $worker; 19 public NormGroup $normGroup; 20 21 public function setUp(): void 22 { 23 parent::setUp(); 24 $this->admin = $this->getAdminUser(); 25 $this->worker = $this->getWorkerUser(); 26 $this->normGroup = NormGroup::factory()->create(); 27 $this->actingAs($this->admin); 28 } 29 30 /** @test */ 31 public function test_read_norm_groups() 32 { 33 $this->get('/norms/groups')->assertSeeLivewire(Index::class); 34 $this->actingAs($this->worker); 35 $this->get('/norms/groups')->assertDontSeeLivewire(Index::class); 36 } 37 38 /** @test */ 39 public function test_can_edit_norm_group() 40 { 41 $data = NormGroup::factory()->make()->toArray(); 42 43 Livewire::test(Update::class, [ 'entityId' => $this->normGroup->id, ]) 44 ->set('norm', $data) 45 ->call('update'); 46 47 $this->assertDatabaseHas('norm_groups', $data); 48 $this->assertDatabaseMissing('norm_groups', $this->normGroup->toArray()); 49 } 50 }