@@ -12,6 +12,70 @@ const config = require('../../data/extension-config.json');
1212let tab ;
1313
1414describe ( 'Tab' , ( ) => {
15+ describe ( 'initExperiments()' , ( ) => {
16+ it ( 'should skip experiments without cohorts' , ( ) => {
17+ const mockAbnMetrics = {
18+ automaticallyEnrollCurrentContentScopeExperiments : jasmine . createSpy ( 'automaticallyEnrollCurrentContentScopeExperiments' ) ,
19+ getCurrentCohorts : jasmine . createSpy ( 'getCurrentCohorts' ) . and . returnValue ( [
20+ { feature : 'contentScopeExperiments' , subfeature : 'feature1' , cohort : 'treatment' } ,
21+ { feature : 'contentScopeExperiments' , subfeature : 'feature2' , cohort : null } ,
22+ { feature : 'contentScopeExperiments' , subfeature : 'feature3' , cohort : 'control' } ,
23+ { feature : 'contentScopeExperiments' , subfeature : 'feature4' , cohort : undefined } ,
24+ ] ) ,
25+ } ;
26+
27+ tab = new Tab (
28+ {
29+ id : 123 ,
30+ requestId : 123 ,
31+ url : 'http://example.com' ,
32+ status : 200 ,
33+ } ,
34+ mockAbnMetrics ,
35+ ) ;
36+
37+ expect ( mockAbnMetrics . automaticallyEnrollCurrentContentScopeExperiments ) . toHaveBeenCalled ( ) ;
38+ expect ( mockAbnMetrics . getCurrentCohorts ) . toHaveBeenCalled ( ) ;
39+ expect ( tab . contentScopeExperiments ) . toEqual ( {
40+ feature1 : 'treatment' ,
41+ feature3 : 'control' ,
42+ } ) ;
43+ } ) ;
44+
45+ it ( 'should handle empty experiments array' , ( ) => {
46+ const mockAbnMetrics = {
47+ automaticallyEnrollCurrentContentScopeExperiments : jasmine . createSpy ( 'automaticallyEnrollCurrentContentScopeExperiments' ) ,
48+ getCurrentCohorts : jasmine . createSpy ( 'getCurrentCohorts' ) . and . returnValue ( [ ] ) ,
49+ } ;
50+
51+ tab = new Tab (
52+ {
53+ id : 123 ,
54+ requestId : 123 ,
55+ url : 'http://example.com' ,
56+ status : 200 ,
57+ } ,
58+ mockAbnMetrics ,
59+ ) ;
60+
61+ expect ( tab . contentScopeExperiments ) . toEqual ( { } ) ;
62+ } ) ;
63+
64+ it ( 'should handle null abnMetrics' , ( ) => {
65+ tab = new Tab (
66+ {
67+ id : 123 ,
68+ requestId : 123 ,
69+ url : 'http://example.com' ,
70+ status : 200 ,
71+ } ,
72+ null ,
73+ ) ;
74+
75+ expect ( tab . contentScopeExperiments ) . toEqual ( { } ) ;
76+ } ) ;
77+ } ) ;
78+
1579 describe ( 'updateSite()' , ( ) => {
1680 beforeEach ( ( ) => {
1781 tab = new Tab ( {
0 commit comments