## Summary - replace the legacy Tenant and TenantMembership core models with ManagedEnvironment and ManagedEnvironmentMembership - propagate the managed environment naming and key changes across Filament resources, pages, controllers, jobs, models, and supporting runtime paths - add feature 279 spec artifacts and focused managed-environment test coverage for model behavior, route binding, panel context, authorization, and legacy guardrails ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ManagedEnvironment/LegacyTenantCoreGuardTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentAuthorizationTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentPanelContextTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentRouteBindingTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentContextResolverTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentModelTest.php` - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` ## Notes - branch pushed from commit `1123b122` - browser smoke test file was added but not run in this pass Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #335
89 lines
3.2 KiB
PHP
89 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\TenantResource\Pages\EditTenant;
|
|
use App\Models\ManagedEnvironment;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\ActionGroup;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Features\SupportTesting\Testable;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
function editTenantHeaderActions(Testable $component): array
|
|
{
|
|
$instance = $component->instance();
|
|
|
|
if ($instance->getCachedHeaderActions() === []) {
|
|
$instance->cacheInteractsWithHeaderActions();
|
|
}
|
|
|
|
return $instance->getCachedHeaderActions();
|
|
}
|
|
|
|
function editTenantHeaderGroupLabels(Testable $component): array
|
|
{
|
|
return collect(editTenantHeaderActions($component))
|
|
->filter(static fn ($action): bool => $action instanceof ActionGroup && $action->isVisible())
|
|
->map(static fn (ActionGroup $action): string => (string) $action->getLabel())
|
|
->values()
|
|
->all();
|
|
}
|
|
|
|
function editTenantHeaderPrimaryNames(Testable $component): array
|
|
{
|
|
return collect(editTenantHeaderActions($component))
|
|
->reject(static fn ($action): bool => $action instanceof ActionGroup)
|
|
->filter(static fn ($action): bool => ! method_exists($action, 'isVisible') || $action->isVisible())
|
|
->map(static fn ($action): ?string => $action instanceof Action ? $action->getName() : null)
|
|
->filter()
|
|
->values()
|
|
->all();
|
|
}
|
|
|
|
it('keeps related links in contextual placement and reserves the header for lifecycle actions', function (): void {
|
|
$tenant = ManagedEnvironment::factory()->onboarding()->create();
|
|
[$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->managed_environment_id,
|
|
'tenant_name' => (string) $tenant->name,
|
|
],
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$component = Livewire::test(EditTenant::class, ['record' => $tenant->getRouteKey()])
|
|
->assertSee('Related context')
|
|
->assertSee('Open tenant detail')
|
|
->assertSee('Resume onboarding');
|
|
|
|
expect(editTenantHeaderPrimaryNames($component))->toBe([])
|
|
->and(editTenantHeaderGroupLabels($component))->toBe([]);
|
|
});
|
|
|
|
it('keeps tenant lifecycle mutations available under the lifecycle header group with confirmation intact', function (): void {
|
|
$tenant = ManagedEnvironment::factory()->active()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$component = Livewire::test(EditTenant::class, ['record' => $tenant->getRouteKey()])
|
|
->assertActionVisible('archive')
|
|
->assertActionEnabled('archive')
|
|
->assertActionExists('archive', fn (Action $action): bool => $action->isConfirmationRequired());
|
|
|
|
expect(editTenantHeaderPrimaryNames($component))->toBe([])
|
|
->and(editTenantHeaderGroupLabels($component))->toBe(['Lifecycle']);
|
|
});
|