@@ -493,6 +493,99 @@ test.describe('Menu', () => {
493493 }
494494 } ) ;
495495
496+ test ( 'should set the data-indent attribute correctly when menu items are dynamically appended' , async ( {
497+ fastPage,
498+ } ) => {
499+ const { element } = fastPage ;
500+
501+ await fastPage . setTemplate ( { innerHTML : '' } ) ;
502+
503+ await element . evaluate ( node => {
504+ const items = [ 'item 1' , 'item 2' , 'item 3' ] ;
505+
506+ items . forEach ( item => {
507+ const menuItem = document . createElement ( 'fluent-menu-item' ) ;
508+ menuItem . role = 'menuitemradio' ;
509+ menuItem . textContent = item ;
510+ node . append ( menuItem ) ;
511+ } ) ;
512+ } ) ;
513+
514+ const menuItems = element . locator ( 'fluent-menu-item' ) ;
515+ await expect ( menuItems ) . toHaveCount ( 3 ) ;
516+
517+ for ( const item of await menuItems . all ( ) ) {
518+ await expect ( item ) . toHaveAttribute ( 'data-indent' , '1' ) ;
519+ }
520+ } ) ;
521+
522+ test ( 'should set the data-indent attribute correctly when menu items are appended via a DocumentFragment' , async ( {
523+ fastPage,
524+ } ) => {
525+ const { element } = fastPage ;
526+
527+ await fastPage . setTemplate ( { innerHTML : '' } ) ;
528+
529+ await element . evaluate ( node => {
530+ const fragment = document . createDocumentFragment ( ) ;
531+ const items = [ 'item 1' , 'item 2' , 'item 3' ] ;
532+
533+ items . forEach ( item => {
534+ const menuItem = document . createElement ( 'fluent-menu-item' ) ;
535+ menuItem . role = 'menuitemradio' ;
536+ menuItem . textContent = item ;
537+ fragment . append ( menuItem ) ;
538+ } ) ;
539+
540+ node . append ( fragment ) ;
541+ } ) ;
542+
543+ const menuItems = element . locator ( 'fluent-menu-item' ) ;
544+ await expect ( menuItems ) . toHaveCount ( 3 ) ;
545+
546+ for ( const item of await menuItems . all ( ) ) {
547+ await expect ( item ) . toHaveAttribute ( 'data-indent' , '1' ) ;
548+ }
549+ } ) ;
550+
551+ test ( 'should update data-indent on existing items when a menuitemradio is appended and removed' , async ( {
552+ fastPage,
553+ } ) => {
554+ const { element } = fastPage ;
555+ const menuItems = element . locator ( 'fluent-menu-item' ) ;
556+
557+ await test . step ( 'all plain menuitems should start with data-indent 0' , async ( ) => {
558+ for ( const item of await menuItems . all ( ) ) {
559+ await expect ( item ) . toHaveAttribute ( 'data-indent' , '0' ) ;
560+ }
561+ } ) ;
562+
563+ await test . step ( 'appending a menuitemradio should update all items to data-indent 1' , async ( ) => {
564+ await element . evaluate ( node => {
565+ const menuItem = document . createElement ( 'fluent-menu-item' ) ;
566+ menuItem . role = 'menuitemradio' ;
567+ menuItem . textContent = 'Radio item' ;
568+ node . append ( menuItem ) ;
569+ } ) ;
570+
571+ await expect ( menuItems ) . toHaveCount ( 5 ) ;
572+
573+ for ( const item of await menuItems . all ( ) ) {
574+ await expect ( item ) . toHaveAttribute ( 'data-indent' , '1' ) ;
575+ }
576+ } ) ;
577+
578+ await test . step ( 'removing the menuitemradio should revert all items to data-indent 0' , async ( ) => {
579+ await menuItems . last ( ) . evaluate ( node => node . remove ( ) ) ;
580+
581+ await expect ( menuItems ) . toHaveCount ( 4 ) ;
582+
583+ for ( const item of await menuItems . all ( ) ) {
584+ await expect ( item ) . toHaveAttribute ( 'data-indent' , '0' ) ;
585+ }
586+ } ) ;
587+ } ) ;
588+
496589 test . describe ( '`change` event' , ( ) => {
497590 test ( 'should emit `change` event when `checked` property changed' , async ( { fastPage } ) => {
498591 const { element } = fastPage ;
0 commit comments