feat: add verification log filtering, gate inspection, and dashboard views for private guard module

This commit is contained in:
Wahyudin
2026-10-14 01:38:48 +07:00
parent faacd65da9
commit 9c00515a73
38 changed files with 4628 additions and 863 deletions
+6 -2
View File
@@ -2,11 +2,13 @@
namespace Tests\Feature;
// use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
use RefreshDatabase;
/**
* A basic test example.
*/
@@ -14,6 +16,8 @@ class ExampleTest extends TestCase
{
$response = $this->get('/');
$response->assertRedirect('/login');
$response->assertStatus(200);
$response->assertSee('Sistem RKM');
$response->assertSee('Masuk Ke Sistem RKM');
}
}
+138
View File
@@ -0,0 +1,138 @@
<?php
namespace Tests\Feature;
use App\Models\Employee;
use App\Models\Gate;
use App\Models\User;
use App\Models\Vehicle;
use App\Models\VehicleActivity;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class HomePageTest extends TestCase
{
use RefreshDatabase;
private function seedBasicData(): void
{
Gate::create(['code' => 'ADIT1', 'name' => 'Adit 1', 'is_active' => true]);
Gate::create(['code' => 'BTUNGGAL', 'name' => 'Beringin Tunggal', 'is_active' => true]);
Employee::create([
'nik' => '1001',
'name' => 'Driver Budi',
'unit_kerja' => 'Umum',
'division' => 'GA',
'position' => 'Driver',
'is_operator' => true,
'simper_expired_at' => Carbon::now()->addMonths(6),
]);
Vehicle::create([
'code' => 'LV62',
'category' => 'light_vehicle',
'brand_type' => 'MITSUBISHI L300',
'license_plate' => 'BH 8893 DI',
'status' => 'Operation',
'current_km' => 12500,
]);
Vehicle::create([
'code' => 'LV01',
'category' => 'light_vehicle',
'brand_type' => 'TOYOTA HILUX',
'license_plate' => 'BH 1024 AB',
'status' => 'Operation',
'current_km' => 45000,
]);
}
public function test_homepage_renders_successfully_for_guest(): void
{
$this->seedBasicData();
$response = $this->get('/');
$response->assertStatus(200);
$response->assertSee('Sistem RKM');
$response->assertSee('PT Kerinci Merangin Hidro');
$response->assertSee('PLTA Merangin 350 MW');
$response->assertSee('Login');
$response->assertSee('Masuk Ke Sistem RKM');
}
public function test_homepage_displays_system_summary_and_modules(): void
{
$this->seedBasicData();
$response = $this->get('/');
$response->assertStatus(200);
$response->assertSee('Ringkasan Sistem');
$response->assertSee('Modul 1: HSE');
$response->assertSee('Modul 2: QMA');
$response->assertSee('Modul 3: Private Guard (PG)');
$response->assertSee('Bagaimana Aktivitas Kendaraan Lewat Gate Bekerja?');
}
public function test_gate_activity_index_is_removed_and_returns_404(): void
{
$this->seedBasicData();
$response = $this->get('/gate-activity');
$response->assertStatus(404);
}
public function test_homepage_does_not_display_recent_activities_or_quick_access_cards_for_privacy(): void
{
$this->seedBasicData();
$response = $this->get('/');
$response->assertStatus(200);
$response->assertDontSee('Riwayat Aktivitas Kendaraan Lewat Gerbang');
$response->assertDontSee('Riwayat Gerbang');
$response->assertDontSee('Akses Cepat Pengguna');
$response->assertDontSee('quickCodeInput');
}
public function test_gate_activity_form_via_qr_code_remains_accessible(): void
{
$this->seedBasicData();
$response = $this->get('/gate-activity/LV62');
$response->assertStatus(200);
$response->assertSee('Input Timesheet Unit');
$response->assertSee('LV62');
$response->assertDontSee('Kembali ke Beranda RKM');
}
public function test_homepage_displays_dashboard_link_when_authenticated(): void
{
$this->seedBasicData();
$user = User::factory()->create([
'name' => 'Pinto QMA',
'role' => 'qma_admin',
]);
$response = $this->actingAs($user)->get('/');
$response->assertStatus(200);
$response->assertSee('Pinto QMA');
$response->assertSee(route('qma.dashboard'));
}
public function test_login_page_renders_back_to_home_button(): void
{
$response = $this->get('/login');
$response->assertStatus(200);
$response->assertSee('Kembali ke Beranda RKM');
$response->assertSee(route('home'));
}
}
+31
View File
@@ -240,4 +240,35 @@ class QmaModuleTest extends TestCase
$responseSupport = $this->actingAs($this->hseAdmin)->get('/qma/vehicles/unit-support');
$responseSupport->assertStatus(403);
}
/**
* Memastikan kolom QR Code dan modal stiker fisik tampil pada tabel Light Vehicle.
*/
public function test_qma_lv_table_renders_qr_code_column_and_modal(): void
{
$vehicle = Vehicle::create([
'code' => 'LV77',
'category' => 'light_vehicle',
'brand_type' => 'Mitsubishi Triton 4x4',
'license_plate' => 'BH 7777 QR',
'division' => 'Civil & Inviro',
'ownership' => 'PT Kerinci Merangin Hidro',
'status' => 'Operation',
'current_km' => 15000,
]);
$response = $this->actingAs($this->qmaAdmin)->get('/qma/vehicles/light-vehicle');
$response->assertStatus(200);
$response->assertSee('QR CODE');
$response->assertSee('Stiker QR');
$response->assertSee('qrVehicleModal');
$response->assertSee('printableStickerArea');
$response->assertSee('gate-activity/LV77');
$response->assertSee('Cetak Stiker');
$response->assertSee('Unduh PNG');
$response->assertSee('btnDownloadSticker');
$response->assertSee('downloadQrCode');
}
}
+177
View File
@@ -0,0 +1,177 @@
<?php
namespace Tests\Feature;
use App\Models\Gate;
use App\Models\SecurityGuard;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class SecurityGuardFilterTest extends TestCase
{
use RefreshDatabase;
protected User $adminPg;
protected function setUp(): void
{
parent::setUp();
$this->seed();
$this->adminPg = User::where('role', 'pg_admin')->first();
}
/**
* Memastikan halaman data satpam berhasil diakses dengan elemen filter & search.
*/
public function test_admin_pg_can_view_guards_page_with_filters(): void
{
$response = $this->actingAs($this->adminPg)->get(route('pg.guards.index'));
$response->assertStatus(200);
$response->assertSee('Data Satpam');
$response->assertSee('Cari ID Satpam atau nama petugas...');
$response->assertSee('Semua Regu');
$response->assertSee('Semua Penempatan');
$response->assertSee('Ahmad Fauzi');
}
/**
* Memastikan filter regu menyaring satpam sesuai regu yang dipilih.
*/
public function test_guards_filtered_by_team(): void
{
// Regu 1: Ahmad Fauzi (SEC-001), Rusli Efendi (SEC-004)
// Regu 2: Budi Santoso (SEC-002), Slamet Widodo (SEC-005)
$response = $this->actingAs($this->adminPg)->get(route('pg.guards.index', ['team' => 1]));
$response->assertStatus(200);
$guards = $response->viewData('guards');
$this->assertTrue($guards->contains('name', 'Ahmad Fauzi'));
$this->assertTrue($guards->contains('name', 'Rusli Efendi'));
$this->assertFalse($guards->contains('name', 'Budi Santoso'));
$this->assertFalse($guards->contains('name', 'Slamet Widodo'));
$response->assertSee('SEC-001');
$response->assertSee('SEC-004');
$response->assertDontSee('SEC-002');
$response->assertDontSee('SEC-005');
$response->assertSee('Reset Filter');
}
/**
* Memastikan filter penempatan pos menyaring satpam sesuai gerbang yang dipilih.
*/
public function test_guards_filtered_by_gate(): void
{
$gateBeringin = Gate::where('code', 'BTUNGGAL')->first();
$response = $this->actingAs($this->adminPg)->get(route('pg.guards.index', ['gate_id' => $gateBeringin->id]));
$response->assertStatus(200);
$guards = $response->viewData('guards');
$this->assertTrue($guards->contains('name', 'Ahmad Fauzi'));
$this->assertFalse($guards->contains('name', 'Budi Santoso'));
$response->assertSee('SEC-001');
$response->assertDontSee('SEC-002');
$response->assertSee('Reset Filter');
}
/**
* Memastikan pencarian kata kunci menyaring satpam sesuai input.
*/
public function test_guards_filtered_by_search_keyword(): void
{
$response = $this->actingAs($this->adminPg)->get(route('pg.guards.index', ['search' => 'Fauzi']));
$response->assertStatus(200);
$guards = $response->viewData('guards');
$this->assertTrue($guards->contains('name', 'Ahmad Fauzi'));
$this->assertFalse($guards->contains('name', 'Budi Santoso'));
$response->assertSee('SEC-001');
$response->assertDontSee('SEC-002');
$response->assertSee('Reset Filter');
}
/**
* Memastikan pencarian kata kunci yang tidak ditemukan menampilkan baris keterangan dan tombol reset.
*/
public function test_empty_search_shows_not_found_message_and_reset_button(): void
{
$keyword = 'sgbsfgh';
$response = $this->actingAs($this->adminPg)->get(route('pg.guards.index', ['search' => $keyword]));
$response->assertStatus(200);
$response->assertSeeText('Data "' . $keyword . '" tidak ditemukan di tabel', false);
$response->assertSeeText('Pastikan ejaan ID Satpam atau nama petugas yang dicari sudah benar.');
$response->assertSee('Reset Filter');
}
/**
* Memastikan modal konfirmasi toggle status dan pemanggilan JS tersedia pada halaman.
*/
public function test_guards_page_renders_toggle_status_confirmation_modal(): void
{
$response = $this->actingAs($this->adminPg)->get(route('pg.guards.index'));
$response->assertStatus(200);
$response->assertSee('toggleStatusModal');
$response->assertSee('Konfirmasi Status Petugas');
$response->assertSee('openToggleStatusModal');
}
/**
* Memastikan admin PG dapat mengubah status aktif/nonaktif petugas.
*/
public function test_admin_pg_can_toggle_guard_status(): void
{
$guard = SecurityGuard::where('badge_id', 'SEC-001')->first();
$this->assertTrue($guard->is_active);
// 1. Nonaktifkan petugas
$response = $this->actingAs($this->adminPg)->post(route('pg.guards.toggle', $guard->id));
$response->assertSessionHas('success');
$this->assertFalse($guard->fresh()->is_active);
// 2. Aktifkan kembali petugas
$response = $this->actingAs($this->adminPg)->post(route('pg.guards.toggle', $guard->id));
$response->assertSessionHas('success');
$this->assertTrue($guard->fresh()->is_active);
}
/**
* Memastikan modal konfirmasi hapus petugas satpam tersedia pada halaman.
*/
public function test_guards_page_renders_delete_guard_modal(): void
{
$response = $this->actingAs($this->adminPg)->get(route('pg.guards.index'));
$response->assertStatus(200);
$response->assertSee('deleteGuardModal');
$response->assertSee('Konfirmasi Hapus Petugas Satpam');
$response->assertSee('openDeleteGuardModal');
}
/**
* Memastikan admin PG dapat menghapus petugas Satpam beserta akun login terkait.
*/
public function test_admin_pg_can_delete_guard_and_associated_user(): void
{
$guard = SecurityGuard::with('user')->where('badge_id', 'SEC-005')->first();
$this->assertNotNull($guard);
$guardId = $guard->id;
$userId = $guard->user_id;
$response = $this->actingAs($this->adminPg)->delete(route('pg.guards.destroy', $guardId));
$response->assertRedirect();
$response->assertSessionHas('success');
$this->assertDatabaseMissing('security_guards', ['id' => $guardId]);
if ($userId) {
$this->assertDatabaseMissing('users', ['id' => $userId]);
}
}
}
+135
View File
@@ -31,6 +31,112 @@ class VehicleActivityTest extends TestCase
$response->assertSee('Input Timesheet Unit');
$response->assertSee('LV62');
$response->assertSee('MITSUBISHI - L300 - PICK UP');
$response->assertDontSee('<aside', false);
$response->assertDontSee('userProfileDropdownBtn');
$response->assertDontSee('openDrawerBtn');
}
public function test_form_qr_hides_sidebar_and_topbar_when_accessed_by_authenticated_admin(): void
{
$admin = User::where('role', 'qma_admin')->first();
$response = $this->actingAs($admin)->get('/gate-activity/LV62');
$response->assertStatus(200);
$response->assertSee('Input Timesheet Unit');
$response->assertDontSee('<aside', false);
$response->assertDontSee('userProfileDropdownBtn');
$response->assertDontSee('openDrawerBtn');
}
public function test_check_nik_endpoint_returns_not_found_for_unregistered_nik(): void
{
$response = $this->postJson('/gate-activity/LV62/check-nik', [
'nik' => 'KMH-9999-999',
]);
$response->assertStatus(404);
$response->assertJson([
'status' => 'not_found',
]);
$response->assertJsonFragment([
'message' => "NIK 'KMH-9999-999' tidak terdaftar dalam database SIMPER PT KMH. Silakan periksa kembali atau hubungi Divisi HSE.",
]);
}
public function test_check_nik_endpoint_returns_expired_for_expired_simper(): void
{
// Randi Kurniawan (KMH-2023-012) memiliki SIMPER kedaluwarsa
$response = $this->postJson('/gate-activity/LV62/check-nik', [
'nik' => 'KMH-2023-012',
]);
$response->assertStatus(422);
$response->assertJson([
'status' => 'expired',
]);
$this->assertStringContainsString('telah KEDALUWARSA', $response->json('message'));
}
public function test_check_nik_endpoint_returns_valid_for_active_simper(): void
{
// Eka Sufiatna (KMH-2022-001) memiliki SIMPER aktif
$response = $this->postJson('/gate-activity/LV62/check-nik', [
'nik' => 'KMH-2022-001',
]);
$response->assertStatus(200);
$response->assertJson([
'status' => 'valid',
'employee' => [
'name' => 'Eka Sufiatna',
'nik' => 'KMH-2022-001',
],
]);
}
public function test_form_qr_auto_fills_driver_when_valid_nik_provided(): void
{
$response = $this->get('/gate-activity/LV62?nik=KMH-2022-001');
$response->assertStatus(200);
$response->assertSee('Eka Sufiatna');
$response->assertSee('KMH-2022-001');
$response->assertSee('Otomatis Terisi');
$response->assertSee('SIMPER Aktif');
}
public function test_check_nik_endpoint_returns_not_driver_when_employee_is_not_operator(): void
{
// Siti Rahma (KMH-2021-088) adalah Staff Finance (Bukan Driver)
$response = $this->postJson('/gate-activity/LV62/check-nik', [
'nik' => 'KMH-2021-088',
]);
$response->assertStatus(422);
$response->assertJson([
'status' => 'not_driver',
'title' => 'Bukan Driver Terdaftar',
]);
$this->assertStringContainsString('terdaftar sebagai BUKAN DRIVER', $response->json('message'));
}
public function test_form_qr_shows_error_when_invalid_or_expired_or_non_driver_nik_provided_via_query(): void
{
// 1. NIK Tidak terdaftar
$responseUnregistered = $this->get('/gate-activity/LV62?nik=KMH-9999-999');
$responseUnregistered->assertStatus(200);
$responseUnregistered->assertSee('tidak terdaftar dalam database SIMPER');
// 2. NIK Kedaluwarsa
$responseExpired = $this->get('/gate-activity/LV62?nik=KMH-2023-012');
$responseExpired->assertStatus(200);
$responseExpired->assertSee('telah KEDALUWARSA');
// 3. NIK Karyawan Bukan Driver (Staff Finance)
$responseNotDriver = $this->get('/gate-activity/LV62?nik=KMH-2021-088');
$responseNotDriver->assertStatus(200);
$responseNotDriver->assertSee('Bukan Driver Terdaftar');
$responseNotDriver->assertSee('terdaftar sebagai BUKAN DRIVER');
}
public function test_submit_blocked_if_driver_simper_is_expired(): void
@@ -336,4 +442,33 @@ class VehicleActivityTest extends TestCase
$response->assertSee('Log Verifikasi Gerbang Terkini');
$response->assertSee('Petugas Satpam per Regu');
}
public function test_guard_can_fetch_live_queue_json_endpoint(): void
{
$gateOfficer = User::where('role', 'gate_officer')->first();
$vehicle = Vehicle::where('code', 'LV62')->first();
$driver = Employee::where('nik', 'KMH-2022-001')->first();
$gateId = $gateOfficer->gate_id ?? Gate::first()->id;
VehicleActivity::create([
'transaction_no' => 'TRX-LIVE-001',
'vehicle_id' => $vehicle->id,
'driver_id' => $driver->id,
'gate_id' => $gateId,
'direction' => 'out',
'previous_km' => 12500,
'current_km' => 12600,
'distance' => 100,
'purpose' => 'Pengujian Live Queue',
'recorded_at' => Carbon::now(),
'validation_status' => 'pending',
]);
$response = $this->actingAs($gateOfficer)->get(route('pg.gate.live_queue'));
$response->assertStatus(200);
$response->assertJsonStructure(['count', 'html']);
$this->assertGreaterThanOrEqual(1, $response->json('count'));
$this->assertStringContainsString('BH 8893 DI', $response->json('html'));
$this->assertStringContainsString('Pengujian Live Queue', $response->json('html'));
}
}
+182
View File
@@ -0,0 +1,182 @@
<?php
namespace Tests\Feature;
use App\Models\Employee;
use App\Models\Gate;
use App\Models\SecurityGuard;
use App\Models\User;
use App\Models\Vehicle;
use App\Models\VehicleActivity;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class VerificationLogFilterTest extends TestCase
{
use RefreshDatabase;
protected User $adminPg;
protected VehicleActivity $testActivity;
protected function setUp(): void
{
parent::setUp();
$this->seed();
$this->adminPg = User::where('role', 'pg_admin')->first();
$vehicle = Vehicle::first();
$driver = Employee::first();
$guard = SecurityGuard::first();
$this->testActivity = VehicleActivity::create([
'transaction_no' => 'TRX-AUDIT-TEST-001',
'vehicle_id' => $vehicle->id,
'driver_id' => $driver->id,
'gate_id' => $guard->gate_id ?? Gate::first()->id,
'security_guard_id' => $guard->id,
'direction' => 'out',
'previous_km' => 1000,
'current_km' => 1050,
'distance' => 50,
'purpose' => 'Uji Validasi Audit Gerbang',
'validation_status' => 'approved',
'recorded_at' => Carbon::now(),
'validated_at' => Carbon::now(),
]);
}
/**
* Memastikan halaman log verifikasi gerbang dapat diakses dengan layout terpisah dan card tertutup secara default.
*/
public function test_admin_pg_can_view_verification_logs_with_collapsed_filter_card_by_default(): void
{
$response = $this->actingAs($this->adminPg)->get(route('pg.logs.index'));
$response->assertStatus(200);
$response->assertSee('Log Riwayat Verifikasi Gerbang');
$response->assertSee('verificationLogSearchInput');
$response->assertSee('filterToggleBtn');
$response->assertSee('id="collapsibleFilterCard" class="hidden bg-white', false);
$response->assertDontSee('id="headerResetFilterBtn"');
}
/**
* Memastikan card filter otomatis terbuka (auto-expanded / tanpa hidden) jika URL memiliki parameter filter lanjutan.
*/
public function test_collapsible_filter_card_auto_expands_when_filter_params_present(): void
{
$response = $this->actingAs($this->adminPg)->get(route('pg.logs.index', ['team' => 1]));
$response->assertStatus(200);
$response->assertSee('id="collapsibleFilterCard" class="bg-white', false);
$response->assertDontSee('id="collapsibleFilterCard" class="hidden', false);
$response->assertSee('Reset Filter');
}
/**
* Memastikan card filter tetap tertutup jika URL hanya memiliki parameter search saja.
*/
public function test_collapsible_filter_card_remains_collapsed_when_only_search_param_present(): void
{
$response = $this->actingAs($this->adminPg)->get(route('pg.logs.index', ['search' => 'TRX']));
$response->assertStatus(200);
$response->assertSee('id="collapsibleFilterCard" class="hidden bg-white', false);
$response->assertSee('Reset Filter');
}
/**
* Memastikan pencarian teks menyaring log verifikasi dengan benar.
*/
public function test_verification_logs_search_filtering(): void
{
$response = $this->actingAs($this->adminPg)->get(route('pg.logs.index', ['search' => 'TRX-AUDIT-TEST-001']));
$response->assertStatus(200);
$response->assertSee('TRX-AUDIT-TEST-001');
$response->assertSee('Reset Filter');
}
/**
* Memastikan pesan pencarian kosong menampilkan format keterangan yang ditentukan saat data tidak ditemukan.
*/
public function test_verification_logs_search_no_results_displays_message_and_reset_button(): void
{
$keyword = 'XYZNONEXISTENTKEYWORD123';
$response = $this->actingAs($this->adminPg)->get(route('pg.logs.index', ['search' => $keyword]));
$response->assertStatus(200);
$response->assertSee('🔍');
$response->assertSeeText('Data "' . $keyword . '" tidak ditemukan di tabel', false);
$response->assertSeeText('Pastikan ejaan nomor transaksi, plat kendaraan, nama pengemudi, atau petugas sudah benar.');
$response->assertSee('Reset Filter');
}
/**
* Memastikan filter multi-parameter (pos gerbang & arah) bekerja dengan benar.
*/
public function test_verification_logs_filtered_by_gate_and_direction(): void
{
$response = $this->actingAs($this->adminPg)->get(route('pg.logs.index', [
'gate_id' => $this->testActivity->gate_id,
'direction' => 'out',
]));
$response->assertStatus(200);
$response->assertSee('TRX-AUDIT-TEST-001');
$response->assertSee('id="collapsibleFilterCard" class="bg-white', false);
$response->assertSee('Reset Filter');
}
/**
* Memastikan filter rentang tanggal secara default diset ke hari ini.
*/
public function test_verification_logs_defaults_date_filter_to_today(): void
{
$todayStr = Carbon::today()->toDateString();
$yesterday = Carbon::yesterday();
// Buat aktivitas kemarin
$yesterdayActivity = VehicleActivity::create([
'transaction_no' => 'TRX-YESTERDAY-001',
'vehicle_id' => $this->testActivity->vehicle_id,
'driver_id' => $this->testActivity->driver_id,
'gate_id' => $this->testActivity->gate_id,
'security_guard_id' => $this->testActivity->security_guard_id,
'direction' => 'in',
'previous_km' => 900,
'current_km' => 950,
'distance' => 50,
'purpose' => 'Aktivitas Hari Kemarin',
'validation_status' => 'approved',
'recorded_at' => $yesterday,
'validated_at' => $yesterday,
]);
$response = $this->actingAs($this->adminPg)->get(route('pg.logs.index'));
$response->assertStatus(200);
$this->assertEquals($todayStr, $response->viewData('startDate'));
$this->assertEquals($todayStr, $response->viewData('endDate'));
// Input value Mulai Tanggal dan Sampai Tanggal di-set hari ini
$response->assertSee('name="start_date"', false);
$response->assertSee('name="end_date"', false);
$response->assertSee('value="' . $todayStr . '"', false);
// Data hari ini tampil, data kemarin tidak tampil secara default
$response->assertSee('TRX-AUDIT-TEST-001');
$response->assertDontSee('TRX-YESTERDAY-001');
// Saat rentang tanggal disetel ke kemarin, data kemarin muncul
$customDateResponse = $this->actingAs($this->adminPg)->get(route('pg.logs.index', [
'start_date' => $yesterday->toDateString(),
'end_date' => $todayStr,
]));
$customDateResponse->assertStatus(200);
$customDateResponse->assertSee('TRX-YESTERDAY-001');
$customDateResponse->assertSee('TRX-AUDIT-TEST-001');
}
}