refactor: update usage pattern for tic tac toe and boop
This commit is contained in:
+13
-21
@@ -498,14 +498,12 @@ describe('Boop - game flow', () => {
|
||||
const runPromise = ctx.commands.run<{winner: WinnerType}>('turn white');
|
||||
|
||||
const promptEvent1 = await promptPromise;
|
||||
// 没有验证器,tryCommit 返回 null,但游戏逻辑会 continue 并重新 prompt
|
||||
// 验证器会拒绝错误的玩家
|
||||
const error1 = promptEvent1.tryCommit({ name: 'play', params: ['black', 2, 2], options: {}, flags: {} });
|
||||
expect(error1).toBeNull();
|
||||
expect(error1).toContain('Invalid player');
|
||||
|
||||
const promptEvent2 = await waitForPrompt(ctx);
|
||||
expect(promptEvent2).not.toBeNull();
|
||||
|
||||
const error2 = promptEvent2.tryCommit({ name: 'play', params: ['white', 2, 2], options: {}, flags: {} });
|
||||
// 验证失败后,再次尝试有效输入
|
||||
const error2 = promptEvent1.tryCommit({ name: 'play', params: ['white', 2, 2], options: {}, flags: {} });
|
||||
expect(error2).toBeNull();
|
||||
|
||||
const result = await runPromise;
|
||||
@@ -524,12 +522,10 @@ describe('Boop - game flow', () => {
|
||||
|
||||
const promptEvent1 = await promptPromise;
|
||||
const error1 = promptEvent1.tryCommit({ name: 'play', params: ['white', 2, 2], options: {}, flags: {} });
|
||||
expect(error1).toBeNull();
|
||||
expect(error1).toContain('occupied');
|
||||
|
||||
const promptEvent2 = await waitForPrompt(ctx);
|
||||
expect(promptEvent2).not.toBeNull();
|
||||
|
||||
const error2 = promptEvent2.tryCommit({ name: 'play', params: ['white', 0, 0], options: {}, flags: {} });
|
||||
// 验证失败后,再次尝试有效输入
|
||||
const error2 = promptEvent1.tryCommit({ name: 'play', params: ['white', 0, 0], options: {}, flags: {} });
|
||||
expect(error2).toBeNull();
|
||||
|
||||
const result = await runPromise;
|
||||
@@ -550,12 +546,10 @@ describe('Boop - game flow', () => {
|
||||
|
||||
const promptEvent1 = await promptPromise;
|
||||
const error1 = promptEvent1.tryCommit({ name: 'play', params: ['white', 0, 0], options: {}, flags: {} });
|
||||
expect(error1).toBeNull();
|
||||
expect(error1).toContain('No kittens');
|
||||
|
||||
const promptEvent2 = await waitForPrompt(ctx);
|
||||
expect(promptEvent2).not.toBeNull();
|
||||
|
||||
promptEvent2.cancel('test end');
|
||||
// 验证失败后,取消
|
||||
promptEvent1.cancel('test end');
|
||||
|
||||
const result = await runPromise;
|
||||
expect(result.success).toBe(false);
|
||||
@@ -643,12 +637,10 @@ describe('Boop - game flow', () => {
|
||||
|
||||
const promptEvent1 = await promptPromise;
|
||||
const error1 = promptEvent1.tryCommit({ name: 'play', params: ['white', 0, 0, 'cat'], options: {}, flags: {} });
|
||||
expect(error1).toBeNull();
|
||||
expect(error1).toContain('No cats');
|
||||
|
||||
const promptEvent2 = await waitForPrompt(ctx);
|
||||
expect(promptEvent2).not.toBeNull();
|
||||
|
||||
promptEvent2.cancel('test end');
|
||||
// 验证失败后,取消
|
||||
promptEvent1.cancel('test end');
|
||||
|
||||
const result = await runPromise;
|
||||
expect(result.success).toBe(false);
|
||||
|
||||
@@ -240,14 +240,12 @@ describe('TicTacToe - game flow', () => {
|
||||
const runPromise = ctx.commands.run<{winner: WinnerType}>('turn X 1');
|
||||
|
||||
const promptEvent1 = await promptPromise;
|
||||
// 没有验证器,tryCommit 返回 null,但游戏逻辑会 continue 并重新 prompt
|
||||
// 验证器会拒绝错误的玩家
|
||||
const error1 = promptEvent1.tryCommit({ name: 'play', params: ['O', 1, 1], options: {}, flags: {} });
|
||||
expect(error1).toBeNull();
|
||||
expect(error1).toContain('Invalid player');
|
||||
|
||||
const promptEvent2 = await waitForPrompt(ctx);
|
||||
expect(promptEvent2).not.toBeNull();
|
||||
|
||||
const error2 = promptEvent2.tryCommit({ name: 'play', params: ['X', 1, 1], options: {}, flags: {} });
|
||||
// 验证失败后,再次尝试有效输入
|
||||
const error2 = promptEvent1.tryCommit({ name: 'play', params: ['X', 1, 1], options: {}, flags: {} });
|
||||
expect(error2).toBeNull();
|
||||
|
||||
const result = await runPromise;
|
||||
@@ -266,12 +264,10 @@ describe('TicTacToe - game flow', () => {
|
||||
|
||||
const promptEvent1 = await promptPromise;
|
||||
const error1 = promptEvent1.tryCommit({ name: 'play', params: ['X', 1, 1], options: {}, flags: {} });
|
||||
expect(error1).toBeNull();
|
||||
expect(error1).toContain('occupied');
|
||||
|
||||
const promptEvent2 = await waitForPrompt(ctx);
|
||||
expect(promptEvent2).not.toBeNull();
|
||||
|
||||
const error2 = promptEvent2.tryCommit({ name: 'play', params: ['X', 0, 0], options: {}, flags: {} });
|
||||
// 验证失败后,再次尝试有效输入
|
||||
const error2 = promptEvent1.tryCommit({ name: 'play', params: ['X', 0, 0], options: {}, flags: {} });
|
||||
expect(error2).toBeNull();
|
||||
|
||||
const result = await runPromise;
|
||||
|
||||
Reference in New Issue
Block a user