mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
Add a Product Insights tab backed by a suite of price-analysis calculators and a redesigned price history chart. - Insights calculators: listing-history and daily best-price series builders, price stats, percentile, deal score, distribution, drop events, store showdown, seasonality, availability timeline, and target tracker - ProductInsights aggregator service composing the calculators - Price history chart: best-price and target datasets, best-price line honours the unit/retail filter, horizontal scroll on mobile - Rename the History tab to Insights with consistent heading styling - Feature and unit test coverage, plus review-feedback fixes
85 lines
2.9 KiB
PHP
85 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Filament;
|
|
|
|
use App\Filament\Resources\StoreResource\Pages\EditStore;
|
|
use App\Models\Store;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class StoreStrategyDtoBridgeTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->user = User::factory()->create([
|
|
'name' => 'Tester',
|
|
'email' => 'tester@test.com',
|
|
'password' => Hash::make('password'),
|
|
]);
|
|
}
|
|
|
|
public function test_edit_fill_from_dto_populates_form_fields(): void
|
|
{
|
|
$store = Store::factory()->create([
|
|
'scrape_strategy' => [
|
|
'title' => ['type' => 'selector', 'value' => 'h1.title'],
|
|
'price' => ['type' => 'selector', 'value' => '.price'],
|
|
'image' => ['type' => 'selector', 'value' => 'img|src'],
|
|
],
|
|
]);
|
|
|
|
$this->actingAs($this->user);
|
|
|
|
Livewire::test(EditStore::class, ['record' => $store->getKey()])
|
|
->assertFormSet(fn (array $state): bool => data_get($state, 'scrape_strategy.title.type') === 'selector'
|
|
&& data_get($state, 'scrape_strategy.title.value') === 'h1.title'
|
|
&& data_get($state, 'scrape_strategy.price.value') === '.price'
|
|
);
|
|
}
|
|
|
|
public function test_edit_save_persists_strategy_via_dto(): void
|
|
{
|
|
$store = Store::factory()->create([
|
|
'scrape_strategy' => [
|
|
'title' => ['type' => 'selector', 'value' => 'h1.old'],
|
|
'price' => ['type' => 'selector', 'value' => '.price'],
|
|
'image' => ['type' => 'selector', 'value' => 'img|src'],
|
|
],
|
|
]);
|
|
|
|
$this->actingAs($this->user);
|
|
|
|
Livewire::test(EditStore::class, ['record' => $store->getKey()])
|
|
// Clear the repeater's record-seeded rows first so fillForm() sets exactly the
|
|
// domains below instead of merging into the existing UUID-keyed repeater state.
|
|
->set('data.domains', null)
|
|
->fillForm([
|
|
'name' => $store->name,
|
|
'domains' => [
|
|
['domain' => 'example.com'],
|
|
],
|
|
'settings.locale_settings.locale' => 'en_US',
|
|
'settings.locale_settings.currency' => 'USD',
|
|
'scrape_strategy.title.value' => 'h2.new',
|
|
'scrape_strategy.title.type' => 'selector',
|
|
'scrape_strategy.price.value' => '.price',
|
|
'scrape_strategy.price.type' => 'selector',
|
|
'scrape_strategy.image.value' => 'img|src',
|
|
'scrape_strategy.image.type' => 'selector',
|
|
])
|
|
->call('save')
|
|
->assertHasNoFormErrors();
|
|
|
|
$store->refresh();
|
|
|
|
$this->assertSame('h2.new', $store->scrape_strategy->title->value);
|
|
}
|
|
}
|