@@ -57,16 +57,6 @@ describe('NewPicker.Range', () => {
5757 beforeAll ( ( ) => {
5858 jest . spyOn ( document . documentElement , 'scrollWidth' , 'get' ) . mockReturnValue ( 1000 ) ;
5959
60- // Viewport size
61- spyElementPrototypes ( HTMLElement , {
62- clientWidth : {
63- get : ( ) => 400 ,
64- } ,
65- clientHeight : {
66- get : ( ) => 400 ,
67- } ,
68- } ) ;
69-
7060 // Popup size
7161 spyElementPrototypes ( HTMLDivElement , {
7262 getBoundingClientRect ( ) {
@@ -110,6 +100,13 @@ describe('NewPicker.Range', () => {
110100 } ,
111101 } ) ;
112102 spyElementPrototypes ( HTMLElement , {
103+ // Viewport size
104+ clientWidth : {
105+ get : ( ) => 400 ,
106+ } ,
107+ clientHeight : {
108+ get : ( ) => 400 ,
109+ } ,
113110 offsetParent : {
114111 get : ( ) => document . body ,
115112 } ,
@@ -120,6 +117,17 @@ describe('NewPicker.Range', () => {
120117 }
121118 } ,
122119 } ,
120+ // offsetParent
121+ getBoundingClientRect ( ) {
122+ if ( this . tagName === 'BODY' ) {
123+ return {
124+ x : 0 ,
125+ y : 0 ,
126+ width : 200 ,
127+ height : 200 ,
128+ } ;
129+ }
130+ } ,
123131 } ) ;
124132 } ) ;
125133
@@ -1423,14 +1431,28 @@ describe('NewPicker.Range', () => {
14231431 it ( 'the arrow should be set to `inset-inline-start` when the popup is aligned to `bottomLeft`.' , async ( ) => {
14241432 render ( < DayRangePicker open /> ) ;
14251433
1434+ const oriGetComputedStyle = window . getComputedStyle ;
1435+ window . getComputedStyle = ( ele : HTMLElement ) => {
1436+ const retObj = oriGetComputedStyle ( ele ) ;
1437+
1438+ retObj . borderRightWidth = '4px' ;
1439+ retObj . borderLeftWidth = '2px' ;
1440+ return retObj ;
1441+ } ;
1442+
14261443 await act ( async ( ) => {
14271444 jest . runAllTimers ( ) ;
14281445
14291446 await Promise . resolve ( ) ;
14301447 } ) ;
1448+
14311449 expect ( document . querySelector ( '.rc-picker-range-arrow' ) ) . toHaveStyle ( {
14321450 'inset-inline-start' : '0' ,
14331451 } ) ;
1452+ expect ( document . querySelector ( '.rc-picker-active-bar' ) ) . toHaveStyle ( {
1453+ 'inset-inline-start' : '-2px' ,
1454+ } ) ;
1455+ window . getComputedStyle = oriGetComputedStyle ;
14341456 } ) ;
14351457
14361458 it ( 'the arrow should be set to `inset-inline-end` when the popup is aligned to `bottomRight`.' , async ( ) => {
@@ -1450,9 +1472,24 @@ describe('NewPicker.Range', () => {
14501472 x : 300 ,
14511473 } ;
14521474 }
1475+ if ( this . className . includes ( 'rc-picker-input' ) ) {
1476+ return {
1477+ ...rangeRect ,
1478+ width : 100 ,
1479+ } ;
1480+ }
14531481 } ,
14541482 } ) ;
14551483
1484+ const oriGetComputedStyle = window . getComputedStyle ;
1485+ window . getComputedStyle = ( ele : HTMLElement ) => {
1486+ const retObj = oriGetComputedStyle ( ele ) ;
1487+
1488+ retObj . borderRightWidth = '4px' ;
1489+ retObj . borderLeftWidth = '2px' ;
1490+ return retObj ;
1491+ } ;
1492+
14561493 render ( < DayRangePicker open /> ) ;
14571494
14581495 await act ( async ( ) => {
@@ -1465,10 +1502,11 @@ describe('NewPicker.Range', () => {
14651502 } ) ;
14661503
14671504 expect ( document . querySelector ( '.rc-picker-active-bar' ) ) . toHaveStyle ( {
1468- 'inset-inline-end' : '100px ' ,
1505+ 'inset-inline-end' : '96px ' ,
14691506 } ) ;
14701507
14711508 mock . mockRestore ( ) ;
1509+ window . getComputedStyle = oriGetComputedStyle ;
14721510 } ) ;
14731511 } ) ;
14741512} ) ;
0 commit comments