TenantAtlas/tests/Feature/Support/Diff/SharedDiffRowPartialTest.php
ahmido 0b5cadc234 feat: add shared diff presentation foundation (#170)
## Summary
- add a shared diff presentation layer under `app/Support/Diff` with deterministic row classification, summary derivation, and value stringification
- centralize diff-state badge semantics through `BadgeCatalog` with a dedicated `DiffRowStatusBadge`
- add reusable Filament diff partials, focused Pest coverage, and the full SpecKit artifact set for spec 141

## Testing
- `vendor/bin/sail artisan test --compact tests/Unit/Support/Diff/DiffRowStatusTest.php tests/Unit/Support/Diff/DiffRowTest.php tests/Unit/Support/Diff/DiffPresenterTest.php tests/Unit/Support/Diff/ValueStringifierTest.php tests/Unit/Badges/DiffRowStatusBadgeTest.php tests/Feature/Support/Diff/SharedDiffSummaryPartialTest.php tests/Feature/Support/Diff/SharedDiffRowPartialTest.php tests/Feature/Support/Diff/SharedInlineListDiffPartialTest.php`
- `vendor/bin/sail bin pint --dirty --format agent`

## Filament / Livewire Contract
- Livewire v4.0+ compliance: unchanged and respected; this feature adds presentation support only within the existing Filament v5 / Livewire v4 stack
- Provider registration: unchanged; no panel/provider changes were required, so `bootstrap/providers.php` remains the correct registration location
- Global search: unchanged; no Resource or global-search behavior was added or modified
- Destructive actions: none introduced in this feature
- Asset strategy: no new registered Filament assets; shared Blade partials rely on the existing asset pipeline and standard deploy step for `php artisan filament:assets` when assets change generally
- Testing coverage: presenter, DTOs, stringifier, badge semantics, summary partial, row partial, and inline-list partial are covered by focused Pest unit and feature tests

## Notes
- Spec checklist status is complete for `specs/141-shared-diff-presentation-foundation/checklists/requirements.md`
- This PR preserves specialized diff renderers and documents incremental adoption rather than forcing migration in the same change

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #170
2026-03-14 12:32:08 +00:00

106 lines
3.3 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('From')
->assertSee('Before')
->assertSee('To')
->assertSee('After');
});
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');
});