## Summary - add conditional polling support for the tenantless operation run viewer and tenant review pack card - add focused Pest coverage for active vs terminal polling behavior and related review pack access regressions - add the full Spec Kit artifacts for Spec 123, including spec, plan, research, data model, contracts, quickstart, tasks, and checklist ## Testing - `vendor/bin/sail artisan test --compact tests/Feature/OpsUx/RunDetailPollingStopsOnTerminalTest.php tests/Feature/Operations/TenantlessOperationRunViewerTest.php tests/Feature/ReviewPack/ReviewPackWidgetTest.php tests/Feature/ReviewPack/ReviewPackGenerationTest.php tests/Feature/ReviewPack/ReviewPackRbacTest.php` - `vendor/bin/sail bin pint --dirty --format agent` ## Notes - Manual QA task `T014` in the Spec Kit checklist remains to be completed outside this automated flow. - Livewire v4.0+ compliance is unchanged. - No panel provider changes were made; provider registration remains in `bootstrap/providers.php`. - No global-search behavior was changed. - No destructive actions were added or modified. - No new Filament assets were introduced; existing deployment expectations for `php artisan filament:assets` remain unchanged. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #149
162 lines
5.9 KiB
PHP
162 lines
5.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Widgets\Tenant\TenantReviewPackCard;
|
|
use App\Models\ReviewPack;
|
|
use App\Models\Tenant;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
Storage::fake('exports');
|
|
});
|
|
|
|
// ─── No Pack State ───────────────────────────────────────────
|
|
|
|
it('shows the generate CTA when no pack exists', function (): void {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(TenantReviewPackCard::class, ['record' => $tenant])
|
|
->assertSee('No review pack generated yet')
|
|
->assertSee('Generate')
|
|
->assertDontSee('wire:poll.10s', escape: false);
|
|
});
|
|
|
|
// ─── Ready State ─────────────────────────────────────────────
|
|
|
|
it('shows download and generate buttons when a ready pack exists', function (): void {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
|
|
$filePath = 'review-packs/widget-test.zip';
|
|
Storage::disk('exports')->put($filePath, 'PK-test');
|
|
|
|
ReviewPack::factory()->ready()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'initiated_by_user_id' => (int) $user->getKey(),
|
|
'file_path' => $filePath,
|
|
'file_disk' => 'exports',
|
|
]);
|
|
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(TenantReviewPackCard::class, ['record' => $tenant])
|
|
->assertSee('Download')
|
|
->assertSee('Generate new')
|
|
->assertDontSee('wire:poll.10s', escape: false);
|
|
});
|
|
|
|
// ─── Generating State ────────────────────────────────────────
|
|
|
|
it('shows in-progress message for a generating pack', function (): void {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
|
|
ReviewPack::factory()->generating()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'initiated_by_user_id' => (int) $user->getKey(),
|
|
]);
|
|
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(TenantReviewPackCard::class, ['record' => $tenant])
|
|
->assertSee('Generation in progress')
|
|
->assertSee('wire:poll.10s', escape: false);
|
|
});
|
|
|
|
// ─── Queued State ────────────────────────────────────────────
|
|
|
|
it('shows in-progress message for a queued pack', function (): void {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
|
|
ReviewPack::factory()->queued()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'initiated_by_user_id' => (int) $user->getKey(),
|
|
]);
|
|
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(TenantReviewPackCard::class, ['record' => $tenant])
|
|
->assertSee('Generation in progress')
|
|
->assertSee('wire:poll.10s', escape: false);
|
|
});
|
|
|
|
// ─── Failed State ────────────────────────────────────────────
|
|
|
|
it('shows retry button for a failed pack', function (): void {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
|
|
ReviewPack::factory()->failed()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'initiated_by_user_id' => (int) $user->getKey(),
|
|
]);
|
|
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(TenantReviewPackCard::class, ['record' => $tenant])
|
|
->assertSee('Retry')
|
|
->assertDontSee('wire:poll.10s', escape: false);
|
|
});
|
|
|
|
// ─── Expired State ───────────────────────────────────────────
|
|
|
|
it('shows generate action for an expired pack', function (): void {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
|
|
ReviewPack::factory()->expired()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'initiated_by_user_id' => (int) $user->getKey(),
|
|
]);
|
|
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(TenantReviewPackCard::class, ['record' => $tenant])
|
|
->assertSee('Generate new')
|
|
->assertDontSee('wire:poll.10s', escape: false);
|
|
});
|
|
|
|
// ─── Generate Pack Livewire Action ──────────────────────────
|
|
|
|
it('can trigger generatePack Livewire action', function (): void {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(TenantReviewPackCard::class, ['record' => $tenant])
|
|
->call('generatePack', true, true)
|
|
->assertHasNoErrors();
|
|
|
|
expect(ReviewPack::query()->where('tenant_id', (int) $tenant->getKey())->count())->toBe(1);
|
|
});
|