Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions twenty-questions/TwentyQuestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,12 @@ export class TwentyQuestions {
}

if (isCorrect) {
await this.#slack.chat.postEphemeral({
channel: this.#SANDBOX_ID,
user: userId,
text: `正解!お題は「${this.#state.currentGame.topic}」でした`,
});

await this.#slack.chat.postMessage({
channel: this.#SANDBOX_ID,
thread_ts: this.#state.currentGame.statusMessageTs ?? undefined,
Expand Down
77 changes: 77 additions & 0 deletions twenty-questions/views/playerModal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,81 @@ describe('playerModal', () => {
expect(historyText).toContain('りんご');
expect(historyText).toContain('不正解です');
});

it('shows topic when player finished with correct answer', () => {
const player: PlayerState = {
...basePlayer,
questionCount: 10,
questions: [
{
question: '答え: テスト',
answer: '正解!',
timestamp: Date.now(),
isAnswerAttempt: true,
isCorrect: true,
},
],
isFinished: true,
score: 10,
};

const view = playerModal(baseState, player);

expectEquals(view.type, 'modal');
expect(view.submit).toBeUndefined();

// 正解済みメッセージが表示されていることを確認
const finishedText = view.blocks
?.filter((block): block is SectionBlock => block.type === 'section')
.map((block) => block.text?.text)
.join('\n');

expect(finishedText).toContain('正解済み');
expect(finishedText).toContain('10問で正解');
expect(finishedText).toContain('正解: *テスト*');
});

it('shows topic when player finished by using all questions', () => {
const player: PlayerState = {
...basePlayer,
questionCount: 20,
questions: Array(20).fill(null).map(() => ({
question: 'test',
answer: 'はい',
timestamp: Date.now(),
isAnswerAttempt: false,
})),
isFinished: true,
score: null,
};

const view = playerModal(baseState, player);

expectEquals(view.type, 'modal');
expect(view.submit).toBeUndefined();

// ゲーム終了メッセージと正解のお題が表示されていることを確認
const finishedText = view.blocks
?.filter((block): block is SectionBlock => block.type === 'section')
.map((block) => block.text?.text)
.join('\n');

expect(finishedText).toContain('ゲーム終了');
expect(finishedText).toContain('20問使い切りました');
expect(finishedText).toContain('正解: *テスト*');
});

it('does not show submit button when player is finished', () => {
const player: PlayerState = {
...basePlayer,
questionCount: 10,
isFinished: true,
score: 10,
};

const view = playerModal(baseState, player);

expectEquals(view.type, 'modal');
expect(view.submit).toBeUndefined();
});
});
10 changes: 10 additions & 0 deletions twenty-questions/views/playerModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ export default (state: StateObj, player: PlayerState): View => {
},
});

if (state.currentGame) {
blocks.push({
type: 'section',
text: {
type: 'mrkdwn',
text: `正解: *${state.currentGame.topic}*`,
},
});
}

return {
type: 'modal',
callback_id: 'twenty_questions_player_modal',
Expand Down
Loading