feat: implement 3-level heavy equipment drilldown and transporter options in unit transfer
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Vehicle;
|
||||
use Database\Seeders\RolePermissionSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class QmaHeavyEquipmentThreeLevelNavigationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $qmaAdmin;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->seed(RolePermissionSeeder::class);
|
||||
|
||||
$this->qmaAdmin = User::factory()->create([
|
||||
'name' => 'Admin QMA Test',
|
||||
'username' => 'qma_test_3level',
|
||||
'role' => 'qma_admin',
|
||||
]);
|
||||
$this->qmaAdmin->assignRole('qma_admin');
|
||||
|
||||
// 1. Hauling Units (Dump Truck & Mixer Truck)
|
||||
Vehicle::create([
|
||||
'code' => 'DT-01',
|
||||
'category' => 'unit_support',
|
||||
'operational_group' => 'HAULING',
|
||||
'unit_category' => 'Dump Truck',
|
||||
'unit_type' => 'DUMP TRUCK',
|
||||
'brand' => 'HOWO',
|
||||
'brand_type' => 'HOWO SINOTRUK 336',
|
||||
'model_number' => 'ZZ3257N3847',
|
||||
'serial_number' => 'HW123456',
|
||||
'location' => 'Main Dam',
|
||||
'site_status' => 'inside_site',
|
||||
'status' => 'Operation',
|
||||
]);
|
||||
|
||||
Vehicle::create([
|
||||
'code' => 'DT-02',
|
||||
'category' => 'unit_support',
|
||||
'operational_group' => 'HAULING',
|
||||
'unit_category' => 'Dump Truck',
|
||||
'unit_type' => 'DUMP TRUCK',
|
||||
'brand' => 'HOWO',
|
||||
'brand_type' => 'HOWO SINOTRUK 336',
|
||||
'location' => 'Adit 3',
|
||||
'site_status' => 'inside_site',
|
||||
'status' => 'Standby',
|
||||
]);
|
||||
|
||||
Vehicle::create([
|
||||
'code' => 'MT-01',
|
||||
'category' => 'unit_support',
|
||||
'operational_group' => 'HAULING',
|
||||
'unit_category' => 'Truk Mixer',
|
||||
'unit_type' => 'MIXER TRUCK',
|
||||
'brand' => 'YUCHAI',
|
||||
'brand_type' => 'YUCHAI DIECI',
|
||||
'location' => 'Batching Plant',
|
||||
'site_status' => 'inside_site',
|
||||
'status' => 'Operation',
|
||||
]);
|
||||
|
||||
// 2. Loader Units (Excavator)
|
||||
Vehicle::create([
|
||||
'code' => 'EX-01',
|
||||
'category' => 'unit_support',
|
||||
'operational_group' => 'LOADER',
|
||||
'unit_category' => 'Excavator',
|
||||
'unit_type' => 'EXCAVATOR',
|
||||
'brand' => 'KOMATSU',
|
||||
'brand_type' => 'KOMATSU PC200-8',
|
||||
'location' => 'Power House',
|
||||
'site_status' => 'inside_site',
|
||||
'status' => 'Operation',
|
||||
]);
|
||||
|
||||
// 3. Support Units (Compressor)
|
||||
Vehicle::create([
|
||||
'code' => 'CP-01',
|
||||
'category' => 'unit_support',
|
||||
'operational_group' => 'SUPPORT',
|
||||
'unit_category' => 'Engine Compressor',
|
||||
'unit_type' => 'COMPRESSOR',
|
||||
'brand' => 'AIRMAN',
|
||||
'brand_type' => 'AIRMAN PDS655S',
|
||||
'location' => 'Adit 2',
|
||||
'site_status' => 'inside_site',
|
||||
'status' => 'Breakdown',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Level 1: Halaman utama menampilkan daftar Kelompok Operasional (HAULING, LOADER, SUPPORT, dll).
|
||||
*/
|
||||
public function test_level_1_shows_operational_groups(): void
|
||||
{
|
||||
$response = $this->actingAs($this->qmaAdmin)->get('/qma/vehicles/unit-support');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertViewIs('qma.vehicles_support');
|
||||
$response->assertViewHas('level', 'groups');
|
||||
$response->assertViewHas('groups');
|
||||
|
||||
// Memastikan nama-nama kelompok operasional tampil di tabel Level 1
|
||||
$response->assertSee('HAULING');
|
||||
$response->assertSee('LOADER');
|
||||
$response->assertSee('SUPPORT');
|
||||
$response->assertSee('Lihat Kategori');
|
||||
}
|
||||
|
||||
/**
|
||||
* Level 2: Memilih salah satu Kelompok Operasional menampilkan daftar tipe alat di dalamnya.
|
||||
*/
|
||||
public function test_level_2_shows_types_in_selected_group(): void
|
||||
{
|
||||
$response = $this->actingAs($this->qmaAdmin)->get('/qma/vehicles/unit-support?group=HAULING');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertViewIs('qma.vehicles_support');
|
||||
$response->assertViewHas('level', 'types');
|
||||
$response->assertViewHas('selectedGroup', 'HAULING');
|
||||
|
||||
// Tipe dalam kelompok HAULING
|
||||
$response->assertSee('DUMP TRUCK');
|
||||
$response->assertSee('MIXER TRUCK');
|
||||
|
||||
$typesInView = collect($response->viewData('types')->items())->pluck('unit_type')->all();
|
||||
$this->assertContains('DUMP TRUCK', $typesInView);
|
||||
$this->assertContains('MIXER TRUCK', $typesInView);
|
||||
$this->assertNotContains('EXCAVATOR', $typesInView);
|
||||
$this->assertNotContains('COMPRESSOR', $typesInView);
|
||||
|
||||
// Breadcrumb & tombol kembali
|
||||
$response->assertSee('Semua Kelompok');
|
||||
$response->assertSee('Buka Unit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Level 3: Memilih tipe alat menampilkan daftar unit fisik individual.
|
||||
*/
|
||||
public function test_level_3_shows_physical_units(): void
|
||||
{
|
||||
$response = $this->actingAs($this->qmaAdmin)->get('/qma/vehicles/unit-support?group=HAULING&type=DUMP+TRUCK');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertViewIs('qma.vehicles_support');
|
||||
$response->assertViewHas('level', 'units');
|
||||
$response->assertViewHas('selectedGroup', 'HAULING');
|
||||
$response->assertViewHas('selectedType', 'DUMP TRUCK');
|
||||
|
||||
// Unit fisik Dump Truck
|
||||
$response->assertSee('DT-01');
|
||||
$response->assertSee('DT-02');
|
||||
$response->assertSee('HOWO SINOTRUK 336');
|
||||
$response->assertSee('Main Dam');
|
||||
|
||||
$codesInView = collect($response->viewData('typeUnits')->items())->pluck('code')->all();
|
||||
$this->assertContains('DT-01', $codesInView);
|
||||
$this->assertContains('DT-02', $codesInView);
|
||||
$this->assertNotContains('MT-01', $codesInView);
|
||||
$this->assertNotContains('EX-01', $codesInView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto-detect group jika user hanya memasukkan query parameter `type`.
|
||||
*/
|
||||
public function test_level_3_auto_detects_group_when_only_type_passed(): void
|
||||
{
|
||||
$response = $this->actingAs($this->qmaAdmin)->get('/qma/vehicles/unit-support?type=EXCAVATOR');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertViewHas('level', 'units');
|
||||
$response->assertViewHas('selectedGroup', 'LOADER');
|
||||
$response->assertViewHas('selectedType', 'EXCAVATOR');
|
||||
$response->assertSee('EX-01');
|
||||
$response->assertSee('Power House');
|
||||
}
|
||||
}
|
||||
@@ -379,4 +379,37 @@ class QmaUnitTransferTest extends TestCase
|
||||
$this->assertEquals('Adit 2 Intake', $transporterHistory->location);
|
||||
$this->assertStringContainsString('Mengantar EXCA-01', $transporterHistory->note);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test transfer unit dengan armada pengangkut eksternal (rental/luar)
|
||||
* dengan asal kendaraan manual dan nama unit manual.
|
||||
*/
|
||||
public function test_store_transfer_with_external_transporter(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$payload = [
|
||||
'vehicle_id' => $this->heavyEquipment->id,
|
||||
'from_location' => 'Main Dam',
|
||||
'transfer_date' => Carbon::now()->format('Y-m-d'),
|
||||
'to_location' => 'Adit 2 Intake',
|
||||
'to_site_status' => 'inside_site',
|
||||
'reported_by' => 'Staff QMA Logistik',
|
||||
'transporter_type' => 'external',
|
||||
'transporter_origin_location' => 'Pool Jambi',
|
||||
'transporter_unit_name' => 'Truk Tronton BA 1234 XY (Vendor Subkon)',
|
||||
'transporter_driver_name' => 'Budi Supir Rental',
|
||||
'transporter_description' => 'Lashing rantai 4 titik aman',
|
||||
];
|
||||
|
||||
$response = $this->actingAs($this->qmaAdmin)->post(route('qma.unit_transfers.store'), $payload);
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
$transfer = UnitTransfer::latest('id')->first();
|
||||
$this->assertEquals('external', $transfer->transporter_type);
|
||||
$this->assertNull($transfer->transporter_vehicle_id);
|
||||
$this->assertEquals('Pool Jambi', $transfer->transporter_origin_location);
|
||||
$this->assertEquals('Truk Tronton BA 1234 XY (Vendor Subkon)', $transfer->transporter_unit_name);
|
||||
$this->assertEquals('Budi Supir Rental', $transfer->transporter_driver_name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user