diff --git a/app/Livewire/Public/Fuel/Recommendation.php b/app/Livewire/Public/Fuel/Recommendation.php new file mode 100644 index 0000000..7140e95 --- /dev/null +++ b/app/Livewire/Public/Fuel/Recommendation.php @@ -0,0 +1,23 @@ +prediction = $prediction; + } + + public function render(): View + { + return view('livewire.public.fuel.recommendation'); + } +} diff --git a/resources/views/livewire/public/fuel/recommendation.blade.php b/resources/views/livewire/public/fuel/recommendation.blade.php new file mode 100644 index 0000000..a153557 --- /dev/null +++ b/resources/views/livewire/public/fuel/recommendation.blade.php @@ -0,0 +1,7 @@ +
+ @if ($prediction) +
+ +
+ @endif +
diff --git a/tests/Feature/Livewire/Fuel/RecommendationTest.php b/tests/Feature/Livewire/Fuel/RecommendationTest.php new file mode 100644 index 0000000..a4dd1fa --- /dev/null +++ b/tests/Feature/Livewire/Fuel/RecommendationTest.php @@ -0,0 +1,52 @@ +assertStatus(200) + ->assertSet('prediction', null) + ->assertDontSee('Recommendation'); +}); + +it('shows recommendation card when stations-found includes a prediction', function () { + $prediction = [ + 'action' => 'fill_now', + 'confidence_score' => 80.0, + 'confidence_label' => 'high', + 'reasoning' => 'Prices are rising sharply.', + 'predicted_direction' => 'up', + 'predicted_change_pence' => 3.5, + ]; + + Livewire::test(Recommendation::class) + ->dispatch('stations-found', results: [], meta: [], prediction: $prediction, radius: 5) + ->assertSet('prediction', $prediction) + ->assertSee('Recommendation') + ->assertSee('Fill up now'); +}); + +it('shows nothing when stations-found has null prediction', function () { + Livewire::test(Recommendation::class) + ->dispatch('stations-found', results: [], meta: [], prediction: null, radius: 5) + ->assertSet('prediction', null) + ->assertDontSee('Recommendation'); +}); + +it('clears previous prediction when new stations-found fires with null prediction', function () { + $prediction = [ + 'action' => 'fill_now', + 'confidence_score' => 80.0, + 'confidence_label' => 'high', + 'reasoning' => 'Prices rising.', + 'predicted_direction' => 'up', + 'predicted_change_pence' => 3.5, + ]; + + Livewire::test(Recommendation::class) + ->dispatch('stations-found', results: [], meta: [], prediction: $prediction, radius: 5) + ->assertSee('Recommendation') + ->dispatch('stations-found', results: [], meta: [], prediction: null, radius: 5) + ->assertDontSee('Recommendation'); +});