@@ -6,6 +6,7 @@ import {Dialog} from './Dialog'
66import { Button } from '../Button'
77import { implementsClassName } from '../utils/testing'
88import classes from './Dialog.module.css'
9+ import { FeatureFlags } from '../FeatureFlags'
910
1011describe ( 'Dialog' , ( ) => {
1112 implementsClassName ( Dialog , classes . Dialog )
@@ -338,4 +339,107 @@ describe('Footer button loading states', () => {
338339 expect ( publishButton ) . toHaveAttribute ( 'data-loading' , 'true' )
339340 expect ( deleteButton ) . not . toHaveAttribute ( 'data-loading' , 'true' )
340341 } )
342+
343+ describe ( 'primer_react_css_has_selector_perf feature flag' , ( ) => {
344+ it ( 'does not add data-dialog-scroll-optimized attribute when flag is OFF' , ( ) => {
345+ const { unmount} = render (
346+ < FeatureFlags flags = { { primer_react_css_has_selector_perf : false } } >
347+ < Dialog onClose = { ( ) => { } } > Dialog content</ Dialog >
348+ </ FeatureFlags > ,
349+ )
350+
351+ expect ( document . body . hasAttribute ( 'data-dialog-scroll-optimized' ) ) . toBe ( false )
352+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( true )
353+
354+ unmount ( )
355+
356+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( false )
357+ } )
358+
359+ it ( 'adds data-dialog-scroll-optimized attribute when flag is ON' , ( ) => {
360+ const { unmount} = render (
361+ < FeatureFlags flags = { { primer_react_css_has_selector_perf : true } } >
362+ < Dialog onClose = { ( ) => { } } > Dialog content</ Dialog >
363+ </ FeatureFlags > ,
364+ )
365+
366+ expect ( document . body . hasAttribute ( 'data-dialog-scroll-optimized' ) ) . toBe ( true )
367+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( true )
368+
369+ unmount ( )
370+
371+ expect ( document . body . hasAttribute ( 'data-dialog-scroll-optimized' ) ) . toBe ( false )
372+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( false )
373+ } )
374+
375+ it ( 'handles multiple dialogs with ref counting when flag is ON' , ( ) => {
376+ const { unmount : unmount1 } = render (
377+ < FeatureFlags flags = { { primer_react_css_has_selector_perf : true } } >
378+ < Dialog onClose = { ( ) => { } } > Dialog 1</ Dialog >
379+ </ FeatureFlags > ,
380+ )
381+
382+ expect ( document . body . hasAttribute ( 'data-dialog-scroll-optimized' ) ) . toBe ( true )
383+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( true )
384+
385+ // Render second dialog
386+ const { unmount : unmount2 } = render (
387+ < FeatureFlags flags = { { primer_react_css_has_selector_perf : true } } >
388+ < Dialog onClose = { ( ) => { } } > Dialog 2</ Dialog >
389+ </ FeatureFlags > ,
390+ )
391+
392+ // Attribute should still be present
393+ expect ( document . body . hasAttribute ( 'data-dialog-scroll-optimized' ) ) . toBe ( true )
394+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( true )
395+
396+ // Unmount first dialog
397+ unmount1 ( )
398+
399+ // Attribute and class should still be present (second dialog is still open)
400+ expect ( document . body . hasAttribute ( 'data-dialog-scroll-optimized' ) ) . toBe ( true )
401+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( true )
402+
403+ // Unmount second dialog
404+ unmount2 ( )
405+
406+ // Now both should be removed
407+ expect ( document . body . hasAttribute ( 'data-dialog-scroll-optimized' ) ) . toBe ( false )
408+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( false )
409+ } )
410+
411+ it ( 'handles multiple dialogs correctly when flag is OFF' , ( ) => {
412+ const { unmount : unmount1 } = render (
413+ < FeatureFlags flags = { { primer_react_css_has_selector_perf : false } } >
414+ < Dialog onClose = { ( ) => { } } > Dialog 1</ Dialog >
415+ </ FeatureFlags > ,
416+ )
417+
418+ expect ( document . body . hasAttribute ( 'data-dialog-scroll-optimized' ) ) . toBe ( false )
419+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( true )
420+
421+ // Render second dialog
422+ const { unmount : unmount2 } = render (
423+ < FeatureFlags flags = { { primer_react_css_has_selector_perf : false } } >
424+ < Dialog onClose = { ( ) => { } } > Dialog 2</ Dialog >
425+ </ FeatureFlags > ,
426+ )
427+
428+ // Attribute should not be present, class should be present
429+ expect ( document . body . hasAttribute ( 'data-dialog-scroll-optimized' ) ) . toBe ( false )
430+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( true )
431+
432+ // Unmount first dialog
433+ unmount1 ( )
434+
435+ // Class should still be present (second dialog is still open)
436+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( true )
437+
438+ // Unmount second dialog
439+ unmount2 ( )
440+
441+ // Class should be removed
442+ expect ( document . body . classList . contains ( 'DialogScrollDisabled' ) ) . toBe ( false )
443+ } )
444+ } )
341445} )
0 commit comments