## Summary - amend the operator UI constitution and related SpecKit templates for the new UI/UX governance rules - add Spec 168 artifacts plus the tenant governance aggregate implementation used by the tenant dashboard, banner, and baseline compare landing surfaces - normalize Filament action surfaces around clickable-row inspection, grouped secondary actions, and explicit action-surface declarations across enrolled resources and pages - fix post-suite regressions in membership cache priming, finding workflow state refresh, tenant review derived-state invalidation, and tenant-bound backup-set related navigation ## Commit Series - `docs: amend operator UI constitution` - `spec: add tenant governance aggregate contract` - `feat: add tenant governance aggregate contract` - `refactor: normalize filament action surfaces` - `fix: resolve post-suite state regressions` ## Testing - `vendor/bin/sail artisan test --compact` - Result: `3176 passed, 8 skipped (17384 assertions)` ## Notes - Livewire v4 / Filament v5 stack remains unchanged - no provider registration changes; `bootstrap/providers.php` remains the relevant location - no new global-search resources or asset-registration changes in this branch Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #199
177 lines
6.8 KiB
PHP
177 lines
6.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\TenantResource;
|
|
use App\Models\Tenant;
|
|
use App\Services\Tenants\TenantActionPolicySurface;
|
|
use App\Support\Tenants\TenantActionSurface;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('does not expose archive as a lifecycle action for draft and onboarding tenants', function (\Closure $tenantFactory): void {
|
|
$tenant = $tenantFactory();
|
|
|
|
expect(app(TenantActionPolicySurface::class)->lifecycleActionForTenant($tenant))
|
|
->toBeNull();
|
|
})->with([
|
|
'draft' => [fn (): Tenant => Tenant::factory()->draft()->create()],
|
|
'onboarding' => [fn (): Tenant => Tenant::factory()->onboarding()->create()],
|
|
]);
|
|
|
|
it('returns archive only for active tenants and restore only for archived tenants', function (
|
|
\Closure $tenantFactory,
|
|
string $expectedKey,
|
|
string $expectedLabel,
|
|
): void {
|
|
$tenant = $tenantFactory();
|
|
$descriptor = app(TenantActionPolicySurface::class)->lifecycleActionForTenant($tenant);
|
|
|
|
expect($descriptor)
|
|
->not->toBeNull()
|
|
->and($descriptor?->key)->toBe($expectedKey)
|
|
->and($descriptor?->label)->toBe($expectedLabel)
|
|
->and($descriptor?->requiresConfirmation)->toBeTrue();
|
|
})->with([
|
|
'active' => [fn (): Tenant => Tenant::factory()->active()->create(), 'archive', 'Archive'],
|
|
'archived' => [fn (): Tenant => Tenant::factory()->archived()->create(), 'restore', 'Restore'],
|
|
]);
|
|
|
|
it('returns resume onboarding as the primary action for draft and onboarding tenants with resumable drafts', function (\Closure $tenantFactory): void {
|
|
$tenant = $tenantFactory();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
|
|
|
|
createOnboardingDraft([
|
|
'workspace' => $tenant->workspace,
|
|
'tenant' => $tenant,
|
|
'started_by' => $user,
|
|
'updated_by' => $user,
|
|
'state' => [
|
|
'entra_tenant_id' => (string) $tenant->tenant_id,
|
|
'tenant_name' => (string) $tenant->name,
|
|
],
|
|
]);
|
|
|
|
$catalog = tenantActionCatalog($tenant, TenantActionSurface::TenantIndexRow, $user);
|
|
|
|
expect(tenantActionKeys($catalog))
|
|
->toBe(['view', 'related_onboarding'])
|
|
->and($catalog[1]->label)->toBe('Resume onboarding');
|
|
})->with([
|
|
'draft' => [fn (): Tenant => Tenant::factory()->draft()->create()],
|
|
'onboarding' => [fn (): Tenant => Tenant::factory()->onboarding()->create()],
|
|
]);
|
|
|
|
it('keeps completed onboarding as a view-only overflow action for active tenants', function (): void {
|
|
$tenant = Tenant::factory()->active()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
|
|
|
|
createOnboardingDraft([
|
|
'workspace' => $tenant->workspace,
|
|
'tenant' => $tenant,
|
|
'started_by' => $user,
|
|
'updated_by' => $user,
|
|
'status' => 'completed',
|
|
'state' => [
|
|
'entra_tenant_id' => (string) $tenant->tenant_id,
|
|
'tenant_name' => (string) $tenant->name,
|
|
],
|
|
]);
|
|
|
|
$catalog = tenantActionCatalog($tenant, TenantActionSurface::TenantIndexRow, $user);
|
|
|
|
expect(tenantActionKeys($catalog))
|
|
->toBe(['view', 'archive', 'related_onboarding'])
|
|
->and($catalog[2]->label)->toBe('View completed onboarding');
|
|
});
|
|
|
|
it('keeps tenant index catalogs within the clickable-row overflow contract', function (): void {
|
|
$tenant = Tenant::factory()->active()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
|
|
|
|
createOnboardingDraft([
|
|
'workspace' => $tenant->workspace,
|
|
'tenant' => $tenant,
|
|
'started_by' => $user,
|
|
'updated_by' => $user,
|
|
'status' => 'completed',
|
|
'state' => [
|
|
'entra_tenant_id' => (string) $tenant->tenant_id,
|
|
'tenant_name' => (string) $tenant->name,
|
|
],
|
|
]);
|
|
|
|
$catalog = tenantActionCatalog($tenant, TenantActionSurface::TenantIndexRow, $user);
|
|
|
|
$primaryKeys = collect($catalog)
|
|
->filter(static fn ($action): bool => $action->group === 'primary')
|
|
->map(static fn ($action): string => $action->key)
|
|
->values()
|
|
->all();
|
|
|
|
$inspectKeys = collect($catalog)
|
|
->filter(static fn ($action): bool => $action->group === 'inspect')
|
|
->map(static fn ($action): string => $action->key)
|
|
->values()
|
|
->all();
|
|
|
|
$overflowKeys = collect($catalog)
|
|
->filter(static fn ($action): bool => $action->group === 'overflow')
|
|
->map(static fn ($action): string => $action->key)
|
|
->values()
|
|
->all();
|
|
|
|
expect($inspectKeys)->toBe(['view'])
|
|
->and($primaryKeys)->toBe(['archive'])
|
|
->and($overflowKeys)->toBe(['related_onboarding'])
|
|
->and(TenantResource::actionSurfaceDeclaration()->listRowPrimaryActionLimit())->toBe(1);
|
|
});
|
|
|
|
it('invalidates cached tenant index catalogs when the related onboarding draft lifecycle changes', function (): void {
|
|
$tenant = Tenant::factory()->active()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
|
|
|
|
$draft = createOnboardingDraft([
|
|
'workspace' => $tenant->workspace,
|
|
'tenant' => $tenant,
|
|
'started_by' => $user,
|
|
'updated_by' => $user,
|
|
'status' => 'in_progress',
|
|
'state' => [
|
|
'entra_tenant_id' => (string) $tenant->tenant_id,
|
|
'tenant_name' => (string) $tenant->name,
|
|
],
|
|
]);
|
|
|
|
$initialCatalog = tenantActionCatalog($tenant, TenantActionSurface::TenantIndexRow, $user);
|
|
|
|
expect(tenantActionKeys($initialCatalog))->toBe(['view', 'archive', 'related_onboarding'])
|
|
->and($initialCatalog[2]->group)->toBe('overflow')
|
|
->and($initialCatalog[2]->label)->toBe('View related onboarding');
|
|
|
|
$draft->forceFill([
|
|
'completed_at' => now()->addSecond(),
|
|
'lifecycle_state' => 'completed',
|
|
'updated_at' => now()->addSecond(),
|
|
])->save();
|
|
|
|
$tenant->refresh();
|
|
|
|
$updatedCatalog = tenantActionCatalog($tenant, TenantActionSurface::TenantIndexRow, $user);
|
|
|
|
expect(tenantActionKeys($updatedCatalog))->toBe(['view', 'archive', 'related_onboarding'])
|
|
->and($updatedCatalog[2]->group)->toBe('overflow')
|
|
->and($updatedCatalog[2]->label)->toBe('View completed onboarding');
|
|
});
|
|
|
|
it('uses workflow-accurate onboarding entry labels', function (int $draftCount, string $expectedLabel): void {
|
|
$descriptor = app(TenantActionPolicySurface::class)->onboardingEntryDescriptor($draftCount);
|
|
|
|
expect($descriptor->label)->toBe($expectedLabel);
|
|
})->with([
|
|
'no drafts' => [0, 'Add tenant'],
|
|
'one draft' => [1, 'Resume onboarding'],
|
|
'multiple drafts' => [2, 'Choose onboarding draft'],
|
|
]);
|