Update dashboard widgets

This commit is contained in:
DariusIII
2026-07-20 13:07:56 +02:00
parent c2789fb333
commit 7906148f7f
16 changed files with 375 additions and 185 deletions
@@ -16,14 +16,14 @@ class AdminDashboardAutoRefreshTest extends TestCase
$this->assertStringContainsString('x-data="adminDashboard"', $content);
$this->assertStringContainsString('data-data-url="{{ route(\'admin.api.dashboard-data\') }}"', $content);
$this->assertStringContainsString('data-refresh-interval="{{ 15 * 60 * 1000 }}"', $content);
$this->assertStringContainsString('data-refresh-interval="{{ 60 * 1000 }}"', $content);
$this->assertStringContainsString('data-dashboard-content', $content);
// The previous full-page-reload approach has been removed in favour of
// updating headline tiles + widgets directly from the JSON payload.
$this->assertStringNotContainsString('data-refresh-url=', $content);
}
public function test_dashboard_blade_labels_match_fifteen_minute_refresh(): void
public function test_dashboard_blade_labels_match_one_minute_refresh(): void
{
$bladePath = resource_path('views/admin/dashboard.blade.php');
@@ -31,7 +31,7 @@ class AdminDashboardAutoRefreshTest extends TestCase
$content = file_get_contents($bladePath);
$this->assertStringContainsString('Auto-refreshes every 15 minutes', $content);
$this->assertStringContainsString('Auto-refreshes every minute', $content);
$this->assertStringContainsString('Last dashboard refresh:', $content);
$this->assertStringContainsString('$dashboardLastRefreshedAt', $content);
$this->assertStringContainsString('data-stat="last-refresh"', $content);
@@ -47,8 +47,7 @@ class AdminDashboardAutoRefreshTest extends TestCase
$content = file_get_contents($scriptPath);
// Auto-refresh interval is preserved.
$this->assertStringContainsString('15 * 60 * 1000', $content);
$this->assertStringContainsString('60 * 1000', $content);
// The fetch hits the cached JSON endpoint.
$this->assertStringContainsString('this.$el.dataset.dataUrl', $content);
// Each tick re-renders headline tiles + registration status + the
@@ -10,8 +10,7 @@ use Tests\TestCase;
* Locks in the "(7d) = last 7 calendar days inclusive of today" semantics
* and the source layering used by the headline summary tiles:
*
* - Closed days come from `user_activity_stats`.
* - Today's closed hours come from `user_activity_stats_hourly`.
* - Every completed hour comes from `user_activity_stats_hourly`.
* - The current in-progress hour comes from the live `user_downloads` /
* `user_requests` tables (which are pruned hourly to ~24h).
*
@@ -21,7 +20,7 @@ use Tests\TestCase;
*/
class AdminDashboardSummaryWindowTest extends TestCase
{
public function test_summary_window_layers_daily_hourly_and_live_sources(): void
public function test_summary_window_layers_hourly_and_live_sources(): void
{
$servicePath = app_path('Services/UserStatsService.php');
@@ -36,18 +35,16 @@ class AdminDashboardSummaryWindowTest extends TestCase
'Summary window must be the last 7 calendar days inclusive of today.'
);
// Closed days from the daily aggregate, strictly before today.
$this->assertStringContainsString('UserActivityStat::query()', $content);
// Every completed hour in the seven-day window comes from the retained
// hourly aggregate, including completed hours from today.
$this->assertStringContainsString(
"->where('stat_date', '>=', \$weekStart->format('Y-m-d'))",
"->where('stat_hour', '>=', \$weekStart->format('Y-m-d H:00:00'))",
$content
);
$this->assertStringContainsString(
"->where('stat_date', '<', \$today->format('Y-m-d'))",
"->where('stat_hour', '<', \$currentHourStart->format('Y-m-d H:00:00'))",
$content
);
// Today's closed hours from the hourly aggregate.
$this->assertStringContainsString(
"DB::table('user_activity_stats_hourly')",
$content
@@ -67,13 +64,13 @@ class AdminDashboardSummaryWindowTest extends TestCase
$content
);
// Today and week totals must combine all three sources.
// Today and week totals combine closed hourly data with live data.
$this->assertStringContainsString(
"'downloads_today' => \$downloadsToday,",
$content
);
$this->assertStringContainsString(
"'downloads_week' => (int) (\$historical->downloads ?? 0) + \$downloadsToday,",
"'downloads_week' => (int) (\$weekClosed->downloads ?? 0) + \$downloadsCurrentHour,",
$content
);
$this->assertStringContainsString(
@@ -81,7 +78,7 @@ class AdminDashboardSummaryWindowTest extends TestCase
$content
);
$this->assertStringContainsString(
"'api_hits_week' => (int) (\$historical->api_hits ?? 0) + \$apiHitsToday,",
"'api_hits_week' => (int) (\$weekClosed->api_hits ?? 0) + \$apiHitsCurrentHour,",
$content
);