@@ -12,6 +12,18 @@ import DxcCard from "../card/Card.tsx";
1212import DxcRadioGroup from "../radio-group/RadioGroup.tsx" ;
1313import DxcSlider from "../slider/Slider.tsx" ;
1414import DxcSwitch from "../switch/Switch.tsx" ;
15+ import DxcDateInput from "../date-input/DateInput.tsx" ;
16+
17+ // Mocking DOMRect for Radix Primitive Popover
18+ global . globalThis = global ;
19+ global . DOMRect = {
20+ fromRect : ( ) => ( { top : 0 , left : 0 , bottom : 0 , right : 0 , width : 0 , height : 0 } ) ,
21+ } ;
22+ global . ResizeObserver = class ResizeObserver {
23+ observe ( ) { }
24+ unobserve ( ) { }
25+ disconnect ( ) { }
26+ } ;
1527
1628const options = [
1729 { label : "Female" , value : "female" } ,
@@ -57,6 +69,19 @@ describe("Dialog component tests", () => {
5769 fireEvent . keyDown ( getByRole ( "dialog" ) , { key : "Escape" , code : "Escape" , keyCode : 27 , charCode : 27 } ) ;
5870 expect ( onCloseClick ) . toHaveBeenCalled ( ) ;
5971 } ) ;
72+
73+ test ( "Does not call function onCloseClick when 'Escape' key is pressed while a child popover is opened" , async ( ) => {
74+ const onCloseClick = jest . fn ( ) ;
75+ const { getByRole } = render (
76+ < DxcDialog onCloseClick = { onCloseClick } >
77+ < DxcDateInput label = "With format M-dd-yyyy" format = "M-dd-yyyy" />
78+ </ DxcDialog >
79+ ) ;
80+ const calendarAction = getByRole ( "combobox" ) ;
81+ await userEvent . click ( calendarAction ) ;
82+ fireEvent . keyDown ( document . activeElement , { key : "Escape" , code : "Escape" , keyCode : 27 , charCode : 27 } ) ;
83+ expect ( onCloseClick ) . not . toHaveBeenCalled ( ) ;
84+ } ) ;
6085} ) ;
6186
6287describe ( "Dialog component: Focus lock tests" , ( ) => {
0 commit comments