Default lobby cards to four-player capacity

This commit is contained in:
2026-10-07 23:53:01 -04:00
parent 92c50e62a1
commit e514d21b74
2 changed files with 11 additions and 7 deletions
+3 -2
View File
@@ -65,7 +65,8 @@
const currentRound = $derived(!gameEndedAt ? (round !== undefined ? round : reportedRound) : null);
const gameElapsed = $derived(gameStartedAt && !gameEndedAt ? elapsedSince(gameStartedAt, $uiNow) : null);
const emptyElapsed = $derived(elapsedSince(inactiveSince, $uiNow));
const knownCapacity = $derived(capacity !== null && Number.isFinite(capacity) && capacity > 0 ? capacity : null);
// These lobbies have four slots when the live status omits the limit.
const displayCapacity = $derived(capacity !== null && Number.isSafeInteger(capacity) && capacity > 0 ? capacity : 4);
const cardStyle = $derived(`view-transition-name: server-${name.replace(/[^a-z0-9_-]/gi, '-')};`);
</script>
@@ -90,7 +91,7 @@
{#if showMap}<p class="map-note">{health === 'online' ? 'Current map' : 'Last map'}: {mapLabel}</p>{/if}
{#if health === 'online'}
<dl class="metrics">
<div><dt>Players</dt><dd title={knownCapacity === null ? 'Capacity unavailable' : `${knownCapacity} player capacity`}>{players ?? '—'}<span class="capacity">/{knownCapacity ?? '?'}</span></dd></div>
<div><dt>Players</dt><dd title={`${displayCapacity} player capacity`}>{players ?? '—'}<span class="capacity">/{displayCapacity}</span></dd></div>
<div><dt>Round</dt><dd>{currentRound ?? '—'}</dd></div>
<div><dt>Match time</dt><dd>{gameElapsed ?? '—'}</dd></div>
</dl>
+8 -5
View File
@@ -29,11 +29,14 @@ describe('compact server cards', () => {
expect(body).not.toMatch(/Last seen|Last reported|Zombies Classic|>Active</);
});
it('keeps capacity unknown when unavailable and never invents a four-player limit', () => {
const body = html({ players: 2, capacity: null });
expect(body).toContain('title="Capacity unavailable"');
expect(body).toMatch(/>2<span[^>]*>\/\?<\/span>/);
expect(body).not.toContain('/4');
it('defaults to four lobby slots when capacity is unavailable, while preserving a reported limit', () => {
for (const capacity of [null, undefined, 0, -1, 4.5, NaN, Infinity]) {
const body = html({ players: 2, capacity });
expect(body).toContain('title="4 player capacity"');
expect(body).toMatch(/>2<span[^>]*>\/4<\/span>/);
expect(body).not.toContain('/?');
}
expect(html({ players: 2, capacity: 8 })).toMatch(/>2<span[^>]*>\/8<\/span>/);
});
it('uses the newest fresh report while respecting explicit round data and match boundaries', () => {