@@ -16,7 +16,8 @@ describe('BeaconLrc', function() {
16
16
} ,
17
17
getAttribute : ( ) => 'hash1' ,
18
18
hasAttribute : ( ) => true ,
19
- dataset : { rocketLocationHash : 'hash1' }
19
+ dataset : { rocketLocationHash : 'hash1' } ,
20
+ children : [ ]
20
21
} ,
21
22
{
22
23
getBoundingClientRect : ( ) => {
@@ -26,7 +27,8 @@ describe('BeaconLrc', function() {
26
27
} ,
27
28
getAttribute : ( ) => 'hash2' ,
28
29
hasAttribute : ( ) => true ,
29
- dataset : { rocketLocationHash : 'hash2' }
30
+ dataset : { rocketLocationHash : 'hash2' } ,
31
+ children : [ ]
30
32
} ,
31
33
{
32
34
getBoundingClientRect : ( ) => {
@@ -36,7 +38,8 @@ describe('BeaconLrc', function() {
36
38
} ,
37
39
getAttribute : ( ) => 'hash3' ,
38
40
hasAttribute : ( ) => true ,
39
- dataset : { rocketLocationHash : 'hash3' }
41
+ dataset : { rocketLocationHash : 'hash3' } ,
42
+ children : [ ]
40
43
} ,
41
44
{
42
45
getBoundingClientRect : ( ) => {
@@ -46,7 +49,8 @@ describe('BeaconLrc', function() {
46
49
} ,
47
50
getAttribute : ( ) => 'hash4' ,
48
51
hasAttribute : ( ) => true ,
49
- dataset : { rocketLocationHash : 'hash4' }
52
+ dataset : { rocketLocationHash : 'hash4' } ,
53
+ children : [ ]
50
54
} ,
51
55
] ;
52
56
@@ -74,6 +78,18 @@ describe('BeaconLrc', function() {
74
78
75
79
// Mocking window.pageYOffset
76
80
global . window = { pageYOffset : 100 , innerHeight : 500 } ;
81
+
82
+ if ( typeof global . window . getComputedStyle !== 'function' ) {
83
+ global . window . getComputedStyle = ( ) => ( {
84
+ marginTop : '0px' ,
85
+ marginRight : '0px' ,
86
+ marginBottom : '0px' ,
87
+ marginLeft : '0px' ,
88
+ contentVisibility : 'visible' ,
89
+ position : 'static' ,
90
+ overflow : 'visible'
91
+ } ) ;
92
+ }
77
93
} ) ;
78
94
79
95
afterEach ( function ( ) {
@@ -232,4 +248,84 @@ describe('BeaconLrc', function() {
232
248
233
249
_getElementXPathStub . restore ( ) ;
234
250
} ) ;
251
+
252
+ it ( 'should detect conflict when element has negative margins' , ( ) => {
253
+ const element = mockElements [ 0 ] ;
254
+
255
+ sinon . stub ( window , 'getComputedStyle' ) . callsFake ( ( ) => ( {
256
+ marginTop : '-10px' ,
257
+ marginRight : '0px' ,
258
+ marginBottom : '0px' ,
259
+ marginLeft : '0px' ,
260
+ contentVisibility : 'visible' ,
261
+ position : 'static' ,
262
+ overflow : 'visible'
263
+ } ) ) ;
264
+
265
+ const result = beaconLrc . _checkLcrConflict ( element ) ;
266
+
267
+ assert . strictEqual ( result . length , 1 ) ;
268
+ assert . strictEqual ( result [ 0 ] . conflicts . includes ( 'negative margin' ) , true ) ;
269
+ window . getComputedStyle . restore ( ) ;
270
+ } ) ;
271
+
272
+ it ( 'should detect conflict when content visibility is hidden' , ( ) => {
273
+ const element = mockElements [ 0 ] ;
274
+
275
+ sinon . stub ( window , 'getComputedStyle' ) . callsFake ( ( ) => ( {
276
+ marginTop : '0px' ,
277
+ marginRight : '0px' ,
278
+ marginBottom : '0px' ,
279
+ marginLeft : '0px' ,
280
+ contentVisibility : 'hidden' ,
281
+ position : 'static' ,
282
+ overflow : 'visible'
283
+ } ) ) ;
284
+
285
+ const result = beaconLrc . _checkLcrConflict ( element ) ;
286
+
287
+ assert . strictEqual ( result . length , 1 ) ;
288
+ assert . strictEqual ( result [ 0 ] . conflicts . includes ( 'content-visibility:hidden' ) , true ) ;
289
+ window . getComputedStyle . restore ( ) ;
290
+ } ) ;
291
+
292
+ it ( 'should detect conflict when child has negative margins' , ( ) => {
293
+ const element = mockElements [ 0 ] ;
294
+
295
+ const child = {
296
+ getBoundingClientRect : ( ) => ( { top : 500 } ) ,
297
+ getAttribute : ( ) => null ,
298
+ hasAttribute : ( ) => false ,
299
+ children : [ ]
300
+ } ;
301
+ element . children = [ child ] ;
302
+
303
+ sinon . stub ( window , 'getComputedStyle' )
304
+ . onCall ( 0 ) . returns ( {
305
+ marginTop : '0px' ,
306
+ marginRight : '0px' ,
307
+ marginBottom : '0px' ,
308
+ marginLeft : '0px' ,
309
+ contentVisibility : 'visible' ,
310
+ position : 'static' ,
311
+ overflow : 'visible'
312
+ } )
313
+ . onCall ( 1 ) . returns ( {
314
+ marginTop : '-20px' ,
315
+ marginRight : '0px' ,
316
+ marginBottom : '0px' ,
317
+ marginLeft : '0px' ,
318
+ contentVisibility : 'visible' ,
319
+ position : 'absolute' ,
320
+ overflow : 'visible'
321
+ } ) ;
322
+
323
+ const result = beaconLrc . _checkLcrConflict ( element ) ;
324
+
325
+ assert . strictEqual ( result . length , 1 ) ;
326
+ assert . strictEqual ( result [ 0 ] . element , child ) ;
327
+ assert . strictEqual ( result [ 0 ] . conflicts . includes ( 'negative margin' ) , true ) ;
328
+
329
+ window . getComputedStyle . restore ( ) ;
330
+ } )
235
331
} ) ;
0 commit comments