# GUI Testing Guide for 11-Step Automotive Repair Workflow

## 🌐 Prerequisites
- Development server running on `http://localhost:8000` (or your configured port)
- Database seeded with test data
- User accounts with different roles (Admin, Service Advisor, Service Coordinator, Technician)

## 🚀 Step-by-Step GUI Testing

### Phase 1: Setup and Login

#### 1. Access the Application
- Open browser and navigate to: `http://localhost:8000`
- You should see the login page or be redirected based on authentication

#### 2. Create Test Users (if needed)
```bash
# Run this in terminal to create test users
php artisan tinker --execute="
// Create test users with different roles
\$admin = App\Models\User::factory()->create([
    'name' => 'Test Admin',
    'email' => 'admin@test.com',
    'password' => bcrypt('password'),
    'role' => 'admin'
]);

\$advisor = App\Models\User::factory()->create([
    'name' => 'Service Advisor',
    'email' => 'advisor@test.com', 
    'password' => bcrypt('password'),
    'role' => 'service_advisor'
]);

\$coordinator = App\Models\User::factory()->create([
    'name' => 'Service Coordinator',
    'email' => 'coordinator@test.com',
    'password' => bcrypt('password'),
    'role' => 'service_coordinator'
]);

\$technician = App\Models\User::factory()->create([
    'name' => 'Technician',
    'email' => 'tech@test.com',
    'password' => bcrypt('password'),
    'role' => 'technician'
]);

echo 'Test users created successfully!';
"
```

#### 3. Create Test Customer and Vehicle Data
```bash
php artisan tinker --execute="
\$customer = App\Models\Customer::factory()->create([
    'first_name' => 'John',
    'last_name' => 'Doe',
    'email' => 'john.doe@example.com',
    'phone' => '555-0123'
]);

\$vehicle = App\Models\Vehicle::factory()->create([
    'customer_id' => \$customer->id,
    'make' => 'Toyota',
    'model' => 'Camry',
    'year' => 2020,
    'vin' => '1234567890ABCDEFG',
    'license_plate' => 'ABC123'
]);

echo 'Test customer and vehicle created: Customer ID ' . \$customer->id . ', Vehicle ID ' . \$vehicle->id;
"
```

### Phase 2: Workflow Testing

#### 🔹 Step 1: Vehicle Reception (STATUS_RECEIVED)

**Login as Service Advisor** (`advisor@test.com` / `password`)

1. **Navigate to Job Cards**
   - Go to `/job-cards` or find "Job Cards" in the navigation
   - Click "Create New Job Card" or similar button

2. **Fill Out Reception Form**
   - **Customer**: Select "John Doe" from dropdown
   - **Vehicle**: Select "Toyota Camry (ABC123)"
   - **Branch Code**: Select "ACC" 
   - **Arrival Date/Time**: Current date/time
   - **Mileage In**: Enter "75000"
   - **Fuel Level In**: Select "Half"
   - **Customer Reported Issues**: Enter "Engine making noise during acceleration"
   - **Vehicle Condition Notes**: Enter "Vehicle appears clean, customer reports issue started 2 weeks ago"
   - **Keys Location**: Select "Service Desk"
   - **Personal Items Removed**: Check the box
   - **Photos Taken**: Check the box

3. **Submit and Verify**
   - Click "Create Job Card"
   - Verify job card number starts with "ACC/" (e.g., ACC/00001)
   - Verify status shows "Vehicle Received"
   - Note the Job Card ID for next steps

#### 🔹 Step 2: Initial Inspection (STATUS_INSPECTED)

**Stay logged in as Service Advisor or switch to Inspector role**

1. **Access Job Card**
   - Find the job card created in Step 1
   - Click "View" or "Edit" to open job card details

2. **Perform Initial Inspection**
   - Look for "Initial Inspection" button or tab
   - Fill out inspection checklist:
     - **Engine**: Select "Fair"
     - **Brakes**: Select "Good" 
     - **Tires**: Select "Excellent"
     - **Oil Level**: Select "Full"
     - **Coolant Level**: Select "Full"
     - **Battery**: Select "Good"
   - **Overall Condition**: Enter "Engine requires diagnosis, other systems in good condition"
   - **Inspector Notes**: Enter "Noise audible during test drive, engine vibration detected"

3. **Complete Inspection**
   - Click "Complete Initial Inspection"
   - Verify status changes to "Initial Inspection Complete"
   - Check that inspection data is saved in the system

#### 🔹 Step 3: Service Assignment (STATUS_ASSIGNED_FOR_DIAGNOSIS)

**Login as Admin or Service Manager**

1. **Access Job Card Management**
   - Navigate to job cards list
   - Find the inspected job card
   - Click "Assign for Diagnosis"

2. **Assign to Service Coordinator**
   - **Service Coordinator**: Select "Service Coordinator" from dropdown
   - **Priority Level**: Select "Medium"
   - **Estimated Completion**: Set date 2-3 days from now
   - **Assignment Notes**: Enter "Please diagnose engine noise issue"

3. **Confirm Assignment**
   - Click "Assign"
   - Verify status changes to "Assigned for Diagnosis"
   - Check that diagnosis record is created

### Phase 3: Customer Portal Testing

#### 🔹 Test Customer Portal Access

1. **Create Customer User Account**
```bash
php artisan tinker --execute="
\$customer = App\Models\Customer::where('email', 'john.doe@example.com')->first();
\$customerUser = App\Models\User::factory()->create([
    'name' => \$customer->first_name . ' ' . \$customer->last_name,
    'email' => \$customer->email,
    'password' => bcrypt('password'),
    'role' => 'customer'
]);

// Link customer to user
\$customer->update(['user_id' => \$customerUser->id]);
echo 'Customer user account created';
"
```

2. **Login as Customer** (`john.doe@example.com` / `password`)
   - Should be redirected to `/customer-portal`
   - Should see dashboard with active job cards

3. **Test Workflow Progress Component**
   - Navigate to job card details
   - Verify progress visualization shows:
     - ✅ Step 1: Vehicle Reception (Completed)
     - ✅ Step 2: Initial Inspection (Completed) 
     - 🔄 Step 3: Service Assignment (Current)
     - ⏳ Steps 4-11: Pending
   - Check progress percentage calculation
   - Verify service advisor contact information displays

### Phase 4: Management Analytics Testing

#### 🔹 Test Management Dashboard

**Login as Admin** (`admin@test.com` / `password`)

1. **Access Analytics Dashboard**
   - Navigate to `/reports/workflow-analytics`
   - Should see comprehensive dashboard

2. **Verify Key Metrics Display**
   - **Total Revenue**: Should show calculated amount
   - **Completed Jobs**: Should show count
   - **Average Turnaround**: Should show days
   - **Quality Alerts**: Should show count

3. **Test Filtering**
   - **Branch Filter**: Select different branches (ACC, KSI)
   - **Time Period**: Test "Last 7 Days", "Last 30 Days", etc.
   - Verify charts and data update accordingly

4. **Test Export Functionality**
   - Click "Export Workflow Report"
   - Click "Export Labor Utilization" 
   - Click "Export Quality Metrics"
   - Verify files download or reports generate

### Phase 5: Advanced Workflow Testing

#### 🔹 Test Workflow Progression Validation

1. **Create New Job Card**
   - Create another job card in "Received" status

2. **Try to Skip Steps**
   - Attempt to assign directly to diagnosis without inspection
   - Should see validation error preventing invalid progression

3. **Test Status Transitions**
   - Progress through each step in correct order
   - Verify each status change is properly recorded
   - Check timestamps are accurate

#### 🔹 Test Quality Control System

1. **Complete Initial Inspection**
   - Record inspection with some "Fair" or "Poor" ratings

2. **Later Complete Final Inspection**
   - Record outgoing inspection with improved ratings
   - System should detect improvements automatically

3. **Generate Quality Alerts**
   - Create scenario where outgoing inspection is worse than incoming
   - Verify quality alert is generated and displayed

### Phase 6: Multi-Branch Testing

#### 🔹 Test Branch-Specific Operations

1. **Create Job Cards for Different Branches**
   - Create job card with branch code "ACC"
   - Create job card with branch code "KSI"
   - Create job card with branch code "NBO"

2. **Verify Branch-Specific Numbering**
   - ACC jobs should have format: ACC/00001, ACC/00002, etc.
   - KSI jobs should have format: KSI/00001, KSI/00002, etc.
   - Numbering should be independent per branch

3. **Test Branch Filtering**
   - In analytics dashboard, filter by specific branch
   - Verify only that branch's data appears
   - Test "All Branches" shows combined data

### Phase 7: Error Handling and Edge Cases

#### 🔹 Test Error Scenarios

1. **Invalid Data Entry**
   - Try submitting forms with missing required fields
   - Verify validation messages appear
   - Check error handling is user-friendly

2. **Workflow Validation**
   - Try accessing steps out of order
   - Verify proper error messages
   - Ensure system maintains data integrity

3. **Permission Testing**
   - Login as different user roles
   - Verify role-based access restrictions
   - Test that users only see appropriate sections

## 🎯 Expected Results Checklist

### ✅ Job Card Management
- [ ] Job cards can be created with proper branch-specific numbering
- [ ] Status progression follows 11-step workflow correctly
- [ ] All required fields are validated properly
- [ ] Data persists correctly between steps

### ✅ Customer Portal
- [ ] Customers can view their job card progress
- [ ] Progress visualization shows current step clearly
- [ ] Estimated completion times display
- [ ] Contact information is accessible

### ✅ Management Analytics
- [ ] Dashboard loads without errors
- [ ] All metrics calculate correctly
- [ ] Filtering works across branches and time periods
- [ ] Export functionality generates reports

### ✅ Quality Control
- [ ] Inspection checklists save properly
- [ ] Quality comparisons detect improvements/issues
- [ ] Quality alerts generate when appropriate
- [ ] Historical inspection data is preserved

### ✅ User Experience
- [ ] Navigation is intuitive across all user roles
- [ ] Loading times are acceptable
- [ ] Error messages are clear and helpful
- [ ] Interface is responsive on different screen sizes

## 🚨 Troubleshooting Common Issues

### Issue: "Page Not Found" Errors
**Solution**: Check routes are properly registered in `routes/web.php`

### Issue: Permission Denied
**Solution**: Verify user has correct role and permissions

### Issue: Database Errors
**Solution**: Ensure migrations are up to date: `php artisan migrate`

### Issue: Livewire Component Not Loading
**Solution**: Clear cache: `php artisan view:clear && php artisan route:clear`

### Issue: Missing CSS/JS Assets
**Solution**: Build assets: `npm run build` or `npm run dev`

## 📋 Testing Completion Verification

Once you've completed all testing phases, verify:

1. **Workflow Integrity**: Each step transitions correctly
2. **Data Consistency**: Information persists accurately 
3. **User Experience**: Interface is intuitive for all roles
4. **Performance**: Pages load quickly and smoothly
5. **Error Handling**: Graceful handling of invalid operations
6. **Security**: Proper access controls for different user types

Your 11-step automotive repair workflow is now fully tested and ready for production use! 🎉
