TenantAtlas/apps/platform/tests/Browser/Spec286EnvironmentCopyNeutralizationSmokeTest.php
ahmido e0c2cdb1f4 feat: enforce workspace and environment scope contract (Spec 338) (#409)
## Summary
- enforce the canonical workspace/environment scope contract for workspace hubs and environment-owned surfaces
- replace first-party Operations deep links that leaked Filament `tableFilters[...]` internals with stable product-level query behavior
- add the sidebar scope indicator and split environment-page navigation into explicit `Workspace-wide` and `Workspace admin` groups
- remove redundant tenantless `All environments` scope badges from workspace-wide pages while preserving explicit environment filter affordances
- include the Spec 338 artifacts, guard tests, and browser smoke coverage for the new contract

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Navigation/Spec338EnvironmentSidebarSeparationTest.php tests/Feature/Navigation/Spec338OperationRunLinksQueryContractTest.php tests/Feature/Navigation/Spec338SidebarScopeIndicatorTest.php tests/Feature/Filament/PanelNavigationSegregationTest.php`
- `cd apps/platform && ./vendor/bin/sail php vendor/bin/pest tests/Browser/Spec338ScopeContractSmokeTest.php --compact`

## Notes
- Livewire v4 compliance unchanged
- Filament provider registration remains in `bootstrap/providers.php`
- no destructive action behavior changed
- no migrations, env var changes, or new Filament asset registration

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #409
2026-05-31 01:36:08 +00:00

96 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Resources\PolicyResource;
use App\Models\ManagedEnvironment;
use App\Models\Policy;
use App\Models\PolicyVersion;
use App\Models\ProviderConnection;
use App\Models\User;
use App\Models\Workspace;
use App\Models\WorkspaceMembership;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
pest()->browser()->timeout(20_000);
it('smokes environment-first chooser and policy helper copy', function (): void {
$workspace = Workspace::factory()->create([
'name' => 'Spec 286 Workspace',
]);
$environment = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Spec 286 Production',
'slug' => 'spec-286-production',
]);
$secondaryEnvironment = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Spec 286 Secondary',
'slug' => 'spec-286-secondary',
]);
$user = User::factory()->create();
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
foreach ([$environment, $secondaryEnvironment] as $memberEnvironment) {
$user->tenants()->syncWithoutDetaching([
(int) $memberEnvironment->getKey() => ['role' => 'owner'],
]);
}
ProviderConnection::factory()->platform()->consentGranted()->create([
'managed_environment_id' => (int) $environment->getKey(),
'workspace_id' => (int) $workspace->getKey(),
'is_default' => true,
]);
$policy = Policy::factory()->create([
'managed_environment_id' => (int) $environment->getKey(),
'display_name' => 'Spec 286 Policy',
]);
PolicyVersion::factory()->create([
'managed_environment_id' => (int) $environment->getKey(),
'policy_id' => (int) $policy->getKey(),
'metadata' => [],
]);
$this->actingAs($user);
$landing = visit(route('admin.workspace.managed-environments.index', ['workspace' => $workspace]))
->waitForText('Managed environments')
->assertDontSee('Choose environment')
->assertSee('Spec 286 Production')
->assertSee('Spec 286 Secondary')
->assertDontSee('Managed tenants')
->assertNoJavaScriptErrors()
->assertNoConsoleLogs();
$landing
->click('[wire\:key="tenant-'.$environment->getKey().'"]')
->waitForText('Spec 286 Production')
->waitForText('Environment governance overview')
->assertNoJavaScriptErrors()
->assertNoConsoleLogs();
visit(PolicyResource::getUrl('view', ['record' => $policy], tenant: $environment))
->waitForText('Capture snapshot')
->assertSee('Restore to environment')
->assertDontSee('Restore to Microsoft Intune')
->click('Capture snapshot')
->waitForText('Capture snapshot now')
->assertSee('current environment')
->assertSee('Source: Microsoft Intune')
->assertNoJavaScriptErrors()
->assertNoConsoleLogs();
});