5df82aa4f3
The launcher was mixing lifecycle event handlers with the games-list snapshot when deciding the card status. That left multiple writers for the same install_status field and made event ordering visible in React. Make games-list-updated active_operations the authoritative source for busy status. Lifecycle events no longer mutate the card status; they only keep their non-status side effects such as rescans and error messages. The only remaining optimistic status is CheckingPeers before the backend emits its next snapshot. Add a frontend reducer test that proves an install stays in Installing while an active install snapshot exists, then settles to Installed only after the active operation clears with installed local state. Test Plan: - git diff --check - just fmt - just frontend-test - just build Refs: local install/download status snapshot cleanup
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import {
|
|
activeStatusById,
|
|
mergeGameUpdate,
|
|
} from '../src/lib/gameState.ts';
|
|
import {
|
|
ActiveOperationKind,
|
|
GameAvailability,
|
|
InstallStatus,
|
|
type Game,
|
|
} from '../src/lib/types.ts';
|
|
|
|
const assertEquals = <T>(actual: T, expected: T, message: string) => {
|
|
if (actual !== expected) {
|
|
throw new Error(`${message}: expected ${expected}, got ${actual}`);
|
|
}
|
|
};
|
|
|
|
const game = (overrides: Partial<Game> = {}): Game => ({
|
|
id: 'game',
|
|
name: 'Game',
|
|
description: '',
|
|
size: 0,
|
|
downloaded: false,
|
|
installed: false,
|
|
availability: GameAvailability.LocalOnly,
|
|
install_status: InstallStatus.NotInstalled,
|
|
peer_count: 1,
|
|
...overrides,
|
|
});
|
|
|
|
Deno.test('snapshot keeps installing visible until installed state settles', () => {
|
|
const fromDownloading = game({
|
|
install_status: InstallStatus.Downloading,
|
|
});
|
|
const installing = mergeGameUpdate(
|
|
game({ downloaded: true }),
|
|
fromDownloading,
|
|
InstallStatus.Installing,
|
|
);
|
|
const installedWhileActive = mergeGameUpdate(
|
|
game({ downloaded: true, installed: true }),
|
|
installing,
|
|
InstallStatus.Installing,
|
|
);
|
|
const settled = mergeGameUpdate(
|
|
game({ downloaded: true, installed: true }),
|
|
installedWhileActive,
|
|
);
|
|
|
|
assertEquals(
|
|
installing.install_status,
|
|
InstallStatus.Installing,
|
|
'active install snapshot should render Installing',
|
|
);
|
|
assertEquals(
|
|
installedWhileActive.install_status,
|
|
InstallStatus.Installing,
|
|
'installed local state should not override an active install snapshot',
|
|
);
|
|
assertEquals(
|
|
settled.install_status,
|
|
InstallStatus.Installed,
|
|
'cleared active snapshot with installed local state should render Installed',
|
|
);
|
|
});
|
|
|
|
Deno.test('active operation snapshot is the source of busy status', () => {
|
|
const statuses = activeStatusById([
|
|
{ id: 'game', operation: ActiveOperationKind.Downloading },
|
|
{ id: 'other', operation: ActiveOperationKind.Updating },
|
|
]);
|
|
|
|
assertEquals(
|
|
statuses.get('game'),
|
|
InstallStatus.Downloading,
|
|
'download operation should render Downloading',
|
|
);
|
|
assertEquals(
|
|
statuses.get('other'),
|
|
InstallStatus.Installing,
|
|
'update operation should render Installing',
|
|
);
|
|
});
|