Skip to content

Commit 22e8845

Browse files
committed
test(web): make the minimized-card test prove the keyboard guard
The assertion only observed an absence, so it passed even when the document keydown listener was missing entirely. Answer once while the card is expanded, then assert the count does not grow after minimizing.
1 parent 4df78c2 commit 22e8845

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

apps/pythinker-web/test/question-card-lifecycle.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,16 @@ describe('QuestionCard lifecycle', () => {
107107
const wrapper = mountCard(question(new Date(Date.now() + 20 * 60_000).toISOString()));
108108

109109
document.dispatchEvent(new KeyboardEvent('keydown', { key: '1', bubbles: true }));
110+
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
111+
const answerCount = wrapper.emitted('answer')?.length ?? 0;
112+
113+
expect(answerCount).toBe(1);
114+
110115
await wrapper.find('.qmin').trigger('click');
116+
117+
document.dispatchEvent(new KeyboardEvent('keydown', { key: '1', bubbles: true }));
111118
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
112119

113-
expect(wrapper.emitted('answer')).toBeUndefined();
120+
expect(wrapper.emitted('answer')).toHaveLength(answerCount);
114121
});
115122
});

0 commit comments

Comments
 (0)