Files
pricebuddy/tests/Feature/View/StatBarTest.php

60 lines
1.6 KiB
PHP

<?php
namespace Tests\Feature\View;
use App\Services\Helpers\CurrencyHelper;
use App\Services\Helpers\SettingsHelper;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class StatBarTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
SettingsHelper::$settings = null;
SettingsHelper::setSetting('default_locale_settings', ['locale' => 'en', 'currency' => 'USD']);
}
protected function tearDown(): void
{
SettingsHelper::$settings = null;
parent::tearDown();
}
private function renderStatBar(array $overrides = []): string
{
$stats = array_merge([
'tracked' => 10,
'atLowest' => 2,
'belowAverage' => 3,
'outOfStock' => 1,
'potentialSavings' => 123.45,
], $overrides);
return (string) $this->view('filament.widgets.dashboard.stat-bar', ['stats' => $stats]);
}
public function test_potential_savings_uses_configured_currency(): void
{
SettingsHelper::setSetting('default_locale_settings', ['locale' => 'en_IE', 'currency' => 'EUR']);
$html = $this->renderStatBar();
$this->assertStringContainsString(CurrencyHelper::toString(123.45), $html);
$this->assertStringContainsString('€', $html);
$this->assertStringNotContainsString('$123.45', $html);
}
public function test_potential_savings_configured_usd_renders_dollar_value(): void
{
$html = $this->renderStatBar(['potentialSavings' => 123.45]);
$this->assertStringContainsString('$123.45', $html);
}
}