feat: add currentPlayer to prompt
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user