phpvms/tests/Feature/Filament/FlightBundleResourceTest.php
Nabeel Shahzad 28f49b97c3
feat(schema-modernization): foundations for RouteForge
Schema, model, Filament, cron, and visibility-semantics foundations
required by the RouteForge change. Four phases delivered as one
coherent change. Verified against four spec files (flight-bundles,
flight-time-storage, subfleet-capability, flight-visibility).

Phase 1.1 \xe2\x80\x94 Flight time columns
- flights.departure_time, flights.arrival_time TIME NULL
- Flight model accessors (Hi-format) + mutators (FlightTimeParser)
- FlightTimeParser supports 9 formats + Z/L/tz suffix stripping
- Migration backfills inline via chunked raw DB::table->update()
- Legacy dpt_time/arr_time VARCHAR columns preserved for one release

Phase 1.2 \xe2\x80\x94 Subfleet capability columns
- subfleets.cruise_speed, max_range_nm, route_types (CSV VARCHAR(64))
- FlightTypesCast splits/sorts/dedupes/logs-on-invalid
- routeforge defaults in config/phpvms.php
- SubfleetForm Operational Capability section

Phase 1.3 \xe2\x80\x94 Flight Bundles
- flight_bundles table + flights.bundle_id NOT NULL FK
- Default bundle seeded inline; existing flights backfilled
- FlightBundle model + factory + BundleObserver (queued recompute)
- FlightBundleResource as sole Flights nav entry (slug=flights,
  icon=OutlinedMap, sort=2)
- Nested FlightResource under FlightBundleResource (slug=flight,
  parentResource, create+edit only, no nav entry)
- FlightsRelationManager with relatedResource for full-page row actions
- FlightForm: bundle selector removed (route-bound), date inputs
  hidden when parent bundle owns dates, XSS-safe placeholder link
- Date columns stored as TIMESTAMP UTC, UI converts to local tz
- Soft-deleting a bundle leaves children non-deleted; visibility
  recompute sets visible=false (no cascade delete)
- Spatie Shield permissions: flight_bundle.* seeded

Phase 1.4 \xe2\x80\x94 Visibility semantics
- flights.active renamed to flights.enabled (admin source of truth)
- flights.visible is cron-managed combined state
- SetActiveFlights cron deleted; SetVisibleFlights cron added
- Two-pass bulk SQL UPDATE scoped by bundle, chunks of 500
- RecomputeBundleVisibility queued job dispatched on bundle save/restore
- Flight::scopeVisible added; scopeActive retained as plain alias
- Pilot-facing read sites use ->visible() (AirportController fix)
- FlightResource JSON + FlightExporter CSV expose both enabled+active
- Four-state status badge (Disabled / Disabled by Bundle / Enabled
  Out of Window / Enabled & In Window) replaces Visible toggle
- 5 visibility indexes added

Verification
- 469 Pest tests passed (2058 assertions)
- phpstan level 5 clean (646 files)
- pint --test clean
- rector --dry-run clean
- All four spec files PASS (28 requirements + 36 scenarios verified
  by kimi-spec-reviewer)

Migration path documented in docs/UPGRADING.md and openspec/changes/
schema-modernization-for-routeforge/.
2026-05-23 12:05:09 -05:00

84 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Resources\FlightBundles\Pages\CreateFlightBundle;
use App\Filament\Resources\FlightBundles\Pages\EditFlightBundle;
use App\Filament\Resources\FlightBundles\Pages\ListFlightBundles;
use App\Models\FlightBundle;
use Database\Seeders\ShieldSeeder;
use Livewire\Livewire;
it('renders the list page happy path', function (): void {
$this->seed(ShieldSeeder::class);
$admin = createAdminUser();
$bundle = FlightBundle::factory()->create(['name' => 'Test Bundle']);
Livewire::test(ListFlightBundles::class)
->assertSuccessful()
->assertCanSeeTableRecords([$bundle]);
});
it('creates a new bundle and persists created_by', function (): void {
$this->seed(ShieldSeeder::class);
$admin = createAdminUser();
$this->actingAs($admin);
Livewire::test(CreateFlightBundle::class)
->fillForm([
'name' => 'Promo Q3',
'enabled' => true,
])
->call('create')
->assertHasNoFormErrors();
$this->assertDatabaseHas('flight_bundles', [
'name' => 'Promo Q3',
'created_by' => $admin->id,
]);
});
it('renders the edit page happy path', function (): void {
$this->seed(ShieldSeeder::class);
$admin = createAdminUser();
$bundle = FlightBundle::factory()->create();
Livewire::test(EditFlightBundle::class, ['record' => $bundle->getRouteKey()])
->assertSuccessful();
});
it('shows delete action for default bundle', function (): void {
$this->seed(ShieldSeeder::class);
$admin = createAdminUser();
// The default bundle is seeded by migration 2026_05_19_100003
$defaultBundle = FlightBundle::query()->where('is_default', true)->first();
expect($defaultBundle)->not->toBeNull();
Livewire::test(ListFlightBundles::class)
->assertTableActionVisible('delete', $defaultBundle);
});
it('enabled toggle is editable on default bundle edit page', function (): void {
$this->seed(ShieldSeeder::class);
$admin = createAdminUser();
$default = FlightBundle::query()->where('is_default', true)->first();
expect($default)->not->toBeNull();
// Page renders successfully — enabled toggle is no longer disabled.
Livewire::test(EditFlightBundle::class, ['record' => $default->getRouteKey()])
->assertSuccessful()
->assertFormFieldExists('enabled');
});