TenantAtlas/tests/Unit/Support/Ui/EnterpriseDetail/FactPresentationTest.php
2026-03-11 00:05:33 +01:00

111 lines
3.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Support\Ui\EnterpriseDetail\FactPresentation;
it('suppresses duplicate fact values when the badge already says the same thing', function (): void {
expect(FactPresentation::value([
'label' => 'Status',
'value' => 'Completed',
'badge' => [
'label' => 'Completed',
'color' => 'success',
],
]))->toBeNull();
});
it('suppresses boolean fact values when the badge carries the same enabled state', function (): void {
expect(FactPresentation::value([
'label' => 'Security enabled',
'value' => 'Yes',
'badge' => [
'label' => 'Enabled',
'color' => 'success',
],
]))->toBeNull();
expect(FactPresentation::value([
'label' => 'Mail enabled',
'value' => 'No',
'badge' => [
'label' => 'Disabled',
'color' => 'gray',
],
]))->toBeNull();
});
it('keeps the fact value when it adds context beyond the badge label', function (): void {
expect(FactPresentation::value([
'label' => 'Completed',
'value' => 'Completed 2 minutes ago',
'badge' => [
'label' => 'Completed',
'color' => 'success',
],
]))->toBe('Completed 2 minutes ago');
});
it('renders shared header facts without duplicating text already carried by a badge', function (): void {
$html = view('filament.infolists.entries.enterprise-detail.header', [
'header' => [
'title' => 'Backup detail',
'statusBadges' => [],
'primaryActions' => [],
'keyFacts' => [[
'label' => 'Status',
'value' => 'Completed',
'badge' => [
'label' => 'Completed',
'color' => 'success',
],
]],
],
])->render();
expect(substr_count($html, 'Completed'))->toBe(1);
});
it('renders shared section facts without duplicating text already carried by a badge', function (): void {
$html = view('filament.infolists.entries.enterprise-detail.section-items', [
'items' => [[
'label' => 'Status',
'value' => 'Completed',
'badge' => [
'label' => 'Completed',
'color' => 'success',
],
]],
])->render();
expect(substr_count($html, 'Completed'))->toBe(1);
});
it('renders boolean facts without showing both yes-no text and enabled-disabled badges', function (): void {
$html = view('filament.infolists.entries.enterprise-detail.section-items', [
'items' => [
[
'label' => 'Security enabled',
'value' => 'Yes',
'badge' => [
'label' => 'Enabled',
'color' => 'success',
],
],
[
'label' => 'Mail enabled',
'value' => 'No',
'badge' => [
'label' => 'Disabled',
'color' => 'gray',
],
],
],
])->render();
expect($html)->not->toContain('>Yes</span>')
->and($html)->not->toContain('>No</span>')
->and(substr_count($html, 'Enabled'))->toBe(1)
->and(substr_count($html, 'Disabled'))->toBe(1);
});