diff --git a/app/Livewire/Public/Fuel/StationList.php b/app/Livewire/Public/Fuel/StationList.php new file mode 100644 index 0000000..8d0384e --- /dev/null +++ b/app/Livewire/Public/Fuel/StationList.php @@ -0,0 +1,34 @@ +results = $results; + $this->meta = $meta; + $this->radius = $radius; + $this->hasSearched = true; + } + + public function render(): View + { + return view('livewire.public.fuel.station-list'); + } +} diff --git a/resources/views/livewire/public/fuel/station-list.blade.php b/resources/views/livewire/public/fuel/station-list.blade.php new file mode 100644 index 0000000..ac6fb19 --- /dev/null +++ b/resources/views/livewire/public/fuel/station-list.blade.php @@ -0,0 +1,24 @@ +
+ @if ($hasSearched) +
+ @if (! empty($meta)) +
+

Stations Nearby

+ + {{ $meta['count'] ?? 0 }} {{ str('Result')->plural($meta['count'] ?? 0) }} + +
+ @endif + + @forelse ($results as $station) +
+ +
+ @empty +

+ No stations found within {{ $radius }} {{ str('mile')->plural($radius) }} of "{{ $search }}". +

+ @endforelse +
+ @endif +
diff --git a/tests/Feature/Livewire/Fuel/StationListTest.php b/tests/Feature/Livewire/Fuel/StationListTest.php new file mode 100644 index 0000000..eff7c10 --- /dev/null +++ b/tests/Feature/Livewire/Fuel/StationListTest.php @@ -0,0 +1,73 @@ +assertStatus(200) + ->assertSet('hasSearched', false) + ->assertDontSee('Stations Nearby'); +}); + +it('shows station cards after stations-found event', function () { + $station = [ + 'station_id' => 'abc123', + 'name' => 'BP Garage', + 'brand' => 'BP', + 'is_supermarket' => false, + 'address' => '1 High Street', + 'postcode' => 'SW1A 1AA', + 'lat' => 51.5074, + 'lng' => -0.1278, + 'distance_km' => 1.5, + 'fuel_type' => 'e10', + 'price_pence' => 14390, + 'price' => 143.9, + 'price_updated_at' => '2026-04-05T08:00:00.000Z', + 'price_classification' => 'current', + 'price_classification_label' => 'Current', + ]; + $meta = ['count' => 1, 'lowest_pence' => 14390, 'avg_pence' => 14390.0]; + + Livewire::test(StationList::class) + ->dispatch('stations-found', results: [$station], meta: $meta, prediction: null, radius: 5) + ->assertSet('hasSearched', true) + ->assertSee('Stations Nearby') + ->assertSee('BP Garage') + ->assertSee('1 Result'); +}); + +it('shows empty state message when stations-found has no results', function () { + Livewire::test(StationList::class) + ->set('search', 'ZZ99 9ZZ') + ->dispatch('stations-found', results: [], meta: ['count' => 0], prediction: null, radius: 5) + ->assertSet('hasSearched', true) + ->assertSee('No stations found'); +}); + +it('updates results when stations-found fires again', function () { + $station = [ + 'station_id' => 'abc123', + 'name' => 'BP Garage', + 'brand' => 'BP', + 'is_supermarket' => false, + 'address' => '1 High Street', + 'postcode' => 'SW1A 1AA', + 'lat' => 51.5074, + 'lng' => -0.1278, + 'distance_km' => 1.5, + 'fuel_type' => 'e10', + 'price_pence' => 14390, + 'price' => 143.9, + 'price_updated_at' => '2026-04-05T08:00:00.000Z', + 'price_classification' => 'current', + 'price_classification_label' => 'Current', + ]; + + Livewire::test(StationList::class) + ->dispatch('stations-found', results: [$station], meta: ['count' => 1], prediction: null, radius: 5) + ->assertSee('BP Garage') + ->dispatch('stations-found', results: [], meta: ['count' => 0], prediction: null, radius: 5) + ->assertDontSee('BP Garage'); +});