159 lines
5.3 KiB
PHP
159 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\DailyReports\Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Modules\DailyReports\Models\DailyReport;
|
|
use Modules\Equipments\Models\Equipment;
|
|
use Modules\Labors\Models\Labor;
|
|
use Modules\MasterData\Models\Material;
|
|
use Modules\ProjectManagement\Enums\ProjectStatus;
|
|
use Modules\ProjectManagement\Models\Project;
|
|
use Modules\ProjectManagement\Models\Task;
|
|
use Spatie\Permission\Models\Permission;
|
|
use Spatie\Permission\Models\Role;
|
|
use Tests\TestCase;
|
|
|
|
class DailyReportEstimationScopedDropdownsTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $admin;
|
|
protected Project $project;
|
|
protected Labor $estimatedLabor;
|
|
protected Equipment $estimatedEquipment;
|
|
protected Material $estimatedMaterial;
|
|
protected Task $task;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$role = Role::firstOrCreate(['name' => 'Super Admin', 'guard_name' => 'web']);
|
|
Permission::firstOrCreate(['name' => 'projects.access', 'guard_name' => 'web']);
|
|
|
|
$this->admin = User::factory()->create([
|
|
'status' => 'active',
|
|
'user_type' => 'admin',
|
|
]);
|
|
$this->admin->assignRole($role);
|
|
|
|
$this->project = Project::create([
|
|
'name' => 'Highland Heights Tower',
|
|
'code' => 'PRJ-HHT-2026',
|
|
'status' => ProjectStatus::InProgress,
|
|
'project_type' => 'standard',
|
|
'is_unprofitable' => false,
|
|
'contract_value' => 12000000.00,
|
|
'current_wizard_step' => 8,
|
|
]);
|
|
|
|
$this->estimatedLabor = Labor::create([
|
|
'name' => 'Master Electrician',
|
|
'category' => 'skilled',
|
|
'hourly_rate' => 150.00,
|
|
]);
|
|
|
|
$this->estimatedEquipment = Equipment::create([
|
|
'name' => 'Caterpillar 320 Excavator',
|
|
'category' => 'Heavy Machinery',
|
|
'hourly_rate' => 2500.00,
|
|
]);
|
|
|
|
$this->estimatedMaterial = Material::create([
|
|
'name' => 'Deformed Steel Bar 16mm',
|
|
'sku' => 'ST-BAR-16',
|
|
'unit' => 'length',
|
|
'unit_cost' => 450.00,
|
|
'category' => 'steel',
|
|
'type' => 'raw',
|
|
'status' => 'active',
|
|
]);
|
|
|
|
$this->project->materialsEstimates()->create([
|
|
'material_id' => $this->estimatedMaterial->id,
|
|
'estimated_qty' => 500,
|
|
'unit_cost' => 450.00,
|
|
]);
|
|
|
|
$this->task = $this->project->tasks()->create([
|
|
'name' => 'Foundation Structural Works',
|
|
'sort_order' => 1,
|
|
'duration_days' => 14,
|
|
'status' => 'in_progress',
|
|
]);
|
|
|
|
$this->task->taskLabors()->create([
|
|
'labor_id' => $this->estimatedLabor->id,
|
|
'estimated_hours' => 80,
|
|
]);
|
|
|
|
$this->task->taskEquipments()->create([
|
|
'equipment_id' => $this->estimatedEquipment->id,
|
|
'estimated_hours' => 40,
|
|
]);
|
|
}
|
|
|
|
/** @test */
|
|
public function test_create_page_loads_project_tasks_and_estimation_resources(): void
|
|
{
|
|
$response = $this->actingAs($this->admin)->get(route('projects.daily-reports.create', [
|
|
'project' => $this->project->ulid,
|
|
]));
|
|
|
|
$response->assertOk();
|
|
$projectProp = $response->viewData('page')['props']['project'];
|
|
$this->assertNotNull($projectProp);
|
|
$this->assertEquals($this->project->ulid, $projectProp['ulid']);
|
|
$this->assertNotEmpty($projectProp['tasks']);
|
|
|
|
$task = $projectProp['tasks'][0];
|
|
$this->assertNotEmpty($task['task_labors']);
|
|
$this->assertEquals('Master Electrician', $task['task_labors'][0]['labor']['name']);
|
|
|
|
$this->assertNotEmpty($task['task_equipments']);
|
|
$this->assertEquals('Caterpillar 320 Excavator', $task['task_equipments'][0]['equipment']['name']);
|
|
}
|
|
|
|
/** @test */
|
|
public function test_edit_page_loads_project_estimation_resources(): void
|
|
{
|
|
$report = DailyReport::create([
|
|
'project_id' => $this->project->id,
|
|
'user_id' => $this->admin->id,
|
|
'report_number' => 'DR-2026-001',
|
|
'report_date' => '2026-08-26',
|
|
'weather' => 'Sunny',
|
|
'status' => 'draft',
|
|
]);
|
|
|
|
$report->labors()->create([
|
|
'trade' => 'Master Electrician',
|
|
'workers_count' => 4,
|
|
'hours' => 8,
|
|
]);
|
|
|
|
$report->equipment()->create([
|
|
'equipment_name' => 'Caterpillar 320 Excavator',
|
|
'hours_used' => 6,
|
|
'status' => 'Active',
|
|
]);
|
|
|
|
$response = $this->actingAs($this->admin)->get(route('projects.daily-reports.edit', [
|
|
'daily_report' => $report->id,
|
|
]));
|
|
|
|
$response->assertOk();
|
|
$reportProp = $response->viewData('page')['props']['report'];
|
|
$this->assertNotNull($reportProp['project']);
|
|
$this->assertNotEmpty($reportProp['project']['tasks']);
|
|
|
|
$task = $reportProp['project']['tasks'][0];
|
|
$this->assertNotEmpty($task['task_labors']);
|
|
$this->assertEquals('Master Electrician', $task['task_labors'][0]['labor']['name']);
|
|
$this->assertNotEmpty($task['task_equipments']);
|
|
$this->assertEquals('Caterpillar 320 Excavator', $task['task_equipments'][0]['equipment']['name']);
|
|
}
|
|
}
|