@@ -5,12 +5,12 @@ describe('hx-push-url attribute', function() {
55 beforeEach ( function ( ) {
66 this . server = makeServer ( )
77 clearWorkArea ( )
8- localStorage . removeItem ( HTMX_HISTORY_CACHE_NAME )
8+ sessionStorage . removeItem ( HTMX_HISTORY_CACHE_NAME )
99 } )
1010 afterEach ( function ( ) {
1111 this . server . restore ( )
1212 clearWorkArea ( )
13- localStorage . removeItem ( HTMX_HISTORY_CACHE_NAME )
13+ sessionStorage . removeItem ( HTMX_HISTORY_CACHE_NAME )
1414 } )
1515
1616 it ( 'navigation should push an element into the cache when true' , function ( ) {
@@ -22,7 +22,7 @@ describe('hx-push-url attribute', function() {
2222 div . click ( )
2323 this . server . respond ( )
2424 getWorkArea ( ) . textContent . should . equal ( 'second' )
25- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
25+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
2626 cache [ cache . length - 1 ] . url . should . equal ( '/test' )
2727 } )
2828
@@ -35,7 +35,7 @@ describe('hx-push-url attribute', function() {
3535 div . click ( )
3636 this . server . respond ( )
3737 getWorkArea ( ) . textContent . should . equal ( 'second' )
38- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
38+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
3939 should . equal ( cache , null )
4040 } )
4141
@@ -48,7 +48,7 @@ describe('hx-push-url attribute', function() {
4848 div . click ( )
4949 this . server . respond ( )
5050 getWorkArea ( ) . textContent . should . equal ( 'second' )
51- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
51+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
5252 cache . length . should . equal ( 2 )
5353 cache [ 1 ] . url . should . equal ( '/abc123' )
5454 } )
@@ -68,7 +68,7 @@ describe('hx-push-url attribute', function() {
6868 this . server . respond ( )
6969 workArea . textContent . should . equal ( 'test2' )
7070
71- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
71+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
7272
7373 cache . length . should . equal ( 2 )
7474 htmx . _ ( 'restoreHistory' ) ( '/test1' )
@@ -106,7 +106,7 @@ describe('hx-push-url attribute', function() {
106106 byId ( 'd1' ) . click ( )
107107 this . server . respond ( )
108108 }
109- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
109+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
110110 cache . length . should . equal ( 10 ) // should only be 10 elements
111111 } )
112112
@@ -125,10 +125,10 @@ describe('hx-push-url attribute', function() {
125125 this . server . respond ( )
126126 workArea . textContent . should . equal ( 'test2' )
127127
128- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
128+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
129129
130130 cache . length . should . equal ( 2 )
131- localStorage . removeItem ( HTMX_HISTORY_CACHE_NAME ) // clear cache
131+ sessionStorage . removeItem ( HTMX_HISTORY_CACHE_NAME ) // clear cache
132132 htmx . _ ( 'restoreHistory' ) ( '/test1' )
133133 this . server . respond ( )
134134 getWorkArea ( ) . textContent . should . equal ( 'test1' )
@@ -138,7 +138,7 @@ describe('hx-push-url attribute', function() {
138138 htmx . config . refreshOnHistoryMiss = true
139139 var refresh = false
140140 htmx . location = { reload : function ( ) { refresh = true } }
141- localStorage . removeItem ( HTMX_HISTORY_CACHE_NAME ) // clear cache
141+ sessionStorage . removeItem ( HTMX_HISTORY_CACHE_NAME ) // clear cache
142142 htmx . _ ( 'restoreHistory' ) ( '/test3' )
143143 refresh . should . equal ( true )
144144 htmx . location = window . location
@@ -152,20 +152,20 @@ describe('hx-push-url attribute', function() {
152152 div . click ( )
153153 this . server . respond ( )
154154 getWorkArea ( ) . textContent . should . equal ( 'second' )
155- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
155+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
156156 cache . length . should . equal ( 1 )
157157 } )
158158
159159 it ( 'deals with malformed JSON in history cache when getting' , function ( ) {
160- localStorage . setItem ( HTMX_HISTORY_CACHE_NAME , 'Invalid JSON' )
160+ sessionStorage . setItem ( HTMX_HISTORY_CACHE_NAME , 'Invalid JSON' )
161161 var history = htmx . _ ( 'getCachedHistory' ) ( 'url' )
162162 should . equal ( history , null )
163163 } )
164164
165165 it ( 'deals with malformed JSON in history cache when saving' , function ( ) {
166- localStorage . setItem ( HTMX_HISTORY_CACHE_NAME , 'Invalid JSON' )
166+ sessionStorage . setItem ( HTMX_HISTORY_CACHE_NAME , 'Invalid JSON' )
167167 htmx . _ ( 'saveToHistoryCache' ) ( 'url' , make ( '<div>' ) )
168- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
168+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
169169 cache . length . should . equal ( 1 )
170170 } )
171171
@@ -174,17 +174,17 @@ describe('hx-push-url attribute', function() {
174174 htmx . _ ( 'saveToHistoryCache' ) ( 'url2' , make ( '<div>' ) )
175175 htmx . _ ( 'saveToHistoryCache' ) ( 'url3' , make ( '<div>' ) )
176176 htmx . _ ( 'saveToHistoryCache' ) ( 'url2' , make ( '<div>' ) )
177- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
177+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
178178 cache . length . should . equal ( 3 )
179179 } )
180180
181181 it ( 'setting history cache size to 0 clears cache' , function ( ) {
182182 htmx . _ ( 'saveToHistoryCache' ) ( 'url1' , make ( '<div>' ) )
183- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
183+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
184184 cache . length . should . equal ( 1 )
185185 htmx . config . historyCacheSize = 0
186186 htmx . _ ( 'saveToHistoryCache' ) ( 'url2' , make ( '<div>' ) )
187- cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
187+ cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
188188 should . equal ( cache , null )
189189 htmx . config . historyCacheSize = 10
190190 } )
@@ -195,7 +195,7 @@ describe('hx-push-url attribute', function() {
195195 htmx . _ ( 'saveToHistoryCache' ) ( 'url3' , make ( '<div>' ) )
196196 htmx . _ ( 'saveToHistoryCache' ) ( 'url2' , make ( '<div>' ) )
197197 htmx . _ ( 'saveToHistoryCache' ) ( 'url1' , make ( '<div>' ) )
198- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
198+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
199199 cache . length . should . equal ( 3 )
200200 cache [ 0 ] . url . should . equal ( '/url3' )
201201 cache [ 1 ] . url . should . equal ( '/url2' )
@@ -246,19 +246,19 @@ describe('hx-push-url attribute', function() {
246246 bigContent += bigContent
247247 }
248248 try {
249- localStorage . removeItem ( 'htmx-history-cache' )
249+ sessionStorage . removeItem ( 'htmx-history-cache' )
250250 htmx . _ ( 'saveToHistoryCache' ) ( '/dummy' , make ( '<div>' + bigContent + '</div>' ) , 'Foo' , 0 )
251- should . equal ( localStorage . getItem ( 'htmx-history-cache' ) , null )
251+ should . equal ( sessionStorage . getItem ( 'htmx-history-cache' ) , null )
252252 } finally {
253253 // clear history cache afterwards
254- localStorage . removeItem ( 'htmx-history-cache' )
254+ sessionStorage . removeItem ( 'htmx-history-cache' )
255255 }
256256 } )
257257
258258 if ( / c h r o m e / i. test ( navigator . userAgent ) ) {
259- it ( 'when localStorage disabled history not saved fine' , function ( ) {
260- var setItem = localStorage . setItem
261- localStorage . setItem = undefined
259+ it ( 'when sessionStorage disabled history not saved fine' , function ( ) {
260+ var setItem = sessionStorage . setItem
261+ sessionStorage . setItem = undefined
262262 this . server . respondWith ( 'GET' , '/test' , 'second' )
263263 getWorkArea ( ) . innerHTML . should . be . equal ( '' )
264264 var div = make ( '<div hx-push-url="true" hx-get="/test">first</div>' )
@@ -269,23 +269,23 @@ describe('hx-push-url attribute', function() {
269269 getWorkArea ( ) . textContent . should . equal ( 'second' )
270270 var hist = htmx . _ ( 'getCachedHistory' ) ( '/test' )
271271 should . equal ( hist , null )
272- localStorage . setItem = setItem
272+ sessionStorage . setItem = setItem
273273 } )
274274 }
275275
276276 it . skip ( 'normalizePath falls back to no normalization if path not valid URL' , function ( ) {
277277 // path normalization has a bug breaking it right now preventing this test
278278 htmx . _ ( 'saveToHistoryCache' ) ( 'http://' , make ( '<div>' ) )
279279 htmx . _ ( 'saveToHistoryCache' ) ( 'http//' , make ( '<div>' ) )
280- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
280+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
281281 cache . length . should . equal ( 2 )
282282 cache [ 0 ] . url . should . equal ( 'http://' ) // no normalization as invalid
283283 cache [ 1 ] . url . should . equal ( '/http' ) // can normalize this one
284284 } )
285285
286286 it ( 'history cache clears out disabled attribute' , function ( ) {
287287 htmx . _ ( 'saveToHistoryCache' ) ( '/url1' , make ( '<div><div data-disabled-by-htmx disabled></div></div>' ) )
288- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
288+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
289289 cache . length . should . equal ( 1 )
290290 cache [ 0 ] . url . should . equal ( '/url1' )
291291 cache [ 0 ] . content . should . equal ( '<div data-disabled-by-htmx=""></div>' )
@@ -337,7 +337,7 @@ describe('hx-push-url attribute', function() {
337337 div1 . click ( )
338338 this . server . respond ( )
339339 div1 . innerHTML . should . equal ( 'Result' )
340- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
340+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
341341 cache . length . should . equal ( 1 )
342342 path . should . equal ( '/pushpath' )
343343 htmx . off ( 'htmx:pushedIntoHistory' , handler )
@@ -353,7 +353,7 @@ describe('hx-push-url attribute', function() {
353353 div1 . click ( )
354354 this . server . respond ( )
355355 div1 . innerHTML . should . equal ( 'Result' )
356- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
356+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
357357 cache . length . should . equal ( 1 )
358358 path . should . equal ( '/pushpath' )
359359 htmx . off ( 'htmx:pushedIntoHistory' , handler )
@@ -369,7 +369,7 @@ describe('hx-push-url attribute', function() {
369369 div1 . click ( )
370370 this . server . respond ( )
371371 div1 . innerHTML . should . equal ( 'Result' )
372- var cache = JSON . parse ( localStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
372+ var cache = JSON . parse ( sessionStorage . getItem ( HTMX_HISTORY_CACHE_NAME ) )
373373 should . equal ( cache , null )
374374 path . should . equal ( '' )
375375 htmx . off ( 'htmx:pushedIntoHistory' , handler )
0 commit comments