@@ -57,16 +57,6 @@ describe('NewPicker.Range', () => {
57
57
beforeAll ( ( ) => {
58
58
jest . spyOn ( document . documentElement , 'scrollWidth' , 'get' ) . mockReturnValue ( 1000 ) ;
59
59
60
- // Viewport size
61
- spyElementPrototypes ( HTMLElement , {
62
- clientWidth : {
63
- get : ( ) => 400 ,
64
- } ,
65
- clientHeight : {
66
- get : ( ) => 400 ,
67
- } ,
68
- } ) ;
69
-
70
60
// Popup size
71
61
spyElementPrototypes ( HTMLDivElement , {
72
62
getBoundingClientRect ( ) {
@@ -110,6 +100,13 @@ describe('NewPicker.Range', () => {
110
100
} ,
111
101
} ) ;
112
102
spyElementPrototypes ( HTMLElement , {
103
+ // Viewport size
104
+ clientWidth : {
105
+ get : ( ) => 400 ,
106
+ } ,
107
+ clientHeight : {
108
+ get : ( ) => 400 ,
109
+ } ,
113
110
offsetParent : {
114
111
get : ( ) => document . body ,
115
112
} ,
@@ -120,6 +117,17 @@ describe('NewPicker.Range', () => {
120
117
}
121
118
} ,
122
119
} ,
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
+ } ,
123
131
} ) ;
124
132
} ) ;
125
133
@@ -1423,14 +1431,28 @@ describe('NewPicker.Range', () => {
1423
1431
it ( 'the arrow should be set to `inset-inline-start` when the popup is aligned to `bottomLeft`.' , async ( ) => {
1424
1432
render ( < DayRangePicker open /> ) ;
1425
1433
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
+
1426
1443
await act ( async ( ) => {
1427
1444
jest . runAllTimers ( ) ;
1428
1445
1429
1446
await Promise . resolve ( ) ;
1430
1447
} ) ;
1448
+
1431
1449
expect ( document . querySelector ( '.rc-picker-range-arrow' ) ) . toHaveStyle ( {
1432
1450
'inset-inline-start' : '0' ,
1433
1451
} ) ;
1452
+ expect ( document . querySelector ( '.rc-picker-active-bar' ) ) . toHaveStyle ( {
1453
+ 'inset-inline-start' : '-2px' ,
1454
+ } ) ;
1455
+ window . getComputedStyle = oriGetComputedStyle ;
1434
1456
} ) ;
1435
1457
1436
1458
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', () => {
1450
1472
x : 300 ,
1451
1473
} ;
1452
1474
}
1475
+ if ( this . className . includes ( 'rc-picker-input' ) ) {
1476
+ return {
1477
+ ...rangeRect ,
1478
+ width : 100 ,
1479
+ } ;
1480
+ }
1453
1481
} ,
1454
1482
} ) ;
1455
1483
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
+
1456
1493
render ( < DayRangePicker open /> ) ;
1457
1494
1458
1495
await act ( async ( ) => {
@@ -1465,10 +1502,11 @@ describe('NewPicker.Range', () => {
1465
1502
} ) ;
1466
1503
1467
1504
expect ( document . querySelector ( '.rc-picker-active-bar' ) ) . toHaveStyle ( {
1468
- 'inset-inline-end' : '100px ' ,
1505
+ 'inset-inline-end' : '96px ' ,
1469
1506
} ) ;
1470
1507
1471
1508
mock . mockRestore ( ) ;
1509
+ window . getComputedStyle = oriGetComputedStyle ;
1472
1510
} ) ;
1473
1511
} ) ;
1474
1512
} ) ;
0 commit comments