-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ff1b8a
commit 9097812
Showing
5 changed files
with
274 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature\Volunteers; | ||
|
||
use App\Enum\VolunteerSpecialization; | ||
use App\Filament\Resources\VolunteerResource\Pages\EditVolunteer; | ||
use App\Filament\Resources\VolunteerResource\Pages\ListVolunteers; | ||
use App\Filament\Resources\VolunteerResource\Pages\ViewVolunteer; | ||
use App\Models\Organisation; | ||
use App\Models\Volunteer; | ||
use Tests\Traits\ActingAsPlatformAdmin; | ||
|
||
class AdminPlatformTest extends VolunteersBaseTest | ||
{ | ||
use ActingAsPlatformAdmin; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->actingAsPlatformAdmin(); | ||
} | ||
|
||
public function testPlatformAdminCanViewVolunteers() | ||
{ | ||
$volunteers = Volunteer::query() | ||
->orderByDesc('id') | ||
->limit(10) | ||
->get(); | ||
|
||
$organisation = Organisation::query() | ||
->with('volunteers') | ||
->inRandomOrder() | ||
->first(); | ||
|
||
$county = $volunteers->first()->county; | ||
$volunteersFromCounty = Volunteer::query() | ||
->where('county_id', $county->id) | ||
->orderByDesc('id') | ||
->limit(10) | ||
->get(); | ||
|
||
$specialization = fake()->randomElements(VolunteerSpecialization::values()); | ||
$specializationVolunteers = Volunteer::query() | ||
->whereJsonContains('specializations', $specialization) | ||
->orderByDesc('id') | ||
->limit(10) | ||
->get(); | ||
|
||
$hasFirstAid = fake()->boolean; | ||
$firstAidVolunteers = Volunteer::query() | ||
->where('has_first_aid_accreditation', $hasFirstAid) | ||
->orderByDesc('id') | ||
->limit(10) | ||
->get(); | ||
|
||
\Livewire::test(ListVolunteers::class) | ||
->assertSuccessful() | ||
->assertCountTableRecords(25) | ||
->assertCanSeeTableRecords($volunteers) | ||
->assertCanRenderTableColumn('organisation.name') | ||
->assertCanRenderTableColumn('full_name') | ||
->assertCanRenderTableColumn('email') | ||
->assertCanRenderTableColumn('phone') | ||
->assertCanRenderTableColumn('specializations') | ||
->assertCanRenderTableColumn('has_first_aid_accreditation') | ||
->filterTable('organisation', $organisation->id) | ||
->assertCanSeeTableRecords($organisation->volunteers) | ||
->resetTableFilters() | ||
->filterTable('county', $county->id) | ||
->assertCanSeeTableRecords($volunteersFromCounty) | ||
->resetTableFilters() | ||
->filterTable('specializations', $specialization) | ||
->assertCanSeeTableRecords($specializationVolunteers) | ||
->resetTableFilters() | ||
->filterTable('has_first_aid_accreditation', $hasFirstAid) | ||
->assertCanSeeTableRecords($firstAidVolunteers) | ||
->assertPageActionVisible('create') | ||
->assertPageActionEnabled('create'); | ||
} | ||
|
||
public function testAdminPlatformCanViewVolunteer() | ||
{ | ||
$volunteer = Volunteer::query() | ||
->whereJsonDoesntContain('specializations', VolunteerSpecialization::translator) | ||
->inRandomOrder() | ||
->first(); | ||
|
||
\Livewire::test(ViewVolunteer::class, ['record' => $volunteer->id]) | ||
->assertSuccessful() | ||
->assertFormFieldIsVisible('organisation_id') | ||
->assertFormFieldIsDisabled('organisation_id') | ||
->assertFormFieldIsVisible('first_name') | ||
->assertFormFieldIsDisabled('first_name') | ||
->assertFormFieldIsVisible('last_name') | ||
->assertFormFieldIsDisabled('last_name') | ||
->assertFormFieldIsVisible('email') | ||
->assertFormFieldIsDisabled('email') | ||
->assertFormFieldIsVisible('phone') | ||
->assertFormFieldIsDisabled('phone') | ||
->assertFormFieldIsVisible('cnp') | ||
->assertFormFieldIsDisabled('cnp') | ||
->assertFormFieldIsVisible('role') | ||
->assertFormFieldIsDisabled('role') | ||
->assertFormFieldIsVisible('specializations') | ||
->assertFormFieldIsDisabled('specializations') | ||
->assertFormFieldIsVisible('has_first_aid_accreditation') | ||
->assertFormFieldIsDisabled('has_first_aid_accreditation') | ||
->assertFormFieldIsVisible('county_id') | ||
->assertFormFieldIsDisabled('county_id') | ||
->assertFormFieldIsVisible('city_id') | ||
->assertFormFieldIsDisabled('city_id') | ||
->assertPageActionVisible('edit') | ||
->assertPageActionEnabled('edit') | ||
->assertFormFieldIsHidden('language'); | ||
|
||
$volunteerTranslator = Volunteer::query() | ||
->whereJsonContains('specializations', VolunteerSpecialization::translator) | ||
->inRandomOrder() | ||
->first(); | ||
|
||
\Livewire::test(ViewVolunteer::class, ['record' => $volunteerTranslator->id]) | ||
->assertSuccessful() | ||
->assertFormFieldIsVisible('organisation_id') | ||
->assertFormFieldIsDisabled('organisation_id') | ||
->assertFormFieldIsVisible('first_name') | ||
->assertFormFieldIsDisabled('first_name') | ||
->assertFormFieldIsVisible('last_name') | ||
->assertFormFieldIsDisabled('last_name') | ||
->assertFormFieldIsVisible('email') | ||
->assertFormFieldIsDisabled('email') | ||
->assertFormFieldIsVisible('phone') | ||
->assertFormFieldIsDisabled('phone') | ||
->assertFormFieldIsVisible('cnp') | ||
->assertFormFieldIsDisabled('cnp') | ||
->assertFormFieldIsVisible('role') | ||
->assertFormFieldIsDisabled('role') | ||
->assertFormFieldIsVisible('specializations') | ||
->assertFormFieldIsDisabled('specializations') | ||
->assertFormFieldIsVisible('language') | ||
->assertFormFieldIsDisabled('language') | ||
->assertFormFieldIsVisible('has_first_aid_accreditation') | ||
->assertFormFieldIsDisabled('has_first_aid_accreditation') | ||
->assertFormFieldIsVisible('county_id') | ||
->assertFormFieldIsDisabled('county_id') | ||
->assertFormFieldIsVisible('city_id') | ||
->assertFormFieldIsDisabled('city_id') | ||
->assertPageActionVisible('edit') | ||
->assertPageActionEnabled('edit'); | ||
} | ||
|
||
public function testAdminPlatformCanEditVolunteer() | ||
{ | ||
$volunteer = Volunteer::query() | ||
->whereJsonDoesntContain('specializations', VolunteerSpecialization::translator) | ||
->inRandomOrder() | ||
->first(); | ||
|
||
\Livewire::test(EditVolunteer::class, ['record' => $volunteer->id]) | ||
->assertSuccessful() | ||
->assertFormFieldIsVisible('organisation_id') | ||
->assertFormFieldIsEnabled('organisation_id') | ||
->assertFormFieldIsVisible('first_name') | ||
->assertFormFieldIsEnabled('first_name') | ||
->assertFormFieldIsVisible('last_name') | ||
->assertFormFieldIsEnabled('last_name') | ||
->assertFormFieldIsVisible('email') | ||
->assertFormFieldIsEnabled('email') | ||
->assertFormFieldIsVisible('phone') | ||
->assertFormFieldIsEnabled('phone') | ||
->assertFormFieldIsVisible('cnp') | ||
->assertFormFieldIsEnabled('cnp') | ||
->assertFormFieldIsVisible('role') | ||
->assertFormFieldIsEnabled('role') | ||
->assertFormFieldIsVisible('specializations') | ||
->assertFormFieldIsEnabled('specializations') | ||
->assertFormFieldIsHidden('language') | ||
// ->assertFormFieldIsDisabled('language') | ||
->assertFormFieldIsVisible('has_first_aid_accreditation') | ||
->assertFormFieldIsEnabled('has_first_aid_accreditation') | ||
->assertFormFieldIsVisible('county_id') | ||
->assertFormFieldIsEnabled('county_id') | ||
->assertFormFieldIsVisible('city_id') | ||
->assertFormFieldIsEnabled('city_id') | ||
|
||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature\Volunteers; | ||
|
||
use App\Enum\DocumentType; | ||
use App\Enum\OrganisationStatus; | ||
use App\Enum\UserRole; | ||
use App\Filament\Resources\DocumentResource; | ||
use App\Models\Document; | ||
use App\Models\Organisation; | ||
use App\Models\User; | ||
use Database\Seeders\ResourceCategorySeed; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Notification; | ||
use Livewire; | ||
use Tests\TestCase; | ||
|
||
abstract class VolunteersBaseTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
protected string $seeder = ResourceCategorySeed::class; | ||
|
||
protected User $user; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Notification::fake(); | ||
$this->createOrganisationsWithVolunteers(); | ||
} | ||
|
||
protected function createOrganisationsWithVolunteers() | ||
{ | ||
Organisation::factory() | ||
->count(5) | ||
->withUserAndVolunteers() | ||
->create(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Tests\Traits; | ||
|
||
use App\Models\User; | ||
|
||
trait ActingAsPlatformAdmin | ||
{ | ||
public function getUser(): User | ||
{ | ||
return User::factory() | ||
->platformAdmin() | ||
->create(); | ||
} | ||
|
||
public function actingAsPlatformAdmin(): void | ||
{ | ||
$this->actingAs($this->getUser()); | ||
} | ||
} |