## Summary Implements feature branch `286-ui-copy-ia-localization-neutralization`. This change set: - aligns chooser, managed-environment landing, dashboard, shell, and workspace context copy to environment-first terminology - neutralizes the bounded policy and baseline helper copy called out by Spec 286 - adds focused feature, guard, and browser coverage plus the complete Spec 286 artifact set - records the discovered `Capture snapshot` modal issue as out-of-scope runtime debt in the Spec 286 close-out notes ## Validation - `export PATH="/bin:/usr/bin:/usr/local/bin:$PATH" && cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Localization/EnvironmentContextTerminologyTest.php tests/Feature/Filament/EnvironmentContextSurfaceCopyTest.php tests/Feature/Filament/Localization/PolicyInventoryLocalizationTest.php tests/Feature/Guards/EnvironmentCopyNeutralizationGuardTest.php` - `export PATH="/bin:/usr/bin:/usr/local/bin:$PATH" && cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Browser/Spec286EnvironmentCopyNeutralizationSmokeTest.php` - `export PATH="/bin:/usr/bin:/usr/local/bin:$PATH" && cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` ## Notes - Target branch: `platform-dev` - Filament remains on v5 with Livewire v4. - Provider registration remains unchanged in `apps/platform/bootstrap/providers.php`. - No new destructive actions, asset strategy changes, or global-search posture changes are introduced in this slice. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #345
462 lines
16 KiB
PHP
462 lines
16 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\BackupScheduleResource\Pages\ListBackupSchedules;
|
|
use App\Filament\Resources\BackupSetResource\Pages\ListBackupSets;
|
|
use App\Filament\Resources\ProviderConnectionResource\Pages\ListProviderConnections;
|
|
use App\Filament\Resources\ReviewPackResource\Pages\ListReviewPacks;
|
|
use App\Filament\Resources\RestoreRunResource\Pages\ListRestoreRuns;
|
|
use App\Filament\Resources\TenantResource\Pages\ListTenants;
|
|
use App\Filament\Resources\Workspaces\Pages\ListWorkspaces;
|
|
use App\Models\BackupSchedule;
|
|
use App\Models\BackupSet;
|
|
use App\Models\ProviderConnection;
|
|
use App\Models\ReviewPack;
|
|
use App\Models\RestoreRun;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Models\WorkspaceMembership;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Actions\Action;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Features\SupportTesting\Testable;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
function getHeaderAction(Testable $component, string $name): ?Action
|
|
{
|
|
$instance = $component->instance();
|
|
$instance->cacheInteractsWithHeaderActions();
|
|
|
|
foreach ($instance->getCachedHeaderActions() as $action) {
|
|
if ($action instanceof Action && $action->getName() === $name) {
|
|
return $action;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function getPlacementEmptyStateAction(Testable $component, string $name): ?Action
|
|
{
|
|
foreach ($component->instance()->getTable()->getEmptyStateActions() as $action) {
|
|
if ($action instanceof Action && $action->getName() === $name) {
|
|
return $action;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
it('shows create only in empty state when workspaces table is empty', function (): void {
|
|
$workspace = Workspace::factory()->create([
|
|
'archived_at' => now(),
|
|
]);
|
|
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
|
|
$user->forceFill([
|
|
'last_workspace_id' => (int) $workspace->getKey(),
|
|
])->save();
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]);
|
|
|
|
$component = Livewire::test(ListWorkspaces::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['create']);
|
|
|
|
expect($component->instance()->getTable()->getEmptyStateActions())->toHaveCount(1);
|
|
|
|
$emptyStateCreate = getPlacementEmptyStateAction($component, 'create');
|
|
expect($emptyStateCreate)->not->toBeNull();
|
|
expect($emptyStateCreate?->getLabel())->toBe('New workspace');
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeFalse();
|
|
});
|
|
|
|
it('shows create only in header when workspaces table is not empty', function (): void {
|
|
$workspace = Workspace::factory()->create([
|
|
'archived_at' => null,
|
|
]);
|
|
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
|
|
$user->forceFill([
|
|
'last_workspace_id' => (int) $workspace->getKey(),
|
|
])->save();
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]);
|
|
|
|
$component = Livewire::test(ListWorkspaces::class)
|
|
->assertCountTableRecords(1);
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeTrue();
|
|
});
|
|
|
|
it('shows create only in empty state when backup schedules table is empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$component = Livewire::test(ListBackupSchedules::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['create']);
|
|
|
|
expect($component->instance()->getTable()->getEmptyStateActions())->toHaveCount(1);
|
|
|
|
$emptyStateCreate = getPlacementEmptyStateAction($component, 'create');
|
|
expect($emptyStateCreate)->not->toBeNull();
|
|
expect($emptyStateCreate?->getLabel())->toBe('New backup schedule');
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeFalse();
|
|
});
|
|
|
|
it('shows create only in header when backup schedules table is not empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
BackupSchedule::query()->create([
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
'name' => 'Daily schedule',
|
|
'is_enabled' => true,
|
|
'timezone' => 'UTC',
|
|
'frequency' => 'daily',
|
|
'time_of_day' => '00:00:00',
|
|
'days_of_week' => null,
|
|
'policy_types' => ['device_config'],
|
|
'include_foundations' => true,
|
|
'retention_keep_last' => 30,
|
|
]);
|
|
|
|
$component = Livewire::test(ListBackupSchedules::class)
|
|
->assertCountTableRecords(1);
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeTrue();
|
|
});
|
|
|
|
it('shows create only in empty state when restore runs table is empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$component = Livewire::test(ListRestoreRuns::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['create']);
|
|
|
|
expect($component->instance()->getTable()->getEmptyStateActions())->toHaveCount(1);
|
|
|
|
$emptyStateCreate = getPlacementEmptyStateAction($component, 'create');
|
|
expect($emptyStateCreate)->not->toBeNull();
|
|
expect($emptyStateCreate?->getLabel())->toBe('New restore run');
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeFalse();
|
|
});
|
|
|
|
it('shows create only in header when restore runs table is not empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
RestoreRun::factory()->create([
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
]);
|
|
|
|
$component = Livewire::test(ListRestoreRuns::class)
|
|
->assertCountTableRecords(1);
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeTrue();
|
|
});
|
|
|
|
it('shows create only in empty state when backup sets table is empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$component = Livewire::test(ListBackupSets::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['create']);
|
|
|
|
expect($component->instance()->getTable()->getEmptyStateActions())->toHaveCount(1);
|
|
|
|
$emptyStateCreate = getPlacementEmptyStateAction($component, 'create');
|
|
expect($emptyStateCreate)->not->toBeNull();
|
|
expect($emptyStateCreate?->getLabel())->toBe('Create backup set');
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeFalse();
|
|
});
|
|
|
|
it('shows create only in header when backup sets table is not empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
BackupSet::factory()->create([
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
]);
|
|
|
|
$component = Livewire::test(ListBackupSets::class)
|
|
->assertCountTableRecords(1);
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeTrue();
|
|
});
|
|
|
|
it('shows generate only in empty state when review packs table is empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$component = Livewire::test(ListReviewPacks::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['generate_first']);
|
|
|
|
$emptyStateGenerate = getPlacementEmptyStateAction($component, 'generate_first');
|
|
expect($emptyStateGenerate)->not->toBeNull();
|
|
expect($emptyStateGenerate?->getLabel())->toBe('Generate first pack');
|
|
|
|
$headerGenerate = getHeaderAction($component, 'generate_pack');
|
|
expect($headerGenerate)->not->toBeNull();
|
|
expect($headerGenerate?->isVisible())->toBeFalse();
|
|
});
|
|
|
|
it('shows generate only in header when review packs table is not empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
ReviewPack::factory()->ready()->create([
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'initiated_by_user_id' => (int) $user->getKey(),
|
|
]);
|
|
|
|
$component = Livewire::test(ListReviewPacks::class)
|
|
->assertCountTableRecords(1);
|
|
|
|
$headerGenerate = getHeaderAction($component, 'generate_pack');
|
|
expect($headerGenerate)->not->toBeNull();
|
|
expect($headerGenerate?->isVisible())->toBeTrue();
|
|
expect($headerGenerate?->getLabel())->toBe('Generate Pack');
|
|
});
|
|
|
|
it('shows create only in empty state when tenants table is empty', function (): void {
|
|
$workspace = Workspace::factory()->create([
|
|
'archived_at' => now(),
|
|
]);
|
|
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
|
|
$user->forceFill([
|
|
'last_workspace_id' => (int) $workspace->getKey(),
|
|
])->save();
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]);
|
|
|
|
$component = Livewire::test(ListTenants::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['add_tenant']);
|
|
|
|
$emptyStateCreate = getPlacementEmptyStateAction($component, 'add_tenant');
|
|
expect($emptyStateCreate)->not->toBeNull();
|
|
expect($emptyStateCreate?->getLabel())->toBe('Add environment');
|
|
|
|
$headerCreate = getHeaderAction($component, 'add_tenant');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeFalse();
|
|
});
|
|
|
|
it('shows create only in header when tenants table is not empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
|
|
$component = Livewire::test(ListTenants::class)
|
|
->assertCountTableRecords(1);
|
|
|
|
$headerCreate = getHeaderAction($component, 'add_tenant');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeTrue();
|
|
expect($headerCreate?->getLabel())->toBe('Add environment');
|
|
});
|
|
|
|
it('labels the empty-state tenant action as resume onboarding when one draft exists', function (): void {
|
|
$workspace = Workspace::factory()->create([
|
|
'archived_at' => now(),
|
|
]);
|
|
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
|
|
createOnboardingDraft([
|
|
'workspace' => $workspace,
|
|
'started_by' => $user,
|
|
'updated_by' => $user,
|
|
'state' => [
|
|
'entra_tenant_id' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
|
'tenant_name' => 'Onboarding ManagedEnvironment',
|
|
],
|
|
]);
|
|
|
|
$user->forceFill([
|
|
'last_workspace_id' => (int) $workspace->getKey(),
|
|
])->save();
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]);
|
|
|
|
$component = Livewire::test(ListTenants::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['add_tenant']);
|
|
|
|
$emptyStateCreate = getPlacementEmptyStateAction($component, 'add_tenant');
|
|
expect($emptyStateCreate)->not->toBeNull();
|
|
expect($emptyStateCreate?->getLabel())->toBe('Resume onboarding');
|
|
});
|
|
|
|
it('labels the tenant header action as resume onboarding when one draft exists', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
createOnboardingDraft([
|
|
'workspace' => $tenant->workspace,
|
|
'started_by' => $user,
|
|
'updated_by' => $user,
|
|
'state' => [
|
|
'entra_tenant_id' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
|
'tenant_name' => 'Resumable Draft',
|
|
],
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
|
|
$component = Livewire::test(ListTenants::class)
|
|
->assertCountTableRecords(1);
|
|
|
|
$headerCreate = getHeaderAction($component, 'add_tenant');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeTrue();
|
|
expect($headerCreate?->getLabel())->toBe('Resume onboarding');
|
|
});
|
|
|
|
it('labels the tenant header action as choose onboarding draft when multiple drafts exist', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
createOnboardingDraft([
|
|
'workspace' => $tenant->workspace,
|
|
'started_by' => $user,
|
|
'updated_by' => $user,
|
|
'state' => [
|
|
'entra_tenant_id' => 'cccccccc-cccc-cccc-cccc-cccccccccccc',
|
|
'tenant_name' => 'Draft One',
|
|
],
|
|
]);
|
|
|
|
createOnboardingDraft([
|
|
'workspace' => $tenant->workspace,
|
|
'started_by' => $user,
|
|
'updated_by' => $user,
|
|
'state' => [
|
|
'entra_tenant_id' => 'dddddddd-dddd-dddd-dddd-dddddddddddd',
|
|
'tenant_name' => 'Draft Two',
|
|
],
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
|
|
$component = Livewire::test(ListTenants::class)
|
|
->assertCountTableRecords(1);
|
|
|
|
$headerCreate = getHeaderAction($component, 'add_tenant');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeTrue();
|
|
expect($headerCreate?->getLabel())->toBe('Choose onboarding draft');
|
|
});
|
|
|
|
it('shows create only in empty state when provider connections table is empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$component = Livewire::test(ListProviderConnections::class)
|
|
->assertCountTableRecords(0)
|
|
->assertTableEmptyStateActionsExistInOrder(['create']);
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeFalse();
|
|
});
|
|
|
|
it('shows create only in header when provider connections table is not empty', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
ProviderConnection::factory()->create([
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
]);
|
|
|
|
$component = Livewire::test(ListProviderConnections::class);
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeTrue();
|
|
});
|