TenantAtlas/apps/platform/tests/Feature/System/Spec114/ControlTowerDashboardTest.php
ahmido 86505483bf
Some checks failed
Main Confidence / confidence (push) Failing after 52s
feat(customer-health): add decision card to tenant/workspace detail (spec 245) (#283)
Add Customer Health decision card to tenant & workspace detail pages (spec 245).

What I changed:
- Render a decision-first Customer Health card on tenant and workspace detail pages.
- Reuse `WorkspaceHealthSummaryQuery` and preserve `window` query param.
- Update attention widget link text to "Review health details" and include `?window=`.
- Add/adjust tests to cover new behavior and explainability.
- Run Pint formatting.

Compare URL: https://git.cloudarix.de/ahmido/TenantAtlas/compare/dev...245-customer-health-score

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #283
2026-04-27 08:30:01 +00:00

97 lines
3.9 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\System\Pages\Dashboard;
use App\Filament\System\Widgets\ControlTowerKpis;
use App\Filament\System\Widgets\ControlTowerRecentFailures;
use App\Filament\System\Widgets\ControlTowerTopOffenders;
use App\Filament\System\Widgets\CustomerHealthKpis;
use App\Filament\System\Widgets\CustomerHealthTopWorkspaces;
use App\Filament\System\Widgets\ProductTelemetryKpis;
use App\Models\PlatformUser;
use App\Support\Auth\PlatformCapabilities;
use App\Support\SystemConsole\SystemConsoleWindow;
use Filament\Widgets\WidgetConfiguration;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
Filament::setCurrentPanel('system');
Filament::bootCurrentPanel();
});
it('forbids system dashboard when platform.console.view is missing', function () {
$platformUser = PlatformUser::factory()->create([
'capabilities' => [
PlatformCapabilities::ACCESS_SYSTEM_PANEL,
],
'is_active' => true,
]);
$this->actingAs($platformUser, 'platform')
->get('/system')
->assertForbidden();
});
it('defaults dashboard to the 24h window and allows switching window', function () {
$platformUser = PlatformUser::factory()->create([
'capabilities' => [
PlatformCapabilities::ACCESS_SYSTEM_PANEL,
PlatformCapabilities::CONSOLE_VIEW,
],
'is_active' => true,
]);
$this->actingAs($platformUser, 'platform')
->get('/system')
->assertSuccessful();
Livewire::test(Dashboard::class)
->assertSet('window', SystemConsoleWindow::LastDay)
->callAction('set_window', data: [
'window' => SystemConsoleWindow::LastWeek,
])
->assertSet('window', SystemConsoleWindow::LastWeek);
});
it('passes the selected window into all window-aware dashboard widgets', function () {
$platformUser = PlatformUser::factory()->create([
'capabilities' => [
PlatformCapabilities::ACCESS_SYSTEM_PANEL,
PlatformCapabilities::CONSOLE_VIEW,
],
'is_active' => true,
]);
$component = Livewire::actingAs($platformUser, 'platform')
->withQueryParams(['window' => SystemConsoleWindow::LastWeek])
->test(Dashboard::class)
->assertSet('window', SystemConsoleWindow::LastWeek);
$widgets = $component->instance()->getWidgets();
expect($widgets)->toHaveCount(7)
->and($widgets[1])->toBeInstanceOf(WidgetConfiguration::class)
->and($widgets[2])->toBeInstanceOf(WidgetConfiguration::class)
->and($widgets[3])->toBeInstanceOf(WidgetConfiguration::class)
->and($widgets[4])->toBeInstanceOf(WidgetConfiguration::class)
->and($widgets[5])->toBeInstanceOf(WidgetConfiguration::class)
->and($widgets[6])->toBeInstanceOf(WidgetConfiguration::class)
->and($widgets[1]->widget)->toBe(CustomerHealthKpis::class)
->and($widgets[2]->widget)->toBe(CustomerHealthTopWorkspaces::class)
->and($widgets[3]->widget)->toBe(ControlTowerKpis::class)
->and($widgets[4]->widget)->toBe(ProductTelemetryKpis::class)
->and($widgets[5]->widget)->toBe(ControlTowerTopOffenders::class)
->and($widgets[6]->widget)->toBe(ControlTowerRecentFailures::class)
->and($widgets[1]->getProperties())->toBe(['window' => SystemConsoleWindow::LastWeek])
->and($widgets[2]->getProperties())->toBe(['window' => SystemConsoleWindow::LastWeek])
->and($widgets[3]->getProperties())->toBe(['window' => SystemConsoleWindow::LastWeek])
->and($widgets[4]->getProperties())->toBe(['window' => SystemConsoleWindow::LastWeek])
->and($widgets[5]->getProperties())->toBe(['window' => SystemConsoleWindow::LastWeek])
->and($widgets[6]->getProperties())->toBe(['window' => SystemConsoleWindow::LastWeek]);
});