Remove deprecated resource test files for Classifications, Departments, Locations, SubClassifications, SubLocations, Themes, and Users to streamline the test suite and improve maintainability.
This commit is contained in:
parent
968af2c1c7
commit
2c90380d3b
@ -1,199 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Resources\Master\Classifications\Pages\ManageClassifications;
|
||||
use App\Models\Classification;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
// Setup Permissions
|
||||
Permission::firstOrCreate(['name' => 'ViewAny:Classification', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Create:Classification', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Update:Classification', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Delete:Classification', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Restore:Classification', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'ForceDelete:Classification', 'guard_name' => 'web']);
|
||||
|
||||
$this->user->givePermissionTo([
|
||||
'ViewAny:Classification',
|
||||
'Create:Classification',
|
||||
'Update:Classification',
|
||||
'Delete:Classification',
|
||||
'Restore:Classification',
|
||||
'ForceDelete:Classification',
|
||||
]);
|
||||
});
|
||||
|
||||
test('can render classification list page', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->assertSuccessful();
|
||||
});
|
||||
|
||||
test('can list classifications', function () {
|
||||
$classifications = Classification::factory()->count(5)->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->call('loadTable')
|
||||
->assertCanSeeTableRecords($classifications);
|
||||
});
|
||||
|
||||
test('can create classification', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->mountAction('create')
|
||||
->setActionData([
|
||||
'name' => 'Klasifikasi Baru',
|
||||
])
|
||||
->callMountedAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$this->assertDatabaseHas('classifications', [
|
||||
'name' => 'Klasifikasi Baru',
|
||||
'is_active' => IsActive::ACTIVE->value,
|
||||
]);
|
||||
});
|
||||
|
||||
test('cannot create classification with empty name', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => ''])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['name' => 'required']);
|
||||
});
|
||||
|
||||
test('cannot create classification with name exceeding 50 characters', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => str_repeat('a', 51)])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['name' => 'max']);
|
||||
});
|
||||
|
||||
test('can edit classification', function () {
|
||||
$classification = Classification::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->mountTableAction('edit', $classification)
|
||||
->setActionData([
|
||||
'name' => 'Klasifikasi Updated',
|
||||
])
|
||||
->callMountedTableAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
expect($classification->refresh()->name)->toBe('Klasifikasi Updated');
|
||||
});
|
||||
|
||||
test('can toggle is_active status', function () {
|
||||
$classification = Classification::factory()->create(['is_active' => IsActive::INACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->call('updateTableColumnState', 'is_active', $classification->getKey(), true);
|
||||
|
||||
expect($classification->refresh()->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
|
||||
test('unauthorized user cannot render classification page', function () {
|
||||
$unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($unauthorizedUser);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('user without create permission cannot see create action', function () {
|
||||
$viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
$viewOnlyUser->givePermissionTo('ViewAny:Classification');
|
||||
$classification = Classification::factory()->create();
|
||||
|
||||
$this->actingAs($viewOnlyUser);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->assertActionHidden('create')
|
||||
->assertTableActionHidden('edit', $classification);
|
||||
});
|
||||
|
||||
test('can delete classification', function () {
|
||||
$classification = Classification::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->callTableAction('delete', $classification);
|
||||
|
||||
$this->assertSoftDeleted($classification);
|
||||
});
|
||||
|
||||
test('can restore deleted classification', function () {
|
||||
// Need Developer role to see trashed records via filter
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$classification = Classification::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->filterTable('trashed', 'with')
|
||||
->callTableAction('restore', $classification);
|
||||
|
||||
$this->assertDatabaseHas('classifications', [
|
||||
'id' => $classification->id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can force delete classification', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$classification = Classification::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->filterTable('trashed', 'only')
|
||||
->callTableAction('forceDelete', $classification);
|
||||
|
||||
$this->assertDatabaseMissing('classifications', ['id' => $classification->id]);
|
||||
});
|
||||
|
||||
test('trashed filter visibility depends on developer role', function () {
|
||||
// Administrator but not Developer
|
||||
$roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleAdmin);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->assertTableFilterHidden('trashed');
|
||||
|
||||
// Upgrade to Developer
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
Livewire::test(ManageClassifications::class)
|
||||
->assertTableFilterVisible('trashed');
|
||||
});
|
||||
@ -1,222 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Resources\Master\Departments\Pages\ManageDepartments;
|
||||
use App\Models\Department;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
// Setup Permissions
|
||||
Permission::firstOrCreate(['name' => 'ViewAny:Department', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Create:Department', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Update:Department', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Delete:Department', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Restore:Department', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'ForceDelete:Department', 'guard_name' => 'web']);
|
||||
|
||||
$this->user->givePermissionTo([
|
||||
'ViewAny:Department',
|
||||
'Create:Department',
|
||||
'Update:Department',
|
||||
'Delete:Department',
|
||||
'Restore:Department',
|
||||
'ForceDelete:Department',
|
||||
]);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Positive Scenarios
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('can render department list page', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->assertSuccessful();
|
||||
});
|
||||
|
||||
test('can list departments', function () {
|
||||
$departments = Department::factory()->count(5)->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->call('loadTable')
|
||||
->assertCanSeeTableRecords($departments);
|
||||
});
|
||||
|
||||
test('can create department', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->mountAction('create')
|
||||
->setActionData([
|
||||
'name' => 'Dinas Pendidikan',
|
||||
'alias' => 'Disdik',
|
||||
])
|
||||
->callMountedAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$this->assertDatabaseHas('departments', [
|
||||
'name' => 'Dinas Pendidikan',
|
||||
'alias' => 'Disdik',
|
||||
'is_active' => IsActive::ACTIVE->value,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can edit department', function () {
|
||||
$department = Department::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->mountTableAction('edit', $department)
|
||||
->setActionData([
|
||||
'name' => 'OPD Baru Updated',
|
||||
'alias' => 'OPD-U',
|
||||
])
|
||||
->callMountedTableAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
expect($department->refresh()->name)->toBe('OPD Baru Updated');
|
||||
});
|
||||
|
||||
test('can toggle is_active status', function () {
|
||||
$department = Department::factory()->create(['is_active' => IsActive::INACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->call('updateTableColumnState', 'is_active', $department->getKey(), true);
|
||||
|
||||
expect($department->refresh()->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Negative Scenarios (Validation & Authorization)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('cannot create department with invalid data', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
// Empty name & alias
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => '', 'alias' => ''])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['name' => 'required', 'alias' => 'required']);
|
||||
|
||||
// Name exceeding 100 chars
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => str_repeat('a', 101), 'alias' => 'Short'])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['name' => 'max']);
|
||||
|
||||
// Alias exceeding 20 chars
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => 'Valid Name', 'alias' => str_repeat('a', 21)])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['alias' => 'max']);
|
||||
});
|
||||
|
||||
test('unauthorized user cannot render department page', function () {
|
||||
$unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($unauthorizedUser);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('user without permissions cannot see actions', function () {
|
||||
$viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
$viewOnlyUser->givePermissionTo('ViewAny:Department');
|
||||
$department = Department::factory()->create();
|
||||
|
||||
$this->actingAs($viewOnlyUser);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->assertActionHidden('create')
|
||||
->assertTableActionHidden('edit', $department);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Soft Delete Scenarios
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('can delete department', function () {
|
||||
$department = Department::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->callTableAction('delete', $department);
|
||||
|
||||
$this->assertSoftDeleted($department);
|
||||
});
|
||||
|
||||
test('can restore deleted department', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$department = Department::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->filterTable('trashed', 'with')
|
||||
->callTableAction('restore', $department);
|
||||
|
||||
$this->assertDatabaseHas('departments', [
|
||||
'id' => $department->id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can force delete department', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$department = Department::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->filterTable('trashed', 'only')
|
||||
->callTableAction('forceDelete', $department);
|
||||
|
||||
$this->assertDatabaseMissing('departments', ['id' => $department->id]);
|
||||
});
|
||||
|
||||
test('trashed filter visibility depends on developer role', function () {
|
||||
$roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleAdmin);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->assertTableFilterHidden('trashed');
|
||||
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
Livewire::test(ManageDepartments::class)
|
||||
->assertTableFilterVisible('trashed');
|
||||
});
|
||||
@ -1,214 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Resources\Master\Locations\Pages\ManageLocations;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
// Setup Permissions
|
||||
Permission::firstOrCreate(['name' => 'ViewAny:Location', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Create:Location', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Update:Location', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Delete:Location', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Restore:Location', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'ForceDelete:Location', 'guard_name' => 'web']);
|
||||
|
||||
$this->user->givePermissionTo([
|
||||
'ViewAny:Location',
|
||||
'Create:Location',
|
||||
'Update:Location',
|
||||
'Delete:Location',
|
||||
'Restore:Location',
|
||||
'ForceDelete:Location',
|
||||
]);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Positive Scenarios
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('can render location list page', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->assertSuccessful();
|
||||
});
|
||||
|
||||
test('can list locations', function () {
|
||||
$locations = Location::factory()->count(5)->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->call('loadTable')
|
||||
->assertCanSeeTableRecords($locations);
|
||||
});
|
||||
|
||||
test('can create location', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->mountAction('create')
|
||||
->setActionData([
|
||||
'name' => 'Lokus Baru',
|
||||
])
|
||||
->callMountedAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$this->assertDatabaseHas('locations', [
|
||||
'name' => 'Lokus Baru',
|
||||
'is_active' => IsActive::ACTIVE->value,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can edit location', function () {
|
||||
$location = Location::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->mountTableAction('edit', $location)
|
||||
->setActionData([
|
||||
'name' => 'Lokus Updated',
|
||||
])
|
||||
->callMountedTableAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
expect($location->refresh()->name)->toBe('Lokus Updated');
|
||||
});
|
||||
|
||||
test('can toggle is_active status', function () {
|
||||
$location = Location::factory()->create(['is_active' => IsActive::INACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->call('updateTableColumnState', 'is_active', $location->getKey(), true);
|
||||
|
||||
expect($location->refresh()->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Negative Scenarios (Validation & Authorization)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('cannot create location with empty name', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => ''])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['name' => 'required']);
|
||||
});
|
||||
|
||||
test('cannot create location with name exceeding 50 characters', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => str_repeat('a', 51)])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['name' => 'max']);
|
||||
});
|
||||
|
||||
test('unauthorized user cannot render location page', function () {
|
||||
$unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($unauthorizedUser);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('user without create permission cannot see create action', function () {
|
||||
$viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
$viewOnlyUser->givePermissionTo('ViewAny:Location');
|
||||
$location = Location::factory()->create();
|
||||
|
||||
$this->actingAs($viewOnlyUser);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->assertActionHidden('create')
|
||||
->assertTableActionHidden('edit', $location);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Soft Delete Scenarios
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('can delete location', function () {
|
||||
$location = Location::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->callTableAction('delete', $location);
|
||||
|
||||
$this->assertSoftDeleted($location);
|
||||
});
|
||||
|
||||
test('can restore deleted location', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$location = Location::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->filterTable('trashed', 'with')
|
||||
->callTableAction('restore', $location);
|
||||
|
||||
$this->assertDatabaseHas('locations', [
|
||||
'id' => $location->id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can force delete location', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$location = Location::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->filterTable('trashed', 'only')
|
||||
->callTableAction('forceDelete', $location);
|
||||
|
||||
$this->assertDatabaseMissing('locations', ['id' => $location->id]);
|
||||
});
|
||||
|
||||
test('trashed filter visibility depends on developer role', function () {
|
||||
$roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleAdmin);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->assertTableFilterHidden('trashed');
|
||||
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
Livewire::test(ManageLocations::class)
|
||||
->assertTableFilterVisible('trashed');
|
||||
});
|
||||
@ -1,200 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Resources\Master\SubClassifications\Pages\ManageSubClassifications;
|
||||
use App\Models\Classification;
|
||||
use App\Models\SubClassification;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
// Setup Permissions
|
||||
Permission::firstOrCreate(['name' => 'ViewAny:SubClassification', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Create:SubClassification', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Update:SubClassification', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Delete:SubClassification', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Restore:SubClassification', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'ForceDelete:SubClassification', 'guard_name' => 'web']);
|
||||
|
||||
$this->user->givePermissionTo([
|
||||
'ViewAny:SubClassification',
|
||||
'Create:SubClassification',
|
||||
'Update:SubClassification',
|
||||
'Delete:SubClassification',
|
||||
'Restore:SubClassification',
|
||||
'ForceDelete:SubClassification',
|
||||
]);
|
||||
});
|
||||
|
||||
test('can render subklasifikasi list page', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->assertSuccessful();
|
||||
});
|
||||
|
||||
test('can list subklasifikasi', function () {
|
||||
$subClassifications = SubClassification::factory()->count(5)->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->call('loadTable')
|
||||
->assertCanSeeTableRecords($subClassifications);
|
||||
});
|
||||
|
||||
test('can create subklasifikasi', function () {
|
||||
$classification = Classification::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->mountAction('create')
|
||||
->setActionData([
|
||||
'classification_id' => $classification->id,
|
||||
'name' => 'Subklasifikasi Baru',
|
||||
])
|
||||
->callMountedAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$this->assertDatabaseHas('sub_classifications', [
|
||||
'classification_id' => $classification->id,
|
||||
'name' => 'Subklasifikasi Baru',
|
||||
]);
|
||||
});
|
||||
|
||||
test('cannot create subklasifikasi with invalid data', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
// Empty name
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => '', 'classification_id' => null])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['name' => 'required', 'classification_id' => 'required']);
|
||||
|
||||
// Non-existent classification
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => 'Valid Name', 'classification_id' => 999999])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['classification_id']);
|
||||
});
|
||||
|
||||
test('can edit subklasifikasi', function () {
|
||||
$subClassification = SubClassification::factory()->create();
|
||||
$newClassification = Classification::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->mountTableAction('edit', $subClassification)
|
||||
->setActionData([
|
||||
'classification_id' => $newClassification->id,
|
||||
'name' => 'Subklasifikasi Updated',
|
||||
])
|
||||
->callMountedTableAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
expect($subClassification->refresh()->name)->toBe('Subklasifikasi Updated');
|
||||
expect($subClassification->classification_id)->toBe($newClassification->id);
|
||||
});
|
||||
|
||||
test('can toggle is_active status', function () {
|
||||
$subClassification = SubClassification::factory()->create(['is_active' => IsActive::INACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->call('updateTableColumnState', 'is_active', $subClassification->getKey(), true);
|
||||
|
||||
expect($subClassification->refresh()->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
|
||||
test('unauthorized user cannot render subklasifikasi page', function () {
|
||||
$unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($unauthorizedUser);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('user without update permission cannot see edit action', function () {
|
||||
$viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
$viewOnlyUser->givePermissionTo('ViewAny:SubClassification');
|
||||
$subClassification = SubClassification::factory()->create();
|
||||
|
||||
$this->actingAs($viewOnlyUser);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->assertTableActionHidden('edit', $subClassification);
|
||||
});
|
||||
|
||||
test('can delete subklasifikasi', function () {
|
||||
$subClassification = SubClassification::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->callTableAction('delete', $subClassification);
|
||||
|
||||
$this->assertSoftDeleted($subClassification);
|
||||
});
|
||||
|
||||
test('can restore deleted subklasifikasi', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$subClassification = SubClassification::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->filterTable('trashed', 'with')
|
||||
->callTableAction('restore', $subClassification);
|
||||
|
||||
$this->assertDatabaseHas('sub_classifications', [
|
||||
'id' => $subClassification->id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can force delete subklasifikasi', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$subClassification = SubClassification::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->filterTable('trashed', 'only')
|
||||
->callTableAction('forceDelete', $subClassification);
|
||||
|
||||
$this->assertDatabaseMissing('sub_classifications', ['id' => $subClassification->id]);
|
||||
});
|
||||
|
||||
test('trashed filter visibility depends on developer role', function () {
|
||||
$roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleAdmin);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->assertTableFilterHidden('trashed');
|
||||
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
Livewire::test(ManageSubClassifications::class)
|
||||
->assertTableFilterVisible('trashed');
|
||||
});
|
||||
@ -1,218 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Resources\Master\SubLocations\Pages\ManageSubLocations;
|
||||
use App\Models\Location;
|
||||
use App\Models\SubLocation;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
// Setup Permissions
|
||||
Permission::firstOrCreate(['name' => 'ViewAny:SubLocation', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Create:SubLocation', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Update:SubLocation', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Delete:SubLocation', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Restore:SubLocation', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'ForceDelete:SubLocation', 'guard_name' => 'web']);
|
||||
|
||||
$this->user->givePermissionTo([
|
||||
'ViewAny:SubLocation',
|
||||
'Create:SubLocation',
|
||||
'Update:SubLocation',
|
||||
'Delete:SubLocation',
|
||||
'Restore:SubLocation',
|
||||
'ForceDelete:SubLocation',
|
||||
]);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Positive Scenarios
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('can render sublokus list page', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->assertSuccessful();
|
||||
});
|
||||
|
||||
test('can list sublokus', function () {
|
||||
$subLocations = SubLocation::factory()->count(5)->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->call('loadTable')
|
||||
->assertCanSeeTableRecords($subLocations);
|
||||
});
|
||||
|
||||
test('can create sublokus', function () {
|
||||
$location = Location::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->mountAction('create')
|
||||
->setActionData([
|
||||
'location_id' => $location->id,
|
||||
'name' => 'Sublokus Baru',
|
||||
])
|
||||
->callMountedAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$this->assertDatabaseHas('sub_locations', [
|
||||
'location_id' => $location->id,
|
||||
'name' => 'Sublokus Baru',
|
||||
]);
|
||||
});
|
||||
|
||||
test('can edit sublokus', function () {
|
||||
$subLocation = SubLocation::factory()->create();
|
||||
$newLocation = Location::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->mountTableAction('edit', $subLocation)
|
||||
->setActionData([
|
||||
'location_id' => $newLocation->id,
|
||||
'name' => 'Sublokus Updated',
|
||||
])
|
||||
->callMountedTableAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
expect($subLocation->refresh()->name)->toBe('Sublokus Updated');
|
||||
expect($subLocation->location_id)->toBe($newLocation->id);
|
||||
});
|
||||
|
||||
test('can toggle is_active status', function () {
|
||||
$subLocation = SubLocation::factory()->create(['is_active' => IsActive::INACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->call('updateTableColumnState', 'is_active', $subLocation->getKey(), true);
|
||||
|
||||
expect($subLocation->refresh()->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Negative Scenarios (Validation & Authorization)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('cannot create sublokus with invalid data', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
// Empty name
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => '', 'location_id' => null])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['name' => 'required', 'location_id' => 'required']);
|
||||
|
||||
// Non-existent location
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => 'Valid Name', 'location_id' => 999999])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['location_id']);
|
||||
});
|
||||
|
||||
test('unauthorized user cannot render sublokus page', function () {
|
||||
$unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($unauthorizedUser);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('user without update permission cannot see edit action', function () {
|
||||
$viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
$viewOnlyUser->givePermissionTo('ViewAny:SubLocation');
|
||||
$subLocation = SubLocation::factory()->create();
|
||||
|
||||
$this->actingAs($viewOnlyUser);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->assertTableActionHidden('edit', $subLocation);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Soft Delete Scenarios
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('can delete sublokus', function () {
|
||||
$subLocation = SubLocation::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->callTableAction('delete', $subLocation);
|
||||
|
||||
$this->assertSoftDeleted($subLocation);
|
||||
});
|
||||
|
||||
test('can restore deleted sublokus', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$subLocation = SubLocation::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->filterTable('trashed', 'with')
|
||||
->callTableAction('restore', $subLocation);
|
||||
|
||||
$this->assertDatabaseHas('sub_locations', [
|
||||
'id' => $subLocation->id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can force delete sublokus', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$subLocation = SubLocation::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->filterTable('trashed', 'only')
|
||||
->callTableAction('forceDelete', $subLocation);
|
||||
|
||||
$this->assertDatabaseMissing('sub_locations', ['id' => $subLocation->id]);
|
||||
});
|
||||
|
||||
test('trashed filter visibility depends on developer role', function () {
|
||||
$roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleAdmin);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->assertTableFilterHidden('trashed');
|
||||
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
Livewire::test(ManageSubLocations::class)
|
||||
->assertTableFilterVisible('trashed');
|
||||
});
|
||||
@ -1,214 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Resources\Master\Themes\Pages\ManageThemes;
|
||||
use App\Models\Theme;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
// Setup Permissions
|
||||
Permission::firstOrCreate(['name' => 'ViewAny:Theme', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Create:Theme', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Update:Theme', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Delete:Theme', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'Restore:Theme', 'guard_name' => 'web']);
|
||||
Permission::firstOrCreate(['name' => 'ForceDelete:Theme', 'guard_name' => 'web']);
|
||||
|
||||
$this->user->givePermissionTo([
|
||||
'ViewAny:Theme',
|
||||
'Create:Theme',
|
||||
'Update:Theme',
|
||||
'Delete:Theme',
|
||||
'Restore:Theme',
|
||||
'ForceDelete:Theme',
|
||||
]);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Positive Scenarios
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('can render theme list page', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->assertSuccessful();
|
||||
});
|
||||
|
||||
test('can list themes', function () {
|
||||
$themes = Theme::factory()->count(5)->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->call('loadTable')
|
||||
->assertCanSeeTableRecords($themes);
|
||||
});
|
||||
|
||||
test('can create theme', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->mountAction('create')
|
||||
->setActionData([
|
||||
'name' => 'Tema Pendidikan',
|
||||
])
|
||||
->callMountedAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$this->assertDatabaseHas('themes', [
|
||||
'name' => 'Tema Pendidikan',
|
||||
'is_active' => IsActive::ACTIVE->value,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can edit theme', function () {
|
||||
$theme = Theme::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->mountTableAction('edit', $theme)
|
||||
->setActionData([
|
||||
'name' => 'Tema Updated',
|
||||
])
|
||||
->callMountedTableAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
expect($theme->refresh()->name)->toBe('Tema Updated');
|
||||
});
|
||||
|
||||
test('can toggle is_active status', function () {
|
||||
$theme = Theme::factory()->create(['is_active' => IsActive::INACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->call('updateTableColumnState', 'is_active', $theme->getKey(), true);
|
||||
|
||||
expect($theme->refresh()->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Negative Scenarios (Validation & Authorization)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('cannot create theme with empty name', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => ''])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['name' => 'required']);
|
||||
});
|
||||
|
||||
test('cannot create theme with name exceeding 50 characters', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['name' => str_repeat('a', 51)])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['name' => 'max']);
|
||||
});
|
||||
|
||||
test('unauthorized user cannot render theme page', function () {
|
||||
$unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($unauthorizedUser);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('user without permissions cannot see actions', function () {
|
||||
$viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
$viewOnlyUser->givePermissionTo('ViewAny:Theme');
|
||||
$theme = Theme::factory()->create();
|
||||
|
||||
$this->actingAs($viewOnlyUser);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->assertActionHidden('create')
|
||||
->assertTableActionHidden('edit', $theme);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Soft Delete Scenarios
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
test('can delete theme', function () {
|
||||
$theme = Theme::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->callTableAction('delete', $theme);
|
||||
|
||||
$this->assertSoftDeleted($theme);
|
||||
});
|
||||
|
||||
test('can restore deleted theme', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$theme = Theme::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->filterTable('trashed', 'with')
|
||||
->callTableAction('restore', $theme);
|
||||
|
||||
$this->assertDatabaseHas('themes', [
|
||||
'id' => $theme->id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can force delete theme', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$theme = Theme::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->filterTable('trashed', 'only')
|
||||
->callTableAction('forceDelete', $theme);
|
||||
|
||||
$this->assertDatabaseMissing('themes', ['id' => $theme->id]);
|
||||
});
|
||||
|
||||
test('trashed filter visibility depends on developer role', function () {
|
||||
$roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleAdmin);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->assertTableFilterHidden('trashed');
|
||||
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
Livewire::test(ManageThemes::class)
|
||||
->assertTableFilterVisible('trashed');
|
||||
});
|
||||
@ -1,245 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Resources\Master\Users\Pages\ManageUsers;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
// Setup Permissions
|
||||
$permissions = [
|
||||
'ViewAny:User',
|
||||
'Create:User',
|
||||
'Update:User',
|
||||
'Delete:User',
|
||||
'Restore:User',
|
||||
'ForceDelete:User',
|
||||
];
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
Permission::firstOrCreate(['name' => $permission, 'guard_name' => 'web']);
|
||||
}
|
||||
|
||||
$this->user->givePermissionTo($permissions);
|
||||
|
||||
// Create a default role for testing
|
||||
Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']);
|
||||
});
|
||||
|
||||
test('can render user list page', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->assertSuccessful();
|
||||
});
|
||||
|
||||
test('can list users', function () {
|
||||
$users = User::factory()->count(5)->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->call('loadTable')
|
||||
->assertCanSeeTableRecords($users);
|
||||
});
|
||||
|
||||
test('cannot see developers in the list', function () {
|
||||
$devRole = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$developer = User::factory()->create();
|
||||
$developer->assignRole($devRole);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->call('loadTable')
|
||||
->assertCanNotSeeTableRecords([$developer]);
|
||||
});
|
||||
|
||||
test('can create user', function () {
|
||||
$role = Role::where('name', RoleEnum::ADMINISTRATOR->value)->first();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->mountAction('create')
|
||||
->setActionData([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
'username' => 'testuser',
|
||||
'roles' => [$role->id],
|
||||
])
|
||||
->callMountedAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
'username' => 'testuser',
|
||||
'is_active' => IsActive::ACTIVE->value,
|
||||
]);
|
||||
|
||||
$newUser = User::where('email', 'test@example.com')->first();
|
||||
expect($newUser->roles->pluck('id'))->toContain($role->id);
|
||||
});
|
||||
|
||||
test('validation: required fields', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->mountAction('create')
|
||||
->setActionData([
|
||||
'name' => '',
|
||||
'email' => '',
|
||||
'username' => '',
|
||||
'roles' => [],
|
||||
])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors([
|
||||
'name' => 'required',
|
||||
'email' => 'required',
|
||||
'username' => 'required',
|
||||
'roles' => 'required',
|
||||
]);
|
||||
});
|
||||
|
||||
test('validation: username length and format', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
// Too short
|
||||
Livewire::test(ManageUsers::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['username' => 'abc'])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['username' => 'min']);
|
||||
|
||||
// Invalid format
|
||||
Livewire::test(ManageUsers::class)
|
||||
->mountAction('create')
|
||||
->setActionData(['username' => 'user name'])
|
||||
->callMountedAction()
|
||||
->assertHasActionErrors(['username' => 'regex']);
|
||||
});
|
||||
|
||||
test('can edit user', function () {
|
||||
$userToEdit = User::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$role = Role::where('name', RoleEnum::ADMINISTRATOR->value)->first();
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->mountTableAction('edit', $userToEdit)
|
||||
->setActionData([
|
||||
'name' => 'Updated Name',
|
||||
'roles' => [$role->id],
|
||||
])
|
||||
->callMountedTableAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
expect($userToEdit->refresh()->name)->toBe('Updated Name');
|
||||
});
|
||||
|
||||
test('can change user password', function () {
|
||||
$userToModify = User::factory()->create();
|
||||
$oldPassword = $userToModify->password;
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->mountTableAction('changePassword', $userToModify)
|
||||
->setActionData([
|
||||
'password' => 'newpassword123',
|
||||
])
|
||||
->callMountedTableAction()
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$userToModify->refresh();
|
||||
expect(Hash::check('newpassword123', $userToModify->password))->toBeTrue();
|
||||
expect($userToModify->password)->not->toBe($oldPassword);
|
||||
});
|
||||
|
||||
test('can toggle user active status', function () {
|
||||
$userToToggle = User::factory()->create(['is_active' => IsActive::INACTIVE]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->call('updateTableColumnState', 'is_active', $userToToggle->getKey(), true);
|
||||
|
||||
expect($userToToggle->refresh()->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
|
||||
test('cannot toggle active status for company role', function () {
|
||||
$companyRole = Role::firstOrCreate(['name' => RoleEnum::PERUSAHAAN->value, 'guard_name' => 'web']);
|
||||
$companyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
$companyUser->assignRole($companyRole);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->call('updateTableColumnState', 'is_active', $companyUser->getKey(), false);
|
||||
|
||||
expect($companyUser->refresh()->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
|
||||
test('unauthorized user cannot render user page', function () {
|
||||
$unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
$this->actingAs($unauthorizedUser);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('can delete user', function () {
|
||||
$userToDelete = User::factory()->create();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->callTableAction('delete', $userToDelete);
|
||||
|
||||
$this->assertSoftDeleted($userToDelete);
|
||||
});
|
||||
|
||||
test('can restore deleted user', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$userToRestore = User::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->filterTable('trashed', 'with')
|
||||
->callTableAction('restore', $userToRestore);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $userToRestore->id,
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can force delete user', function () {
|
||||
$roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']);
|
||||
$this->user->assignRole($roleDev);
|
||||
|
||||
$userToForceDelete = User::factory()->create(['deleted_at' => now()]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Livewire::test(ManageUsers::class)
|
||||
->filterTable('trashed', 'only')
|
||||
->callTableAction('forceDelete', $userToForceDelete);
|
||||
|
||||
$this->assertDatabaseMissing('users', ['id' => $userToForceDelete->id]);
|
||||
});
|
||||
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Announcement;
|
||||
use App\Models\AnnouncementMedia;
|
||||
use App\Models\PartnerMedia;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('announcement media relation works', function () {
|
||||
$announcement = Announcement::factory()->create();
|
||||
$media = PartnerMedia::factory()->create();
|
||||
$announcementMedia = AnnouncementMedia::factory()->create([
|
||||
'announcement_id' => $announcement->id,
|
||||
'partner_media_id' => $media->id,
|
||||
]);
|
||||
|
||||
expect($announcementMedia->announcement->id)->toBe($announcement->id);
|
||||
expect($announcementMedia->partnerMedia->id)->toBe($media->id);
|
||||
});
|
||||
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\AnnouncementType;
|
||||
use App\Models\Announcement;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('announcement can be created using factory', function () {
|
||||
$announcement = Announcement::factory()->create(['title' => 'Test Promo']);
|
||||
expect($announcement->title)->toBe('Test Promo');
|
||||
expect($announcement->type)->toBe(AnnouncementType::PUBLIC);
|
||||
});
|
||||
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Models\Classification;
|
||||
use App\Models\SubClassification;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('classification has correct fillable/guarded properties', function () {
|
||||
$classification = new Classification;
|
||||
|
||||
expect($classification->getGuarded())->toBe(['id']);
|
||||
});
|
||||
|
||||
test('classification has correct casts', function () {
|
||||
$classification = new Classification;
|
||||
|
||||
expect($classification->getCasts())->toHaveKey('is_active', IsActive::class);
|
||||
expect($classification->getCasts())->toHaveKey('deleted_at', 'datetime');
|
||||
});
|
||||
|
||||
test('classification can be created using factory', function () {
|
||||
$classification = Classification::factory()->create([
|
||||
'name' => 'Test Classification',
|
||||
]);
|
||||
|
||||
expect($classification->name)->toBe('Test Classification');
|
||||
$this->assertDatabaseHas('classifications', [
|
||||
'id' => $classification->id,
|
||||
'name' => 'Test Classification',
|
||||
]);
|
||||
});
|
||||
|
||||
test('classification active scope filters correctly', function () {
|
||||
Classification::factory()->count(3)->active()->create();
|
||||
Classification::factory()->count(2)->inactive()->create();
|
||||
|
||||
expect(Classification::active()->count())->toBe(3);
|
||||
});
|
||||
|
||||
test('classification inactive scope filters correctly', function () {
|
||||
Classification::factory()->count(3)->active()->create();
|
||||
Classification::factory()->count(2)->inactive()->create();
|
||||
|
||||
expect(Classification::inactive()->count())->toBe(2);
|
||||
});
|
||||
|
||||
test('classification has many sub classifications', function () {
|
||||
$classification = Classification::factory()->create();
|
||||
|
||||
// We need SubClassification factory for this, but let's just check the relation type for now
|
||||
// or create a quick test without factory if it's not ready.
|
||||
expect($classification->subClassifications())->toBeInstanceOf(HasMany::class);
|
||||
});
|
||||
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use App\Models\VerificationRequest;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('company has correct guarded properties', function () {
|
||||
$company = new Company;
|
||||
expect($company->getGuarded())->toBe(['id']);
|
||||
});
|
||||
|
||||
test('company can be created using factory', function () {
|
||||
$company = Company::factory()->create([
|
||||
'name' => 'PT Media Maju',
|
||||
]);
|
||||
|
||||
expect($company->name)->toBe('PT Media Maju');
|
||||
$this->assertDatabaseHas('companies', ['name' => 'PT Media Maju']);
|
||||
});
|
||||
|
||||
test('company belongs to a user', function () {
|
||||
$user = User::factory()->create();
|
||||
$company = Company::factory()->create(['user_id' => $user->id]);
|
||||
|
||||
expect($company->user)->toBeInstanceOf(User::class);
|
||||
expect($company->user->id)->toBe($user->id);
|
||||
});
|
||||
|
||||
test('company has one verification request', function () {
|
||||
$company = Company::factory()->create();
|
||||
$request = VerificationRequest::factory()->create(['company_id' => $company->id]);
|
||||
|
||||
expect($company->verificationRequest)->toBeInstanceOf(VerificationRequest::class);
|
||||
expect($company->verificationRequest->id)->toBe($request->id);
|
||||
});
|
||||
|
||||
test('company has static method for data change labels', function () {
|
||||
$labels = Company::dataChangeEntryLabels();
|
||||
|
||||
expect($labels)->toBeArray();
|
||||
expect($labels)->toHaveKey('name', 'Nama');
|
||||
expect($labels)->toHaveKey('director_nik', 'NIK Direktur');
|
||||
});
|
||||
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Contact;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('contact can be created', function () {
|
||||
$contact = Contact::factory()->create(['email' => 'user@test.com']);
|
||||
expect($contact->email)->toBe('user@test.com');
|
||||
});
|
||||
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Classification;
|
||||
use App\Models\ContentRecap;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('content recap belongs to classification', function () {
|
||||
$recap = ContentRecap::factory()->create(['title' => 'Weekly Recap']);
|
||||
expect($recap->title)->toBe('Weekly Recap');
|
||||
expect($recap->classification)->toBeInstanceOf(Classification::class);
|
||||
});
|
||||
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Cooperation;
|
||||
use App\Models\CooperationMedia;
|
||||
use App\Models\PartnerMedia;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('cooperation media relation works', function () {
|
||||
$cooperation = Cooperation::factory()->create();
|
||||
$media = PartnerMedia::factory()->create();
|
||||
|
||||
$coopMedia = CooperationMedia::factory()->create([
|
||||
'cooperation_id' => $cooperation->id,
|
||||
'partner_media_id' => $media->id,
|
||||
]);
|
||||
|
||||
expect($coopMedia->cooperation->id)->toBe($cooperation->id);
|
||||
expect($coopMedia->partnerMedia->id)->toBe($media->id);
|
||||
});
|
||||
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\CooperationMedia;
|
||||
use App\Models\CooperationPayment;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('cooperation payment can be created', function () {
|
||||
$coopMedia = CooperationMedia::factory()->create();
|
||||
$payment = CooperationPayment::factory()->create([
|
||||
'cooperation_media_id' => $coopMedia->id,
|
||||
'amount' => 5000000,
|
||||
]);
|
||||
|
||||
expect($payment->amount)->toBe(5000000);
|
||||
expect($payment->cooperationMedia->id)->toBe($coopMedia->id);
|
||||
});
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Models\CooperationProposal;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('cooperation proposal can be created', function () {
|
||||
$proposal = CooperationProposal::factory()->create([
|
||||
'status' => ApprovalStatus::PENDING,
|
||||
]);
|
||||
|
||||
expect($proposal->status)->toBe(ApprovalStatus::PENDING);
|
||||
});
|
||||
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\CooperationStatus;
|
||||
use App\Models\Cooperation;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('cooperation can be created using factory', function () {
|
||||
$cooperation = Cooperation::factory()->create();
|
||||
expect($cooperation->status)->toBe(CooperationStatus::PENDING);
|
||||
});
|
||||
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\DataChangeStatus;
|
||||
use App\Models\Company;
|
||||
use App\Models\DataChangeRequest;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('data change request can be created', function () {
|
||||
$company = Company::factory()->create();
|
||||
$request = DataChangeRequest::factory()->create([
|
||||
'entity_type' => Company::class,
|
||||
'entity_id' => $company->id,
|
||||
'status' => DataChangeStatus::PENDING,
|
||||
]);
|
||||
|
||||
expect($request->status)->toBe(DataChangeStatus::PENDING);
|
||||
expect($request->entity)->toBeInstanceOf(Company::class);
|
||||
expect($request->entity->id)->toBe($company->id);
|
||||
});
|
||||
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\DataChangeDecision;
|
||||
use App\Models\DataChangeRequest;
|
||||
use App\Models\DataChangeReview;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('data change review works', function () {
|
||||
$request = DataChangeRequest::factory()->create();
|
||||
$review = DataChangeReview::factory()->create([
|
||||
'data_change_request_id' => $request->id,
|
||||
'decision' => DataChangeDecision::APPROVED,
|
||||
]);
|
||||
|
||||
expect($request->review->id)->toBe($review->id);
|
||||
expect($review->request->id)->toBe($request->id);
|
||||
});
|
||||
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Models\Department;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('department can be created', function () {
|
||||
$dept = Department::factory()->create(['name' => 'IT Research', 'alias' => 'ITR']);
|
||||
expect($dept->name)->toBe('IT Research');
|
||||
expect($dept->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IssueSentiment;
|
||||
use App\Models\Classification;
|
||||
use App\Models\Department;
|
||||
use App\Models\IssueManagement;
|
||||
use App\Models\Location;
|
||||
use App\Models\MediaMonitoring;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('issue management relates monitoring and location', function () {
|
||||
$location = Location::factory()->create();
|
||||
$classification = Classification::factory()->create();
|
||||
$monitoring = MediaMonitoring::factory()->create();
|
||||
$department = Department::factory()->create();
|
||||
|
||||
$issue = IssueManagement::factory()->create([
|
||||
'location_id' => $location->id,
|
||||
'classification_id' => $classification->id,
|
||||
'media_monitoring_id' => $monitoring->id,
|
||||
'issue' => IssueSentiment::POSITIVE,
|
||||
]);
|
||||
|
||||
$issue->departments()->attach($department->id);
|
||||
|
||||
expect($issue->issue)->toBe(IssueSentiment::POSITIVE);
|
||||
expect($issue->location->id)->toBe($location->id);
|
||||
expect($issue->mediaMonitoring->id)->toBe($monitoring->id);
|
||||
expect($issue->departments->first()->id)->toBe($department->id);
|
||||
});
|
||||
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Journalist;
|
||||
use App\Models\PartnerMedia;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('journalist belongs to partner media', function () {
|
||||
$media = PartnerMedia::factory()->create();
|
||||
$journalist = Journalist::factory()->create(['partner_media_id' => $media->id]);
|
||||
|
||||
expect($journalist->partnerMedia->id)->toBe($media->id);
|
||||
});
|
||||
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Models\Location;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('location can be created', function () {
|
||||
$location = Location::factory()->create(['name' => 'Purwakarta']);
|
||||
expect($location->name)->toBe('Purwakarta');
|
||||
expect($location->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\MediaMonitoring;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('media monitoring can be created', function () {
|
||||
$monitoring = MediaMonitoring::factory()->create(['media_name' => 'Tempo']);
|
||||
expect($monitoring->media_name)->toBe('Tempo');
|
||||
});
|
||||
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\MediaMonitoring;
|
||||
use App\Models\MediaMonitoringTheme;
|
||||
use App\Models\Theme;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('media monitoring theme relation works', function () {
|
||||
$monitoring = MediaMonitoring::factory()->create();
|
||||
$theme = Theme::factory()->create();
|
||||
$mmt = MediaMonitoringTheme::factory()->create([
|
||||
'media_monitoring_id' => $monitoring->id,
|
||||
'theme_id' => $theme->id,
|
||||
]);
|
||||
|
||||
expect($mmt->mediaMonitoring->id)->toBe($monitoring->id);
|
||||
expect($mmt->theme->id)->toBe($theme->id);
|
||||
expect($monitoring->themes->first()->id)->toBe($theme->id);
|
||||
});
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\MediaTaskAssignment;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('report relates to media task assignment', function () {
|
||||
$mta = MediaTaskAssignment::factory()->create();
|
||||
$report = Report::factory()->create(['media_task_assignment_id' => $mta->id]);
|
||||
|
||||
expect($report->mediaTaskAssignment->id)->toBe($mta->id);
|
||||
expect($mta->reports)->toHaveCount(1);
|
||||
});
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\News;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('news can be created using factory', function () {
|
||||
$news = News::factory()->create([
|
||||
'title' => 'Kabar Purwakarta',
|
||||
'slug' => 'kabar-purwakarta',
|
||||
]);
|
||||
expect($news->title)->toBe('Kabar Purwakarta');
|
||||
expect($news->slug)->toBe('kabar-purwakarta');
|
||||
});
|
||||
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Journalist;
|
||||
use App\Models\PartnerMedia;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('partner media has journalists', function () {
|
||||
$media = PartnerMedia::factory()->create();
|
||||
Journalist::factory()->count(2)->create(['partner_media_id' => $media->id]);
|
||||
|
||||
expect($media->journalists)->toHaveCount(2);
|
||||
});
|
||||
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\RejectionReason;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('rejection reason uses polymorphic relation', function () {
|
||||
$report = Report::factory()->create();
|
||||
$rejection = RejectionReason::factory()->create([
|
||||
'rejectable_type' => Report::class,
|
||||
'rejectable_id' => $report->id,
|
||||
'reason' => 'Invalid link',
|
||||
]);
|
||||
|
||||
expect($rejection->reason)->toBe('Invalid link');
|
||||
expect($rejection->rejectable)->toBeInstanceOf(Report::class);
|
||||
});
|
||||
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('report can be created and has status', function () {
|
||||
$report = Report::factory()->create(['status' => ApprovalStatus::PENDING]);
|
||||
expect($report->status)->toBe(ApprovalStatus::PENDING);
|
||||
});
|
||||
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Classification;
|
||||
use App\Models\SubClassification;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('sub classification can be created using factory', function () {
|
||||
$sub = SubClassification::factory()->create(['name' => 'Sub Test']);
|
||||
|
||||
expect($sub->name)->toBe('Sub Test');
|
||||
expect($sub->classification)->toBeInstanceOf(Classification::class);
|
||||
});
|
||||
|
||||
test('sub classification belongs to a classification', function () {
|
||||
$parent = Classification::factory()->create();
|
||||
$sub = SubClassification::factory()->create(['classification_id' => $parent->id]);
|
||||
|
||||
expect($sub->classification->id)->toBe($parent->id);
|
||||
});
|
||||
|
||||
test('classification has many sub classifications relationship works', function () {
|
||||
$parent = Classification::factory()->create();
|
||||
SubClassification::factory()->count(3)->create(['classification_id' => $parent->id]);
|
||||
|
||||
expect($parent->subClassifications)->toHaveCount(3);
|
||||
});
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Location;
|
||||
use App\Models\SubLocation;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('sub location belongs to location', function () {
|
||||
$parent = Location::factory()->create();
|
||||
$sub = SubLocation::factory()->create(['location_id' => $parent->id]);
|
||||
|
||||
expect($sub->location->id)->toBe($parent->id);
|
||||
expect($parent->subLocations)->toHaveCount(1);
|
||||
});
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Cooperation;
|
||||
use App\Models\TaskAssignment;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('task assignment works', function () {
|
||||
$cooperation = Cooperation::factory()->create();
|
||||
$task = TaskAssignment::factory()->create(['cooperation_id' => $cooperation->id]);
|
||||
|
||||
expect($task->cooperation->id)->toBe($cooperation->id);
|
||||
expect($cooperation->taskAssignment->id)->toBe($task->id);
|
||||
});
|
||||
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Models\Theme;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('theme can be created', function () {
|
||||
$theme = Theme::factory()->create(['name' => 'Politik']);
|
||||
expect($theme->name)->toBe('Politik');
|
||||
expect($theme->is_active)->toBe(IsActive::ACTIVE);
|
||||
});
|
||||
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsActive;
|
||||
use App\Models\User;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('user has correct fillable/guarded properties', function () {
|
||||
$user = new User;
|
||||
expect($user->getGuarded())->toBe(['id']);
|
||||
});
|
||||
|
||||
test('user has correct casts', function () {
|
||||
$user = new User;
|
||||
expect($user->getCasts())->toHaveKey('password', 'hashed');
|
||||
expect($user->getCasts())->toHaveKey('is_active', IsActive::class);
|
||||
});
|
||||
|
||||
test('user can be created using factory', function () {
|
||||
$user = User::factory()->create([
|
||||
'name' => 'John Doe',
|
||||
'email' => 'john@example.com',
|
||||
]);
|
||||
|
||||
expect($user->name)->toBe('John Doe');
|
||||
expect(Hash::check('password', $user->password))->toBeTrue();
|
||||
$this->assertDatabaseHas('users', ['email' => 'john@example.com']);
|
||||
});
|
||||
|
||||
test('user active scope filters correctly', function () {
|
||||
User::factory()->count(2)->create(['is_active' => IsActive::ACTIVE]);
|
||||
User::factory()->count(1)->create(['is_active' => IsActive::INACTIVE]);
|
||||
|
||||
expect(User::active()->count())->toBe(2);
|
||||
});
|
||||
|
||||
test('user can access panel if active', function () {
|
||||
$user = User::factory()->create(['is_active' => IsActive::ACTIVE]);
|
||||
|
||||
// Default mock for Filament Panel if needed, but the method logic is simple
|
||||
expect($user->canAccessPanel(mock(Panel::class)))->toBeTrue();
|
||||
});
|
||||
|
||||
test('user cannot access panel if inactive', function () {
|
||||
$user = User::factory()->create(['is_active' => IsActive::INACTIVE]);
|
||||
|
||||
expect($user->canAccessPanel(mock(Panel::class)))->toBeFalse();
|
||||
});
|
||||
|
||||
test('user has company relation', function () {
|
||||
$user = User::factory()->create();
|
||||
expect($user->company())->toBeInstanceOf(HasOne::class);
|
||||
});
|
||||
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\VerificationStatus;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use App\Models\VerificationRequest;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('verification request has correct guarded properties', function () {
|
||||
$request = new VerificationRequest;
|
||||
expect($request->getGuarded())->toBe(['id']);
|
||||
});
|
||||
|
||||
test('verification request has correct casts', function () {
|
||||
$request = new VerificationRequest;
|
||||
expect($request->getCasts())->toHaveKey('status', VerificationStatus::class);
|
||||
});
|
||||
|
||||
test('verification request can be created using factory', function () {
|
||||
$request = VerificationRequest::factory()->create();
|
||||
|
||||
expect($request->status)->toBe(VerificationStatus::PENDING);
|
||||
$this->assertDatabaseHas('verification_requests', ['id' => $request->id]);
|
||||
});
|
||||
|
||||
test('verification request scopes filter correctly', function () {
|
||||
VerificationRequest::factory()->count(2)->approved()->create();
|
||||
VerificationRequest::factory()->count(3)->pending()->create();
|
||||
VerificationRequest::factory()->count(1)->rejected()->create();
|
||||
VerificationRequest::factory()->count(1)->needRevision()->create();
|
||||
|
||||
expect(VerificationRequest::approved()->count())->toBe(2);
|
||||
expect(VerificationRequest::pending()->count())->toBe(3);
|
||||
expect(VerificationRequest::rejected()->count())->toBe(1);
|
||||
expect(VerificationRequest::needRevision()->count())->toBe(1);
|
||||
});
|
||||
|
||||
test('verification request belongs to company and user', function () {
|
||||
$company = Company::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$request = VerificationRequest::factory()->create([
|
||||
'company_id' => $company->id,
|
||||
'submitted_by' => $user->id,
|
||||
]);
|
||||
|
||||
expect($request->company)->toBeInstanceOf(Company::class);
|
||||
expect($request->submittedBy)->toBeInstanceOf(User::class);
|
||||
expect($request->company->id)->toBe($company->id);
|
||||
expect($request->submittedBy->id)->toBe($user->id);
|
||||
});
|
||||
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\DecisionAdmin;
|
||||
use App\Models\User;
|
||||
use App\Models\VerificationRequest;
|
||||
use App\Models\VerificationReview;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('verification review can be created', function () {
|
||||
$request = VerificationRequest::factory()->create();
|
||||
$reviewer = User::factory()->create();
|
||||
|
||||
$review = VerificationReview::factory()->create([
|
||||
'verification_request_id' => $request->id,
|
||||
'reviewer_id' => $reviewer->id,
|
||||
'decision' => DecisionAdmin::APPROVED,
|
||||
]);
|
||||
|
||||
expect($review->decision)->toBe(DecisionAdmin::APPROVED);
|
||||
expect($review->verificationRequest->id)->toBe($request->id);
|
||||
expect($review->reviewer->id)->toBe($reviewer->id);
|
||||
});
|
||||
|
||||
test('verification request has many reviews', function () {
|
||||
$request = VerificationRequest::factory()->create();
|
||||
VerificationReview::factory()->count(2)->create(['verification_request_id' => $request->id]);
|
||||
|
||||
expect($request->reviews)->toHaveCount(2);
|
||||
});
|
||||
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Visitor;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('visitor can be created', function () {
|
||||
$visitor = Visitor::factory()->create(['ip' => '127.0.0.1']);
|
||||
expect($visitor->ip)->toBe('127.0.0.1');
|
||||
expect($visitor->user)->toBeInstanceOf(User::class);
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user