TenantAtlas/apps/platform/tests/Feature/Workspaces/Spec195ManagedEnvironmentsLandingTest.php
Ahmed Darrazi a6ff903093
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 3m45s
feat: review output resolve actions v1 (spec 351)
Implemented the first version of review output resolve actions. Included a ReviewOutputResolveActionMapper, commands to seed browser fixtures, updated CustomerReviewWorkspace, EnvironmentReviewResource, UI enforcement, and related views. Also added extensive unit, feature, and browser tests, and updated the design coverage matrix.
2026-06-04 02:48:18 +02:00

141 lines
5.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\EnvironmentDashboard;
use App\Filament\Pages\Workspaces\ManagedEnvironmentsLanding;
use App\Filament\Resources\ManagedEnvironmentResource;
use App\Models\ManagedEnvironment;
use App\Models\User;
use App\Models\Workspace;
use App\Models\WorkspaceMembership;
use App\Support\Workspaces\WorkspaceContext;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
it('keeps the spec 195 managed-tenants landing available without an active tenant context', function (): void {
$workspace = Workspace::factory()->create(['slug' => 'spec195-managed-tenants']);
$user = User::factory()->create();
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
$tenant = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Spec195 Landing ManagedEnvironment',
]);
$user->tenants()->syncWithoutDetaching([
$tenant->getKey() => ['role' => 'owner'],
]);
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
->get(route('admin.workspace.managed-environments.index', ['workspace' => $workspace]))
->assertSuccessful()
->assertSee('Spec195 Landing ManagedEnvironment')
->assertSee(__('localization.shell.managed_environments_title'))
->assertDontSee(__('localization.shell.no_environment_selected'));
});
it('routes the managed-tenants landing card into the open-environment flow', function (): void {
$workspace = Workspace::factory()->create(['slug' => 'spec195-managed-routing']);
$user = User::factory()->create();
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
$tenant = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Spec195 Routed ManagedEnvironment',
]);
$user->tenants()->syncWithoutDetaching([
$tenant->getKey() => ['role' => 'owner'],
]);
$this->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]);
session([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]);
$component = Livewire::actingAs($user)
->test(ManagedEnvironmentsLanding::class, ['workspace' => $workspace]);
$component
->call('openTenant', $tenant->getKey())
->assertRedirect(EnvironmentDashboard::getUrl(tenant: $tenant));
});
it('keeps the managed-environments landing readable for long identities and larger portfolios', function (): void {
$workspace = Workspace::factory()->create([
'name' => 'Spec195 Enterprise Workspace With A Long Portfolio Name',
'slug' => 'spec195-enterprise-portfolio',
]);
$user = User::factory()->create();
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
$longName = 'Spec195 Enterprise North America Production Environment With A Very Long Legal Business Unit Name';
$longExternalId = 'spec195-enterprise-north-america-production-environment-01-7e76a2da-7a86-4a16-9e36-4069b7d3de10';
$environmentIds = [];
for ($index = 1; $index <= 10; $index++) {
$environment = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => $index === 1 ? $longName : "Spec195 Portfolio Environment {$index}",
'slug' => $index === 1 ? $longExternalId : "spec195-portfolio-environment-{$index}",
]);
$environmentIds[$environment->getKey()] = ['role' => 'owner'];
}
$user->tenants()->syncWithoutDetaching($environmentIds);
$this->actingAs($user)
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
->get(route('admin.workspace.managed-environments.index', ['workspace' => $workspace]))
->assertSuccessful()
->assertSee($longName)
->assertSee($longExternalId)
->assertSee('grid grid-cols-1 gap-3 xl:grid-cols-2', false)
->assertSee('[overflow-wrap:anywhere]', false)
->assertSee('break-all', false)
->assertSee('role="list"', false)
->assertSee('Open environment '.$longName, false);
});
it('allows workspace-scoped access to open an environment from the landing without explicit membership', function (): void {
$workspace = Workspace::factory()->create(['slug' => 'spec195-managed-guard']);
$user = User::factory()->create();
WorkspaceMembership::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'user_id' => (int) $user->getKey(),
'role' => 'owner',
]);
$tenant = ManagedEnvironment::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Spec195 Guarded ManagedEnvironment',
]);
$this->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]);
session([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]);
Livewire::actingAs($user)
->test(ManagedEnvironmentsLanding::class, ['workspace' => $workspace])
->call('openTenant', $tenant->getKey())
->assertRedirect(EnvironmentDashboard::getUrl(tenant: $tenant));
});