@@ -29,6 +29,7 @@ describe('module:request', function() {
29
29
// can not spy on imagePing. spy on appendChild instead.
30
30
spyOn ( document . body , 'appendChild' ) ;
31
31
spyOn ( document . body , 'removeChild' ) ;
32
+ spyOn ( localStorage , 'getItem' ) . and . returnValue ( null ) ;
32
33
} ) ;
33
34
34
35
it ( 'should call appendChild' , function ( done ) {
@@ -51,4 +52,46 @@ describe('module:request', function() {
51
52
} , 1500 ) ;
52
53
} ) ;
53
54
} ) ;
55
+
56
+ describe ( 'sendHostname with localstorage' , function ( ) {
57
+ beforeEach ( function ( ) {
58
+ window . tui = window . tui || { } ;
59
+
60
+ // can not spy on imagePing. spy on appendChild instead.
61
+ spyOn ( document . body , 'appendChild' ) ;
62
+ spyOn ( document . body , 'removeChild' ) ;
63
+ } ) ;
64
+
65
+ it ( 'should not call appendChild within 7 days' , function ( done ) {
66
+ var now = new Date ( ) . getTime ( ) ;
67
+ var ms6days = 6 * 24 * 60 * 60 * 1000 ;
68
+
69
+ spyOn ( localStorage , 'getItem' ) . and . returnValue ( now - ms6days ) ;
70
+
71
+ window . tui . usageStatistics = true ;
72
+
73
+ request . sendHostname ( 'editor' ) ;
74
+
75
+ setTimeout ( function ( ) {
76
+ expect ( document . body . appendChild ) . not . toHaveBeenCalled ( ) ;
77
+ done ( ) ;
78
+ } , 1500 ) ;
79
+ } ) ;
80
+
81
+ it ( 'should call appendChild after 7 days' , function ( done ) {
82
+ var now = new Date ( ) . getTime ( ) ;
83
+ var ms8days = 8 * 24 * 60 * 60 * 1000 ;
84
+
85
+ spyOn ( localStorage , 'getItem' ) . and . returnValue ( now - ms8days ) ;
86
+
87
+ window . tui . usageStatistics = true ;
88
+
89
+ request . sendHostname ( 'editor' ) ;
90
+
91
+ setTimeout ( function ( ) {
92
+ expect ( document . body . appendChild ) . toHaveBeenCalled ( ) ;
93
+ done ( ) ;
94
+ } , 1500 ) ;
95
+ } ) ;
96
+ } ) ;
54
97
} ) ;
0 commit comments