- Added buttons for assigning diagnosis and starting diagnosis based on job card status in the job card view. - Implemented a modal for assigning technicians for diagnosis, including form validation and technician selection. - Updated routes to include a test route for job cards. - Created a new Blade view for testing inspection inputs. - Developed comprehensive feature tests for the estimate module, including creation, viewing, editing, and validation of estimates. - Added tests for estimate model relationships and statistics calculations. - Introduced a basic feature test for job cards index.
108 lines
3.7 KiB
PHP
108 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Customer;
|
|
use App\Models\Estimate;
|
|
use App\Models\User;
|
|
use App\Models\Vehicle;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class EstimatesTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_estimate_model_relationships_work(): void
|
|
{
|
|
// Create test data
|
|
$customer = Customer::factory()->create();
|
|
$vehicle = Vehicle::factory()->create(['customer_id' => $customer->id]);
|
|
$user = User::factory()->create();
|
|
|
|
// Create standalone estimate
|
|
$estimate = Estimate::factory()->create([
|
|
'customer_id' => $customer->id,
|
|
'vehicle_id' => $vehicle->id,
|
|
'prepared_by_id' => $user->id,
|
|
'job_card_id' => null,
|
|
'diagnosis_id' => null,
|
|
]);
|
|
|
|
// Test relationships
|
|
$this->assertEquals($customer->id, $estimate->customer->id);
|
|
$this->assertEquals($vehicle->id, $estimate->vehicle->id);
|
|
$this->assertEquals($user->id, $estimate->preparedBy->id);
|
|
$this->assertNull($estimate->job_card_id);
|
|
$this->assertNull($estimate->diagnosis_id);
|
|
}
|
|
|
|
public function test_estimate_customer_and_vehicle_accessors(): void
|
|
{
|
|
$customer = Customer::factory()->create();
|
|
$vehicle = Vehicle::factory()->create(['customer_id' => $customer->id]);
|
|
$user = User::factory()->create();
|
|
|
|
// Create standalone estimate
|
|
$estimate = Estimate::factory()->create([
|
|
'customer_id' => $customer->id,
|
|
'vehicle_id' => $vehicle->id,
|
|
'prepared_by_id' => $user->id,
|
|
'job_card_id' => null,
|
|
'diagnosis_id' => null,
|
|
]);
|
|
|
|
// Test customer accessor (should return direct customer)
|
|
$this->assertEquals($customer->name, $estimate->estimate_customer->name);
|
|
|
|
// Test vehicle accessor (should return direct vehicle)
|
|
$this->assertEquals($vehicle->make, $estimate->estimate_vehicle->make);
|
|
}
|
|
|
|
public function test_estimate_stats_calculation_with_different_statuses(): void
|
|
{
|
|
$customer = Customer::factory()->create();
|
|
$vehicle = Vehicle::factory()->create(['customer_id' => $customer->id]);
|
|
$user = User::factory()->create();
|
|
|
|
// Create estimates with different statuses
|
|
Estimate::factory()->create([
|
|
'customer_id' => $customer->id,
|
|
'vehicle_id' => $vehicle->id,
|
|
'prepared_by_id' => $user->id,
|
|
'job_card_id' => null,
|
|
'diagnosis_id' => null,
|
|
'status' => 'draft',
|
|
'total_amount' => 100.00,
|
|
]);
|
|
|
|
Estimate::factory()->create([
|
|
'customer_id' => $customer->id,
|
|
'vehicle_id' => $vehicle->id,
|
|
'prepared_by_id' => $user->id,
|
|
'job_card_id' => null,
|
|
'diagnosis_id' => null,
|
|
'status' => 'sent',
|
|
'total_amount' => 200.00,
|
|
]);
|
|
|
|
Estimate::factory()->create([
|
|
'customer_id' => $customer->id,
|
|
'vehicle_id' => $vehicle->id,
|
|
'prepared_by_id' => $user->id,
|
|
'job_card_id' => null,
|
|
'diagnosis_id' => null,
|
|
'status' => 'approved',
|
|
'total_amount' => 300.00,
|
|
]);
|
|
|
|
// Verify the estimates were created with correct status and amounts
|
|
$this->assertEquals(1, Estimate::where('status', 'draft')->count());
|
|
$this->assertEquals(1, Estimate::where('status', 'sent')->count());
|
|
$this->assertEquals(1, Estimate::where('status', 'approved')->count());
|
|
$this->assertEquals(600.00, Estimate::sum('total_amount'));
|
|
}
|
|
}
|