Skip to content

Commit e8cf182

Browse files
author
Shipra Gupta
committed
test(menu): improve test coverage for touch and pointer interactions
- Add click event dispatch after touch tap to cover handleSubmenuClick touch prevention - Add touch pointerleave test to cover early return for touch devices - Add test for pointerdown on open submenu followed by focus to cover handleSubmenuFocus These targeted test enhancements improve coverage without adding entirely new test cases.
1 parent 85cb5a8 commit e8cf182

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

1st-gen/packages/menu/test/submenu.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,37 @@ describe('Submenu', () => {
291291

292292
expect(this.rootItem.open).to.be.false;
293293
});
294+
it('handles mouse pointerdown on open submenu followed by focus', async function () {
295+
expect(this.rootItem.open).to.be.false;
296+
297+
// Open the submenu with mouse hover
298+
const opened = oneEvent(this.rootItem, 'sp-opened');
299+
await mouseMoveOver(this.rootItem);
300+
await opened;
301+
302+
expect(this.rootItem.open).to.be.true;
303+
304+
// Dispatch pointerdown on the already-open submenu (non-touch)
305+
// This sets up the focus listener and beforetoggle listener
306+
this.rootItem.dispatchEvent(
307+
new PointerEvent('pointerdown', {
308+
bubbles: true,
309+
pointerType: 'mouse',
310+
})
311+
);
312+
313+
// Dispatch focus event to trigger handleSubmenuFocus
314+
this.rootItem.dispatchEvent(
315+
new FocusEvent('focus', {
316+
bubbles: true,
317+
})
318+
);
319+
320+
await elementUpdated(this.rootItem);
321+
322+
// Submenu should remain open after focus handling
323+
expect(this.rootItem.open).to.be.true;
324+
});
294325
}
295326
function persistsThroughMouseLeaveAndReturn(): void {
296327
it('stays open when mousing off menu item and back again', async function () {
@@ -928,6 +959,17 @@ describe('Submenu', () => {
928959
await aTimeout(150);
929960

930961
expect(this.rootItem.open).to.be.false;
962+
963+
// Also test that touch pointerleave doesn't affect closed state
964+
this.rootItem.dispatchEvent(
965+
new PointerEvent('pointerleave', {
966+
bubbles: true,
967+
pointerType: 'touch',
968+
})
969+
);
970+
971+
await elementUpdated(this.rootItem);
972+
expect(this.rootItem.open).to.be.false;
931973
});
932974

933975
it('opens submenu on touch tap when closed', async function () {
@@ -951,6 +993,18 @@ describe('Submenu', () => {
951993
await opened;
952994

953995
expect(this.rootItem.open).to.be.true;
996+
997+
// Dispatch click event (browsers do this after touch)
998+
// This should be prevented/stopped by handleSubmenuClick
999+
this.rootItem.dispatchEvent(
1000+
new MouseEvent('click', {
1001+
bubbles: true,
1002+
})
1003+
);
1004+
1005+
// Verify submenu remains open (click was handled properly)
1006+
await elementUpdated(this.rootItem);
1007+
expect(this.rootItem.open).to.be.true;
9541008
});
9551009

9561010
it('closes submenu on touch tap when open', async function () {

0 commit comments

Comments
 (0)