import { render, testA11y, screen, press } from '@fuels/jest'; import React from 'react'; import type { MenuProps } from './Menu'; import { Menu } from './Menu'; const TestMenu = (props: Omit) => ( Settings Delete Edit ); describe('Menu', () => { it('a11y', async () => { await testA11y(); }); it('should be focused when use autoFocus', async () => { render(); expect(screen.getByLabelText('settings')).toHaveFocus(); }); it('should be focused when use autoFocus and autoFocusKey', async () => { render(); expect(screen.getByLabelText('trash')).toHaveFocus(); }); it('should dispatch onAction using keyboard command', async () => { let item: React.Key = ''; render( { item = key; }} />, ); await press('Enter'); expect(item).toBe('settings'); }); it('should navigate using arrows keys', async () => { let item: React.Key = ''; render( { item = key; }} />, ); await press('ArrowDown'); await press('Enter'); expect(item).toBe('trash'); }); it('should not be able to trigger action on disabled keys', async () => { let item: React.Key = ''; render( { item = key; }} />, ); await press('ArrowDown'); await press('ArrowDown'); await press('Enter'); expect(item).toBe('settings'); }); });