diff options
author | carson <carson@leaddyno.com> | 2021-02-18 11:13:15 -0700 |
---|---|---|
committer | carson <carson@leaddyno.com> | 2021-02-18 11:13:15 -0700 |
commit | d2b1e10719f1bba5872c74833190735a03ecdde4 (patch) | |
tree | dae31b2fda11aee2621198259b3d08e565e0d988 /test/attributes/hx-push-url.js | |
parent | 8b2d6b0475acf3e33c606542842ee90642bc04e8 (diff) | |
download | htmx-d2b1e10719f1bba5872c74833190735a03ecdde4.tar.gz htmx-d2b1e10719f1bba5872c74833190735a03ecdde4.zip |
all for want of a p: don't blow history out on first successful cache usage :/
potentially fixes https://github.com/bigskysoftware/htmx/issues/370
Diffstat (limited to 'test/attributes/hx-push-url.js')
-rw-r--r-- | test/attributes/hx-push-url.js | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/test/attributes/hx-push-url.js b/test/attributes/hx-push-url.js index 80f5f366..a4d7d807 100644 --- a/test/attributes/hx-push-url.js +++ b/test/attributes/hx-push-url.js @@ -23,8 +23,7 @@ describe("hx-push-url attribute", function() { this.server.respond(); getWorkArea().textContent.should.equal("second") var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME)); - cache.length.should.equal(2); - cache[1].url.should.equal("/test"); + cache[cache.length - 1].url.should.equal("/test"); }); it("navigation should push an element into the cache when string", function () { @@ -78,9 +77,6 @@ describe("hx-push-url attribute", function() { this.server.respond(); workArea.textContent.should.equal("test2") - var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME)); - - cache.length.should.equal(2); htmx._('restoreHistory')("/test1") getWorkArea().getElementsByClassName("htmx-request").length.should.equal(0); }); @@ -149,6 +145,27 @@ describe("hx-push-url attribute", function() { cache.length.should.equal(1); }); + it("does not blow out cache when saving a URL twice", function () { + htmx._('saveToHistoryCache')('url1', 'content', 'title', 'scroll'); + htmx._('saveToHistoryCache')('url2', 'content', 'title', 'scroll'); + htmx._('saveToHistoryCache')('url3', 'content', 'title', 'scroll'); + htmx._('saveToHistoryCache')('url2', 'content', 'title', 'scroll'); + var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME)); + cache.length.should.equal(3); + }); + + it("history cache is LRU", function () { + htmx._('saveToHistoryCache')('url1', 'content', 'title', 'scroll'); + htmx._('saveToHistoryCache')('url2', 'content', 'title', 'scroll'); + htmx._('saveToHistoryCache')('url3', 'content', 'title', 'scroll'); + htmx._('saveToHistoryCache')('url2', 'content', 'title', 'scroll'); + htmx._('saveToHistoryCache')('url1', 'content', 'title', 'scroll'); + var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME)); + cache.length.should.equal(3); + cache[0].url.should.equal("url3"); + cache[1].url.should.equal("url2"); + cache[2].url.should.equal("url1"); + }); it("htmx:afterSettle is called when replacing outerHTML", function () { var called = false; |