feat: add currentPlayer to prompt

This commit is contained in:
2026-04-04 11:01:25 +08:00
parent d1264f3b9e
commit be4ff7ae08
6 changed files with 78 additions and 16 deletions
+46
View File
@@ -410,4 +410,50 @@ describe('GameHost', () => {
expect(host.status.value).toBe('disposed');
});
});
describe('currentPlayer in prompt', () => {
it('should have currentPlayer in PromptEvent', async () => {
const { host } = createTestHost();
const promptPromise = waitForPromptEvent(host);
const runPromise = host.commands.run('setup');
const promptEvent = await promptPromise;
expect(promptEvent.currentPlayer).toBe('X');
expect(host.activePromptPlayer.value).toBe('X');
promptEvent.cancel('test cleanup');
await runPromise;
});
it('should update activePromptPlayer reactively', async () => {
const { host } = createTestHost();
// Initially null
expect(host.activePromptPlayer.value).toBeNull();
// First prompt - X's turn
let promptPromise = waitForPromptEvent(host);
let runPromise = host.commands.run('setup');
let promptEvent = await promptPromise;
expect(promptEvent.currentPlayer).toBe('X');
expect(host.activePromptPlayer.value).toBe('X');
// Make a move
promptEvent.tryCommit({ name: 'play', params: ['X', 1, 1], options: {}, flags: {} });
// Second prompt - O's turn
promptPromise = waitForPromptEvent(host);
promptEvent = await promptPromise;
expect(promptEvent.currentPlayer).toBe('O');
expect(host.activePromptPlayer.value).toBe('O');
// Cancel
promptEvent.cancel('test cleanup');
await runPromise;
// After prompt ends, player should be null
expect(host.activePromptPlayer.value).toBeNull();
});
});
});