Files
pricebuddy/tests/Feature/Filament/ViewProductPriceSummaryTest.php
Jeremy 851b8349f3 feat: show min/avg/max price summary under image on product view
Reuses the existing components/price-aggregates partial (already aggregates
min/avg/max across all of a product's URLs) under the product image on the
overview tab. Hidden when the product has no price history yet.
2026-06-13 12:36:55 +10:00

51 lines
1.5 KiB
PHP

<?php
namespace Tests\Feature\Filament;
use App\Filament\Resources\ProductResource;
use App\Models\Product;
use App\Models\Url;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ViewProductPriceSummaryTest extends TestCase
{
use RefreshDatabase;
public function test_view_shows_price_min_avg_max(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$product = Product::factory()->create(['user_id' => $user->id]);
Url::factory()->withPrices([30, 20, 25])->createOne(['product_id' => $product->id]);
$aggregates = $product->refresh()->price_aggregates;
$this->assertNotEmpty($aggregates);
$response = $this->get(ProductResource::getUrl('view', ['record' => $product]));
$response->assertOk();
// The summary block is rendered.
$response->assertSee('product-price-summary');
// And it shows each aggregate value.
foreach (['min', 'avg', 'max'] as $method) {
$response->assertSee($aggregates[$method]);
}
}
public function test_view_hides_summary_when_no_price_history(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$product = Product::factory()->create(['user_id' => $user->id]);
$this->get(ProductResource::getUrl('view', ['record' => $product]))
->assertOk()
->assertDontSee('product-price-summary');
}
}