1
1
/* eslint-disable react/no-multi-comp */
2
- import React , { Component } from "react" ;
2
+ import React , { Component } from "react" ;
3
3
import PropTypes from "prop-types" ;
4
4
import ReactTestUtils from "react-dom/test-utils" ;
5
5
import ShallowRenderer from "react-test-renderer/shallow" ;
6
6
import Bling from "../src/Bling" ;
7
7
import Events from "../src/Events" ;
8
- import { pubadsAPI , APIToCallBeforeServiceEnabled } from "../src/createManager" ;
9
- import { gptVersion , pubadsVersion } from "../src/utils/apiList" ;
10
- import { createManagerTest } from "../src/utils/createManagerTest" ;
8
+ import { pubadsAPI , APIToCallBeforeServiceEnabled } from "../src/createManager" ;
9
+ import { gptVersion , pubadsVersion } from "../src/utils/apiList" ;
10
+ import { createManagerTest } from "../src/utils/createManagerTest" ;
11
11
12
12
describe ( "Bling" , ( ) => {
13
13
let googletag ;
14
14
const stubs = [ ] ;
15
15
16
16
beforeEach ( ( ) => {
17
- Bling . configure ( { renderWhenViewable : false } ) ;
17
+ Bling . configure ( { renderWhenViewable : false } ) ;
18
18
Bling . testManager = createManagerTest ( ) ;
19
19
googletag = Bling . _adManager . googletag ;
20
20
} ) ;
@@ -43,7 +43,27 @@ describe("Bling", () => {
43
43
) ;
44
44
const result = renderer . getRenderOutput ( ) ;
45
45
expect ( result . type ) . to . equal ( "div" ) ;
46
- expect ( result . props . style ) . to . eql ( { width : 728 , height : 90 } ) ;
46
+ expect ( result . props . style ) . to . eql ( { width : 728 , height : 90 } ) ;
47
+ } ) ;
48
+
49
+ it ( "renders fluid to auto width and height" , ( ) => {
50
+ const renderer = new ShallowRenderer ( ) ;
51
+ renderer . render (
52
+ < Bling adUnitPath = "/4595/nfl.test.open" slotSize = { "fluid" } />
53
+ ) ;
54
+ const result = renderer . getRenderOutput ( ) ;
55
+ expect ( result . type ) . to . equal ( "div" ) ;
56
+ expect ( result . props . style ) . to . eql ( { width : "auto" , height : "auto" } ) ;
57
+ } ) ;
58
+
59
+ it ( "renders ['fluid'] to auto width and height" , ( ) => {
60
+ const renderer = new ShallowRenderer ( ) ;
61
+ renderer . render (
62
+ < Bling adUnitPath = "/4595/nfl.test.open" slotSize = { [ "fluid" ] } />
63
+ ) ;
64
+ const result = renderer . getRenderOutput ( ) ;
65
+ expect ( result . type ) . to . equal ( "div" ) ;
66
+ expect ( result . props . style ) . to . eql ( { width : "auto" , height : "auto" } ) ;
47
67
} ) ;
48
68
49
69
it ( "returns gpt version" , done => {
@@ -239,7 +259,7 @@ describe("Bling", () => {
239
259
240
260
it ( "calls getServices on adSlot on clear" , ( ) => {
241
261
const instance = new Bling ( ) ;
242
- const adSlot = sinon . mock ( { getServices : ( ) => { } } ) ;
262
+ const adSlot = sinon . mock ( { getServices : ( ) => { } } ) ;
243
263
adSlot . expects ( "getServices" ) . once ( ) ;
244
264
instance . _adSlot = adSlot ;
245
265
instance . clear ( ) ;
@@ -296,16 +316,16 @@ describe("Bling", () => {
296
316
< Bling
297
317
adUnitPath = "/4595/nfl.test.open"
298
318
sizeMapping = { [
299
- { viewport : [ 0 , 0 ] , slot : [ 320 , 50 ] } ,
300
- { viewport : [ 750 , 200 ] , slot : [ 728 , 90 ] } ,
301
- { viewport : [ 1050 , 200 ] , slot : [ 1024 , 120 ] }
319
+ { viewport : [ 0 , 0 ] , slot : [ 320 , 50 ] } ,
320
+ { viewport : [ 750 , 200 ] , slot : [ 728 , 90 ] } ,
321
+ { viewport : [ 1050 , 200 ] , slot : [ 1024 , 120 ] }
302
322
] }
303
323
/>
304
324
) ;
305
325
} ) ;
306
326
307
327
it ( "reflects targeting props to adSlot" , done => {
308
- const targeting = { t1 : "v1" , t2 : [ 1 , 2 , 3 ] } ;
328
+ const targeting = { t1 : "v1" , t2 : [ 1 , 2 , 3 ] } ;
309
329
310
330
Bling . once ( Events . RENDER , ( ) => {
311
331
const adSlot = instance . adSlot ;
@@ -372,7 +392,7 @@ describe("Bling", () => {
372
392
const instance = ReactTestUtils . renderIntoDocument (
373
393
< Bling
374
394
adUnitPath = "/4595/nfl.test.open"
375
- attributes = { { attr1 : "val1" , attr2 : "val2" } }
395
+ attributes = { { attr1 : "val1" , attr2 : "val2" } }
376
396
slotSize = { [ 300 , 250 ] }
377
397
/>
378
398
) ;
@@ -575,20 +595,53 @@ describe("Bling", () => {
575
595
) ;
576
596
} ) ;
577
597
598
+ it ( "renders slotSize with an array" , ( ) => {
599
+ const renderer = new ShallowRenderer ( ) ;
600
+ renderer . render (
601
+ < Bling adUnitPath = "/4595/nfl.test.open" slotSize = { [ [ 300 , 250 ] ] } />
602
+ ) ;
603
+ const result = renderer . getRenderOutput ( ) ;
604
+ expect ( result . type ) . to . equal ( "div" ) ;
605
+ expect ( result . props . style ) . to . eql ( { width : 300 , height : 250 } ) ;
606
+ } ) ;
607
+
608
+ it ( "sets slotSize to 0,0 on foldCheck of 'fluid' or ['fluid']" , done => {
609
+ const isInViewport = sinon . spy ( Bling . _adManager , "isInViewport" ) ;
610
+
611
+ class Wrapper extends Component {
612
+ onSlotRenderEnded = ( ) => {
613
+ expect ( isInViewport . args [ 0 ] [ 1 ] . join ( ) ) . to . equal ( [ 0 , 0 ] . join ( ) ) ;
614
+ done ( ) ;
615
+ } ;
616
+ render ( ) {
617
+ return (
618
+ < Bling
619
+ adUnitPath = "/4595/nfl.test.open"
620
+ renderWhenViewable = { true }
621
+ slotSize = { [ "fluid" ] }
622
+ onSlotRenderEnded = { this . onSlotRenderEnded }
623
+ />
624
+ ) ;
625
+ }
626
+ }
627
+
628
+ ReactTestUtils . renderIntoDocument ( < Wrapper /> ) ;
629
+ } ) ;
630
+
578
631
it ( "refreshes ad when refreshable prop changes" , done => {
579
632
let count = 0 ;
580
633
581
634
Bling . syncCorrelator ( ) ;
582
635
583
636
class Wrapper extends Component {
584
637
state = {
585
- targeting : { prop : "val" }
638
+ targeting : { prop : "val" }
586
639
} ;
587
640
onSlotRenderEnded = event => {
588
641
if ( count === 0 ) {
589
642
expect ( event . slot . getTargeting ( "prop" ) ) . to . equal ( "val" ) ;
590
643
this . setState ( {
591
- targeting : { prop : "val2" }
644
+ targeting : { prop : "val2" }
592
645
} ) ;
593
646
count ++ ;
594
647
} else {
@@ -597,7 +650,7 @@ describe("Bling", () => {
597
650
}
598
651
} ;
599
652
render ( ) {
600
- const { targeting} = this . state ;
653
+ const { targeting } = this . state ;
601
654
return (
602
655
< Bling
603
656
adUnitPath = "/4595/nfl.test.open"
@@ -619,13 +672,13 @@ describe("Bling", () => {
619
672
620
673
class Wrapper extends Component {
621
674
state = {
622
- targeting : { prop : "val" }
675
+ targeting : { prop : "val" }
623
676
} ;
624
677
onSlotRenderEnded = event => {
625
678
if ( count === 0 ) {
626
679
expect ( event . slot . getTargeting ( "prop" ) ) . to . equal ( "val" ) ;
627
680
this . setState ( {
628
- targeting : { prop : "val2" }
681
+ targeting : { prop : "val2" }
629
682
} ) ;
630
683
count ++ ;
631
684
} else {
@@ -634,7 +687,7 @@ describe("Bling", () => {
634
687
}
635
688
} ;
636
689
render ( ) {
637
- const { targeting} = this . state ;
690
+ const { targeting } = this . state ;
638
691
return (
639
692
< Bling
640
693
adUnitPath = "/4595/nfl.test.open"
@@ -675,7 +728,7 @@ describe("Bling", () => {
675
728
}
676
729
} ;
677
730
render ( ) {
678
- const { adUnitPath} = this . state ;
731
+ const { adUnitPath } = this . state ;
679
732
return (
680
733
< Bling
681
734
adUnitPath = { adUnitPath }
0 commit comments