Replace unused server metrics with a count (Refs #139)
CI / checks (push) Successful in 4m51s

This commit is contained in:
2026-10-10 16:55:28 -04:00
parent aebfc7a783
commit 0bfda267ec
7 changed files with 80 additions and 88 deletions
+25 -17
View File
@@ -1,11 +1,6 @@
import { beforeEach, expect, it, vi } from 'vitest';
import { render } from 'svelte/server';
import type {
MetricsData,
MapMetrics,
ServerMetrics,
MatchMetrics
} from '../../src/lib/metrics.js';
import type { MetricsData, MapMetrics, MatchMetrics } from '../../src/lib/metrics.js';
import MetricsPage from '../../src/routes/metrics/+page.svelte';
import MetricsSummary from '../../src/lib/ui/components/metrics/MetricsSummary.svelte';
import MetricsTables from '../../src/lib/ui/components/metrics/MetricsTables.svelte';
@@ -53,15 +48,6 @@ const map = (i: number, changes: Partial<MapMetrics> = {}): MapMetrics => ({
policy: null,
...changes
});
const server = (i: number): ServerMetrics => ({
server: `t5_zombie_theater_${i}`,
currentRegistered: i !== 1,
observed: 10,
active: i / 10,
idle: 10 - i / 10,
unknown: 0,
playerHours: i
});
function report(): MetricsData {
const now = Date.parse('2026-10-06T12:00:00Z');
const summary = { observed: 10, active: 5, idle: 5, unknown: 2, playerHours: 20 };
@@ -81,7 +67,7 @@ function report(): MetricsData {
summary,
running: { average: 12, peak: 24, capturedHours: 1 },
maps: Array.from({ length: 24 }, (_, i) => map(i + 1)),
servers: Array.from({ length: 24 }, (_, i) => server(i + 1)),
sampledServerCount: 24,
points: [
{
...summary,
@@ -120,6 +106,28 @@ function scope(search: string, stateSearch?: string) {
}
beforeEach(() => scope(''));
it.each([
[0, 'No captured time in this scope'],
[1, 'Waiting for observed time']
] as const)('uses the sampled-server count %i for the empty state', (sampledServerCount, title) => {
const data = report();
data.summary = { observed: 0, active: 0, idle: 0, unknown: 0, playerHours: 0 };
data.running = { average: null, peak: 0, capturedHours: 0 };
data.matches = matches({
started: 0,
withRecordedPlayers: 0,
averageGroupSize: null,
solo: 0,
soloShare: null
});
data.maps = [];
data.sampledServerCount = sampledServerCount;
const body = render(MetricsPage, {
props: { data: { ...data, user: null, setupRequired: false } }
}).body;
expect(body).toContain(title);
});
it('shows a summary and one paginated breakdown, preserving scope on range links', () => {
scope('?game=t5&days=7&view=maps&mapPage=2');
const body = render(MetricsPage, {
@@ -271,7 +279,7 @@ it('keeps match summaries and map rows visible without any retained occupancy sa
data.firstRetainedSampleAt = null;
data.scopeFirstSampleAt = null;
data.scopeLatestSampleAt = null;
data.servers = [];
data.sampledServerCount = 0;
data.maps = [
map(1, {
...data.summary,