Implements Spec 110 Ops‑UX Enforcement and applies the repo‑wide “enterprise” standard for operation start + dedup surfaces. Key points - Start surfaces: only ephemeral queued toast (no DB notifications for started/queued/running). - Dedup paths: canonical “already queued” toast. - Progress refresh: dispatch run-enqueued browser event so the global widget updates immediately. - Completion: exactly-once terminal DB notification on completion (per Ops‑UX contract). Tests & formatting - Full suite: 1738 passed, 8 skipped (8477 assertions). - Pint: `vendor/bin/sail bin pint --dirty --format agent` (pass). Notable change - Removed legacy `RunStatusChangedNotification` (replaced by the terminal-only completion notification policy). Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #134
279 lines
9.0 KiB
PHP
279 lines
9.0 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\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\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;
|
|
}
|
|
|
|
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']);
|
|
|
|
$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);
|
|
|
|
$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']);
|
|
|
|
$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([
|
|
'tenant_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);
|
|
|
|
$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']);
|
|
|
|
$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([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
]);
|
|
|
|
$component = Livewire::test(ListRestoreRuns::class);
|
|
|
|
$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']);
|
|
|
|
$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([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
]);
|
|
|
|
$component = Livewire::test(ListBackupSets::class);
|
|
|
|
$headerCreate = getHeaderAction($component, 'create');
|
|
expect($headerCreate)->not->toBeNull();
|
|
expect($headerCreate?->isVisible())->toBeTrue();
|
|
});
|
|
|
|
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']);
|
|
|
|
$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();
|
|
});
|
|
|
|
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([
|
|
'tenant_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();
|
|
});
|