Skip to content

Commit 7c74dfb

Browse files
feat(boxai-sidebar): UT added
1 parent 9232631 commit 7c74dfb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/elements/content-sidebar/__tests__/BoxAISidebar.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,29 @@ describe('elements/content-sidebar/BoxAISidebar', () => {
220220

221221
expect(screen.queryByTestId('content-answers-modal')).not.toBeInTheDocument();
222222
});
223+
224+
describe('BoxAISidebar handleKeyPress', () => {
225+
226+
test('should prevent default behavior and stop propagation for ArrowLeft and ArrowRight keys', async () => {
227+
await renderComponent();
228+
229+
const eventLeft = new KeyboardEvent('keydown', { key: 'ArrowLeft' });
230+
const preventDefaultSpy = jest.spyOn(eventLeft, 'preventDefault');
231+
const stopPropagationSpy = jest.spyOn(eventLeft, 'stopPropagation');
232+
233+
document.dispatchEvent(eventLeft);
234+
235+
expect(preventDefaultSpy).toHaveBeenCalled();
236+
expect(stopPropagationSpy).toHaveBeenCalled();
237+
238+
const eventRight = new KeyboardEvent('keydown', { key: 'ArrowRight' });
239+
const preventDefaultSpyRight = jest.spyOn(eventRight, 'preventDefault');
240+
const stopPropagationSpyRight = jest.spyOn(eventRight, 'stopPropagation');
241+
242+
document.dispatchEvent(eventRight);
243+
244+
expect(preventDefaultSpyRight).toHaveBeenCalled();
245+
expect(stopPropagationSpyRight).toHaveBeenCalled();
246+
});
247+
});
223248
});

0 commit comments

Comments
 (0)