From 8fa333b8cd048e5fa6ee2427a3eebe69c9fffc25 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Tue, 10 Oct 2023 17:31:00 +0100 Subject: [PATCH 1/2] fix: arbitary stand predictor departure airfield Allows an arbitrary icao code to be specified rather than one from the fixed airport list. Fixes #1412 --- app/Http/Livewire/StandPredictorForm.php | 12 +++++--- .../Http/Livewire/StandPredictorFormTest.php | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/app/Http/Livewire/StandPredictorForm.php b/app/Http/Livewire/StandPredictorForm.php index ebc1f47fa..74a2da59e 100644 --- a/app/Http/Livewire/StandPredictorForm.php +++ b/app/Http/Livewire/StandPredictorForm.php @@ -4,6 +4,7 @@ use App\Filament\Helpers\SelectOptions; use App\Models\Airfield\Airfield; +use App\Rules\Airfield\AirfieldIcao; use App\Services\AirlineService; use Filament\Forms\Components\Grid; use Filament\Forms\Components\Select; @@ -42,11 +43,11 @@ public function getFormSchema(): array ->options(SelectOptions::aircraftTypes()) ->required() ->searchable(), - Select::make('departureAirfield') + TextInput::make('departureAirfield') ->label('Departure Airfield') - ->options(Airfield::all()->mapWithKeys(fn ($airfield) => [$airfield->code => $airfield->code])) - ->required() - ->searchable(), + ->rule(new AirfieldIcao()) + ->alpha() + ->required(), Select::make('arrivalAirfield') ->label('Arrival Airfield') ->options(Airfield::all()->mapWithKeys(fn ($airfield) => [$airfield->code => $airfield->code])) @@ -58,6 +59,9 @@ public function getFormSchema(): array public function submit(): void { + // Convert the callsign to uppercase before validating it. + $this->callsign = strtoupper($this->callsign); + $this->form->validate(); $this->emit('standPredictorFormSubmitted', [ 'callsign' => $this->callsign, diff --git a/tests/app/Http/Livewire/StandPredictorFormTest.php b/tests/app/Http/Livewire/StandPredictorFormTest.php index 1a95b323d..90fc32be0 100644 --- a/tests/app/Http/Livewire/StandPredictorFormTest.php +++ b/tests/app/Http/Livewire/StandPredictorFormTest.php @@ -32,6 +32,25 @@ public function testItSubmits() ]); } + public function testItSubmitsLowercaseDepartureAirfield() + { + Livewire::test(StandPredictorForm::class) + ->set('callsign', 'BAW999') + ->set('aircraftType', 1) + ->set('departureAirfield', 'egkk') + ->set('arrivalAirfield', 'EGLL') + ->call('submit') + ->assertHasNoErrors() + ->assertEmitted('standPredictorFormSubmitted', [ + 'callsign' => 'BAW999', + 'cid' => 1203533, + 'aircraft_id' => 1, + 'airline_id' => 1, + 'planned_depairport' => 'EGKK', + 'planned_destairport' => 'EGLL', + ]); + } + public function testItDoesntSubmitIfNoCallsign() { Livewire::test(StandPredictorForm::class) @@ -64,6 +83,17 @@ public function testItDoesntSubmitIfNoDepartureAirfield() ->assertNotEmitted('standPredictorFormSubmitted'); } + public function testItDoesntSubmitIfDepartureAirfieldNotIcao() + { + Livewire::test(StandPredictorForm::class) + ->set('callsign', 'BAW123') + ->set('arrivalAirfield', 'EGLL') + ->set('departureAirfield', '1234X') + ->call('submit') + ->assertHasErrors(['departureAirfield']) + ->assertNotEmitted('standPredictorFormSubmitted'); + } + public function testItDoesntSubmitIfNoArrivalAirfield() { Livewire::test(StandPredictorForm::class) From b7dfecd338858784d02c3f2ffb4131f559326a6d Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Tue, 10 Oct 2023 17:34:19 +0100 Subject: [PATCH 2/2] did the wrong field --- app/Http/Livewire/StandPredictorForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Livewire/StandPredictorForm.php b/app/Http/Livewire/StandPredictorForm.php index 74a2da59e..7334b03f3 100644 --- a/app/Http/Livewire/StandPredictorForm.php +++ b/app/Http/Livewire/StandPredictorForm.php @@ -60,7 +60,7 @@ public function getFormSchema(): array public function submit(): void { // Convert the callsign to uppercase before validating it. - $this->callsign = strtoupper($this->callsign); + $this->departureAirfield = strtoupper($this->departureAirfield); $this->form->validate(); $this->emit('standPredictorFormSubmitted', [