Skip to content

Commit

Permalink
fix: arbitary stand predictor departure airfield
Browse files Browse the repository at this point in the history
Allows an arbitrary icao code to be specified rather than one from the fixed airport list.

Fixes #1412
  • Loading branch information
AndyTWF committed Oct 10, 2023
1 parent dfcda9b commit 8fa333b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/Http/Livewire/StandPredictorForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]))
Expand All @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions tests/app/Http/Livewire/StandPredictorFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8fa333b

Please sign in to comment.