TenantAtlas/tests/Feature/Support/Diff/SharedDiffRowPartialTest.php
2026-03-14 21:08:32 +01:00

140 lines
4.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Support\Diff\DiffRow;
use App\Support\Diff\DiffRowStatus;
it('renders changed rows with shared state labels and from or to values', function (): void {
$this->view('filament.partials.diff.row', [
'row' => new DiffRow(
key: 'description',
label: 'Description',
status: DiffRowStatus::Changed,
oldValue: 'Before',
newValue: 'After',
),
'compact' => false,
'dimUnchanged' => true,
])
->assertSee('Changed')
->assertSee('Description')
->assertSee('Changed value')
->assertSee('From')
->assertSee('Before')
->assertSee('To')
->assertSee('After')
->assertSee('border-warning-200')
->assertSee('bg-warning-50/70');
});
it('renders added removed and unchanged rows through the shared dispatcher', function (): void {
$added = (string) $this->view('filament.partials.diff.row', [
'row' => new DiffRow(
key: 'new_setting',
label: 'New setting',
status: DiffRowStatus::Added,
newValue: 'Enabled',
),
'compact' => false,
'dimUnchanged' => true,
]);
$removed = (string) $this->view('filament.partials.diff.row', [
'row' => new DiffRow(
key: 'retired_setting',
label: 'Retired setting',
status: DiffRowStatus::Removed,
oldValue: 'Legacy',
),
'compact' => false,
'dimUnchanged' => true,
]);
$unchanged = (string) $this->view('filament.partials.diff.row', [
'row' => new DiffRow(
key: 'display_name',
label: 'Display name',
status: DiffRowStatus::Unchanged,
oldValue: 'TenantPilot',
newValue: 'TenantPilot',
),
'compact' => false,
'dimUnchanged' => true,
]);
expect($added)->toContain('Added')
->and($added)->toContain('Enabled')
->and($removed)->toContain('Removed')
->and($removed)->toContain('Legacy')
->and($unchanged)->toContain('Unchanged')
->and($unchanged)->toContain('TenantPilot');
});
it('delegates list-like rows to the inline list partial and dims unchanged content when requested', function (): void {
$listRow = (string) $this->view('filament.partials.diff.row', [
'row' => new DiffRow(
key: 'scope_tags',
label: 'Scope tags',
status: DiffRowStatus::Changed,
oldValue: ['Default', 'Legacy', 'Shared'],
newValue: ['Default', 'Shared', 'Workspace'],
isListLike: true,
addedItems: ['Workspace'],
removedItems: ['Legacy'],
unchangedItems: ['Default', 'Shared'],
),
'compact' => false,
'dimUnchanged' => true,
]);
$unchanged = (string) $this->view('filament.partials.diff.row', [
'row' => new DiffRow(
key: 'display_name',
label: 'Display name',
status: DiffRowStatus::Unchanged,
oldValue: 'TenantPilot',
newValue: 'TenantPilot',
),
'compact' => false,
'dimUnchanged' => true,
]);
expect($listRow)->toContain('Added items')
->and($listRow)->toContain('Removed items')
->and($listRow)->toContain('Unchanged items')
->and($unchanged)->toContain('text-gray-500')
->and($unchanged)->toContain('dark:text-gray-400');
});
it('keeps unchanged rows quieter than changed rows while preserving shared state badges', function (): void {
$changed = (string) $this->view('filament.partials.diff.row', [
'row' => new DiffRow(
key: 'description',
label: 'Description',
status: DiffRowStatus::Changed,
oldValue: 'Before',
newValue: 'After',
),
'compact' => false,
'dimUnchanged' => true,
]);
$unchanged = (string) $this->view('filament.partials.diff.row', [
'row' => new DiffRow(
key: 'display_name',
label: 'Display name',
status: DiffRowStatus::Unchanged,
oldValue: 'TenantPilot',
newValue: 'TenantPilot',
),
'compact' => false,
'dimUnchanged' => true,
]);
expect($changed)->toContain('border-warning-200')
->and($changed)->toContain('Changed value')
->and($unchanged)->toContain('No material change')
->and($unchanged)->toContain('rounded-xl border border-gray-200 bg-white');
});