11import globalReset from '../utils/global-reset' ;
2+ import { createMessageWidget } from '../utils/test-helpers' ;
23
3- // -------------------------
4- // A/B TESTING
5- // -------------------------
6- describe ( 'when performing AB testing' , function ( ) {
4+ describe ( 'a/b testing' , function ( ) {
75 beforeEach ( function ( ) {
86 globalReset ( ) ;
97 } ) ;
108
119 it ( 'should select only one A/B Test group to show' , function ( ) {
12- var widgetA = new pathfora . Message ( {
10+ var widgetA = createMessageWidget ( {
1311 id : 'ab-widget1-a' ,
1412 msg : 'A' ,
15- layout : 'slideout'
13+ layout : 'slideout' ,
1614 } ) ;
1715
18- var widgetB = new pathfora . Message ( {
16+ var widgetB = createMessageWidget ( {
1917 id : 'ab-widget1-b' ,
2018 msg : 'B' ,
21- layout : 'slideout'
19+ layout : 'slideout' ,
2220 } ) ;
2321
2422 var ab = new pathfora . ABTest ( {
2523 id : 'ab-1' ,
2624 type : '50/50' ,
27- groups : [ [ widgetA ] , [ widgetB ] ]
25+ groups : [ [ widgetA ] , [ widgetB ] ] ,
2826 } ) ;
2927
3028 pathfora . initializeABTesting ( [ ab ] ) ;
@@ -35,34 +33,37 @@ describe('when performing AB testing', function () {
3533 } ) ;
3634
3735 it ( 'should show all widgets in an A/B test group' , function ( ) {
38- var widget1A = new pathfora . Message ( {
36+ var widget1A = createMessageWidget ( {
3937 id : 'ab-widget2-1a' ,
4038 msg : 'A' ,
41- layout : 'slideout'
39+ layout : 'slideout' ,
4240 } ) ;
4341
44- var widget2A = new pathfora . Message ( {
42+ var widget2A = createMessageWidget ( {
4543 id : 'ab-widget2-2a' ,
4644 msg : 'A' ,
47- layout : 'slideout'
45+ layout : 'slideout' ,
4846 } ) ;
4947
50- var widget1B = new pathfora . Message ( {
48+ var widget1B = createMessageWidget ( {
5149 id : 'ab-widget2-1b' ,
5250 msg : 'B' ,
53- layout : 'slideout'
51+ layout : 'slideout' ,
5452 } ) ;
5553
56- var widget2B = new pathfora . Message ( {
54+ var widget2B = createMessageWidget ( {
5755 id : 'ab-widget2-2b' ,
5856 msg : 'B' ,
59- layout : 'slideout'
57+ layout : 'slideout' ,
6058 } ) ;
6159
6260 var ab = new pathfora . ABTest ( {
6361 id : 'ab-2' ,
6462 type : '50/50' ,
65- groups : [ [ widget1A , widget2A ] , [ widget1B , widget2B ] ]
63+ groups : [
64+ [ widget1A , widget2A ] ,
65+ [ widget1B , widget2B ] ,
66+ ] ,
6667 } ) ;
6768
6869 pathfora . initializeABTesting ( [ ab ] ) ;
@@ -73,10 +74,7 @@ describe('when performing AB testing', function () {
7374
7475 var first = w . first ( ) ;
7576 expect ( first . find ( '.pf-widget-message' ) . text ( ) ) . toEqual (
76- first
77- . next ( )
78- . find ( '.pf-widget-message' )
79- . text ( )
77+ first . next ( ) . find ( '.pf-widget-message' ) . text ( )
8078 ) ;
8179 } ) ;
8280
@@ -85,29 +83,29 @@ describe('when performing AB testing', function () {
8583
8684 pathfora . utils . write ( 'PathforaTest_' + id , 0.2164252290967852 ) ;
8785
88- var widgetA = new pathfora . Message ( {
86+ var widgetA = createMessageWidget ( {
8987 id : 'ab-widget3-a' ,
9088 msg : 'A' ,
91- layout : 'modal'
89+ layout : 'modal' ,
9290 } ) ;
9391
94- var widgetB = new pathfora . Message ( {
92+ var widgetB = createMessageWidget ( {
9593 id : 'ab-widget3-b' ,
9694 msg : 'B' ,
97- layout : 'modal'
95+ layout : 'modal' ,
9896 } ) ;
9997
10098 var ab = new pathfora . ABTest ( {
10199 id : id ,
102100 type : '50/50' ,
103- groups : [ [ widgetA ] , [ widgetB ] ]
101+ groups : [ [ widgetA ] , [ widgetB ] ] ,
104102 } ) ;
105103
106104 pathfora . initializeABTesting ( [ ab ] ) ;
107105 pathfora . initializeWidgets ( [ widgetA , widgetB ] ) ;
108106
109107 var wB = $ ( '#' + widgetB . id ) ,
110- wA = $ ( '#' + widgetA . id ) ;
108+ wA = $ ( '#' + widgetA . id ) ;
111109 expect ( wB . length ) . toBe ( 1 ) ;
112110 expect ( wA . length ) . toBe ( 0 ) ;
113111 } ) ;
@@ -116,77 +114,77 @@ describe('when performing AB testing', function () {
116114 var id = 'ab-4' ;
117115 pathfora . utils . saveCookie ( 'PathforaTest_' + id , 0.7077720651868731 ) ;
118116
119- var widgetA = new pathfora . Message ( {
117+ var widgetA = createMessageWidget ( {
120118 id : 'ab-widget4-a' ,
121119 msg : 'A' ,
122- layout : 'modal'
120+ layout : 'modal' ,
123121 } ) ;
124122
125- var widgetB = new pathfora . Message ( {
123+ var widgetB = createMessageWidget ( {
126124 id : 'ab-widget4-b' ,
127125 msg : 'B' ,
128- layout : 'modal'
126+ layout : 'modal' ,
129127 } ) ;
130128
131129 var ab = new pathfora . ABTest ( {
132130 id : id ,
133131 type : '50/50' ,
134- groups : [ [ widgetA ] , [ widgetB ] ]
132+ groups : [ [ widgetA ] , [ widgetB ] ] ,
135133 } ) ;
136134
137135 pathfora . initializeABTesting ( [ ab ] ) ;
138136 pathfora . initializeWidgets ( [ widgetA , widgetB ] ) ;
139137
140138 var wB = $ ( '#' + widgetB . id ) ,
141- wA = $ ( '#' + widgetA . id ) ;
139+ wA = $ ( '#' + widgetA . id ) ;
142140
143141 expect ( wA . length ) . toBe ( 1 ) ;
144142 expect ( wB . length ) . toBe ( 0 ) ;
145143 } ) ;
146144
147145 it ( 'should allow multiple A/B tests per page' , function ( ) {
148- var widgetA = new pathfora . Message ( {
146+ var widgetA = createMessageWidget ( {
149147 id : 'ab-widget5-a' ,
150148 msg : 'A' ,
151- layout : 'modal'
149+ layout : 'modal' ,
152150 } ) ;
153151
154- var widgetB = new pathfora . Message ( {
152+ var widgetB = createMessageWidget ( {
155153 id : 'ab-widget5-b' ,
156154 msg : 'B' ,
157- layout : 'modal'
155+ layout : 'modal' ,
158156 } ) ;
159157
160158 var ab = new pathfora . ABTest ( {
161159 id : 'ab-5' ,
162160 type : '50/50' ,
163- groups : [ [ widgetA ] , [ widgetB ] ]
161+ groups : [ [ widgetA ] , [ widgetB ] ] ,
164162 } ) ;
165163
166- var widgetC = new pathfora . Message ( {
164+ var widgetC = createMessageWidget ( {
167165 id : 'ab-widget6-c' ,
168166 msg : 'C' ,
169- layout : 'modal'
167+ layout : 'modal' ,
170168 } ) ;
171169
172- var widgetD = new pathfora . Message ( {
170+ var widgetD = createMessageWidget ( {
173171 id : 'ab-widget6-d' ,
174172 msg : 'D' ,
175- layout : 'modal'
173+ layout : 'modal' ,
176174 } ) ;
177175
178176 var ab2 = new pathfora . ABTest ( {
179177 id : 'ab-6' ,
180178 type : '50/50' ,
181- groups : [ [ widgetC ] , [ widgetD ] ]
179+ groups : [ [ widgetC ] , [ widgetD ] ] ,
182180 } ) ;
183181
184182 pathfora . initializeABTesting ( [ ab , ab2 ] ) ;
185183 pathfora . initializeWidgets ( [ widgetA , widgetB , widgetC , widgetD ] ) ;
186184
187185 var w = $ ( '[id*="ab-widget"]' ) ,
188- w5 = $ ( '[id*="ab-widget5"]' ) ,
189- w6 = $ ( '[id*="ab-widget6"]' ) ;
186+ w5 = $ ( '[id*="ab-widget5"]' ) ,
187+ w6 = $ ( '[id*="ab-widget6"]' ) ;
190188
191189 expect ( w . length ) . toBe ( 2 ) ;
192190 expect ( w5 . length ) . toBe ( 1 ) ;
@@ -196,40 +194,40 @@ describe('when performing AB testing', function () {
196194 it ( 'should handle A/B Tests in conjunction with audience targeting' , function ( ) {
197195 window . lio = {
198196 data : {
199- segments : [ 'all' , 'smt_new' ]
197+ segments : [ 'all' , 'smt_new' ] ,
200198 } ,
201199 account : {
202- id : '0'
203- }
200+ id : '0' ,
201+ } ,
204202 } ;
205203
206204 window . lio . loaded = true ;
207205
208- var widgetA = new pathfora . Message ( {
206+ var widgetA = createMessageWidget ( {
209207 id : 'ab-widget10-a' ,
210208 layout : 'slideout' ,
211- msg : 'A'
209+ msg : 'A' ,
212210 } ) ;
213211
214- var widgetB = new pathfora . Message ( {
212+ var widgetB = createMessageWidget ( {
215213 id : 'ab-widget10-b' ,
216214 layout : 'slideout' ,
217- msg : 'B'
215+ msg : 'B' ,
218216 } ) ;
219217
220218 var ab = new pathfora . ABTest ( {
221219 id : 'ab-10' ,
222220 type : '50/50' ,
223- groups : [ [ widgetA ] , [ widgetB ] ]
221+ groups : [ [ widgetA ] , [ widgetB ] ] ,
224222 } ) ;
225223
226224 var widgets = {
227225 target : [
228226 {
229227 segment : 'smt_new' ,
230- widgets : [ widgetA , widgetB ]
231- }
232- ]
228+ widgets : [ widgetA , widgetB ] ,
229+ } ,
230+ ] ,
233231 } ;
234232
235233 pathfora . initializeABTesting ( [ ab ] ) ;
@@ -243,16 +241,16 @@ describe('when performing AB testing', function () {
243241 var id = 'ab-11' ;
244242 pathfora . utils . saveCookie ( 'PathforaTest_' + id , 0.7077720651868731 ) ;
245243
246- var widget = new pathfora . Message ( {
244+ var widget = createMessageWidget ( {
247245 id : 'ab-widget11-a' ,
248246 msg : 'A' ,
249- layout : 'slideout'
247+ layout : 'slideout' ,
250248 } ) ;
251249
252250 var ab = new pathfora . ABTest ( {
253251 id : 'ab-11' ,
254252 type : '80/20' ,
255- groups : [ [ ] , [ widget ] ]
253+ groups : [ [ ] , [ widget ] ] ,
256254 } ) ;
257255
258256 pathfora . initializeABTesting ( [ ab ] ) ;
@@ -263,22 +261,22 @@ describe('when performing AB testing', function () {
263261 } ) ;
264262
265263 it ( 'should not allow a widget to be used in more than one A/B test' , function ( ) {
266- var widgetA = new pathfora . Message ( {
264+ var widgetA = createMessageWidget ( {
267265 id : 'ab-widget8-a' ,
268266 msg : 'A' ,
269- layout : 'slideout'
267+ layout : 'slideout' ,
270268 } ) ;
271269
272270 var ab = new pathfora . ABTest ( {
273271 id : 'ab-7' ,
274272 type : '50/50' ,
275- groups : [ [ widgetA ] , [ ] ]
273+ groups : [ [ widgetA ] , [ ] ] ,
276274 } ) ;
277275
278276 var ab2 = new pathfora . ABTest ( {
279277 id : 'ab-8' ,
280278 type : '50/50' ,
281- groups : [ [ widgetA ] , [ ] ]
279+ groups : [ [ widgetA ] , [ ] ] ,
282280 } ) ;
283281
284282 expect ( function ( ) {
@@ -291,28 +289,28 @@ describe('when performing AB testing', function () {
291289 } ) ;
292290
293291 it ( 'should not allow a widget to be used in more than one A/B test' , function ( ) {
294- var widgetA = new pathfora . Message ( {
292+ var widgetA = createMessageWidget ( {
295293 id : 'ab-widget9-a' ,
296294 msg : 'A' ,
297- layout : 'slideout'
295+ layout : 'slideout' ,
298296 } ) ;
299297
300- var widgetB = new pathfora . Message ( {
298+ var widgetB = createMessageWidget ( {
301299 id : 'ab-widget9-b' ,
302300 msg : 'B' ,
303- layout : 'slideout'
301+ layout : 'slideout' ,
304302 } ) ;
305303
306304 var ab = new pathfora . ABTest ( {
307305 id : 'ab-9' ,
308306 type : '50/50' ,
309- groups : [ [ widgetA ] , [ ] ]
307+ groups : [ [ widgetA ] , [ ] ] ,
310308 } ) ;
311309
312310 var ab2 = new pathfora . ABTest ( {
313311 id : 'ab-9' ,
314312 type : '50/50' ,
315- groups : [ [ widgetB ] , [ ] ]
313+ groups : [ [ widgetB ] , [ ] ] ,
316314 } ) ;
317315
318316 expect ( function ( ) {
0 commit comments