TenantAtlas/apps/platform/tests/Feature/Filament/PolicyListingTest.php
ahmido ce0615a9c1 Spec 182: relocate Laravel platform to apps/platform (#213)
## Summary
- move the Laravel application into `apps/platform` and keep the repository root for orchestration, docs, and tooling
- update the local command model, Sail/Docker wiring, runtime paths, and ignore rules around the new platform location
- add relocation quickstart/contracts plus focused smoke coverage for bootstrap, command model, routes, and runtime behavior

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/PlatformRelocation`
- integrated browser smoke validated `/up`, `/`, `/admin`, `/admin/choose-workspace`, and tenant route semantics for `200`, `403`, and `404`

## Remaining Rollout Checks
- validate Dokploy build context and working-directory assumptions against the new `apps/platform` layout
- confirm web, queue, and scheduler processes all start from the expected working directory in staging/production
- verify no legacy volume mounts or asset-publish paths still point at the old root-level `public/` or `storage/` locations

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #213
2026-04-08 08:40:47 +00:00

79 lines
2.8 KiB
PHP

<?php
use App\Filament\Resources\PolicyResource\Pages\ListPolicies;
use App\Models\Policy;
use App\Models\Tenant;
use App\Models\User;
use Filament\Facades\Filament;
use Livewire\Livewire;
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
test('policies are listed for the active tenant', function () {
$tenant = Tenant::factory()->create();
Policy::create([
'tenant_id' => $tenant->id,
'external_id' => 'policy-1',
'policy_type' => 'deviceConfiguration',
'display_name' => 'Policy A',
'platform' => 'windows',
'last_synced_at' => now(),
]);
$otherTenant = Tenant::factory()->create();
Policy::create([
'tenant_id' => $otherTenant->id,
'external_id' => 'policy-2',
'policy_type' => 'deviceConfiguration',
'display_name' => 'Policy B',
'platform' => 'windows',
'last_synced_at' => now(),
]);
$user = User::factory()->create();
[$user, $tenant] = createUserWithTenant(tenant: $tenant, user: $user, role: 'owner');
$user->tenants()->syncWithoutDetaching([
$otherTenant->getKey() => ['role' => 'owner'],
]);
$this->actingAs($user)
->get(route('filament.tenant.resources.policies.index', filamentTenantRouteParams($tenant)))
->assertOk()
->assertSee('Policy A')
->assertDontSee('Policy B');
});
test('policy list keeps the standard table defaults and persists state in-session', function () {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$this->actingAs($user);
$tenant->makeCurrent();
Filament::setTenant($tenant, true);
$component = Livewire::actingAs($user)
->test(ListPolicies::class)
->assertTableEmptyStateActionsExistInOrder(['sync'])
->searchTable('Policy')
->call('sortTable', 'display_name', 'desc')
->set('tableFilters.visibility.value', 'active');
$table = $component->instance()->getTable();
expect($table->getPaginationPageOptions())->toBe(\App\Support\Filament\TablePaginationProfiles::resource());
expect($table->getEmptyStateHeading())->toBe('No policies synced yet');
expect($table->getColumn('display_name')?->isSearchable())->toBeTrue();
expect($table->getColumn('display_name')?->isSortable())->toBeTrue();
expect($table->getColumn('external_id')?->isToggledHiddenByDefault())->toBeTrue();
expect(count($table->getVisibleColumns()))->toBeLessThanOrEqual(7);
expect(session()->get($component->instance()->getTableSearchSessionKey()))->toBe('Policy');
expect(session()->get($component->instance()->getTableSortSessionKey()))->toBe('display_name:desc');
Livewire::actingAs($user)
->test(ListPolicies::class)
->assertSet('tableSearch', 'Policy')
->assertSet('tableSort', 'display_name:desc')
->assertSet('tableFilters.visibility.value', 'active');
});