summaryrefslogtreecommitdiffstatshomepage
path: root/test/attributes/hx-push-url.js
diff options
context:
space:
mode:
authorcarson <carson@leaddyno.com>2020-06-17 12:30:52 -0700
committercarson <carson@leaddyno.com>2020-06-17 12:30:52 -0700
commitb6f1c834cfd9935cee7694fc679f71575b7b8964 (patch)
tree4456451d5d4ed0e411db20dfb740c9326d97f8d0 /test/attributes/hx-push-url.js
parent19b933449b1af4d4589bee24ae201dbe0c8d374f (diff)
downloadhtmx-b6f1c834cfd9935cee7694fc679f71575b7b8964.tar.gz
htmx-b6f1c834cfd9935cee7694fc679f71575b7b8964.zip
include perf tests
Diffstat (limited to 'test/attributes/hx-push-url.js')
-rw-r--r--test/attributes/hx-push-url.js53
1 files changed, 10 insertions, 43 deletions
diff --git a/test/attributes/hx-push-url.js b/test/attributes/hx-push-url.js
index efb91b02..d1f6b137 100644
--- a/test/attributes/hx-push-url.js
+++ b/test/attributes/hx-push-url.js
@@ -1,15 +1,16 @@
describe("hx-push-url attribute", function() {
- var KUTTY_HISTORY_CACHE = "htmx-history-cache";
+ var HTMX_HISTORY_CACHE_NAME = "htmx-history-cache";
+
beforeEach(function () {
this.server = makeServer();
clearWorkArea();
- localStorage.removeItem(KUTTY_HISTORY_CACHE);
+ localStorage.removeItem(HTMX_HISTORY_CACHE_NAME);
});
afterEach(function () {
this.server.restore();
clearWorkArea();
- localStorage.removeItem(KUTTY_HISTORY_CACHE);
+ localStorage.removeItem(HTMX_HISTORY_CACHE_NAME);
});
it("navigation should push an element into the cache ", function () {
@@ -19,7 +20,7 @@ describe("hx-push-url attribute", function() {
div.click();
this.server.respond();
getWorkArea().textContent.should.equal("second")
- var cache = JSON.parse(localStorage.getItem(KUTTY_HISTORY_CACHE));
+ var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME));
cache.length.should.equal(1);
});
@@ -38,7 +39,7 @@ describe("hx-push-url attribute", function() {
this.server.respond();
workArea.textContent.should.equal("test2")
- var cache = JSON.parse(localStorage.getItem(KUTTY_HISTORY_CACHE));
+ var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME));
cache.length.should.equal(2);
htmx._('restoreHistory')("/test1")
@@ -58,7 +59,7 @@ describe("hx-push-url attribute", function() {
byId("d1").click();
this.server.respond();
}
- var cache = JSON.parse(localStorage.getItem(KUTTY_HISTORY_CACHE));
+ var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME));
cache.length.should.equal(10); // should only be 10 elements
});
@@ -77,49 +78,15 @@ describe("hx-push-url attribute", function() {
this.server.respond();
workArea.textContent.should.equal("test2")
- var cache = JSON.parse(localStorage.getItem(KUTTY_HISTORY_CACHE));
+ var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME));
cache.length.should.equal(2);
- localStorage.removeItem(KUTTY_HISTORY_CACHE); // clear cache
+ localStorage.removeItem(HTMX_HISTORY_CACHE_NAME); // clear cache
htmx._('restoreHistory')("/test1")
this.server.respond();
getWorkArea().textContent.should.equal("test1")
});
- function stringRepeat(str, num) {
- num = Number(num);
-
- var result = '';
- while (true) {
- if (num & 1) { // (1)
- result += str;
- }
- num >>>= 1; // (2)
- if (num <= 0) break;
- str += str;
- }
-
- return result;
- }
-
- it("implementation details should be fast", function(){
- // create an entry with a large content string (256k) and see how fast we can write and read it
- // to local storage as a single entry
- var entry = {url: stringRepeat("x", 32), content:stringRepeat("x", 256*1024)}
- var array = [];
- for (var i = 0; i < 10; i++) {
- array.push(entry);
- }
- var start = performance.now();
- var string = JSON.stringify(array);
- localStorage.setItem(KUTTY_HISTORY_CACHE, string);
- var reReadString = localStorage.getItem(KUTTY_HISTORY_CACHE);
- var finalJson = JSON.parse(reReadString);
- var end = performance.now();
- var timeInMs = end - start;
- chai.assert(timeInMs < 300, "Should take less than 300ms on most platforms");
- })
-
it("navigation should push an element into the cache w/ data-* prefix", function () {
this.server.respondWith("GET", "/test", "second");
getWorkArea().innerHTML.should.be.equal("");
@@ -127,7 +94,7 @@ describe("hx-push-url attribute", function() {
div.click();
this.server.respond();
getWorkArea().textContent.should.equal("second")
- var cache = JSON.parse(localStorage.getItem(KUTTY_HISTORY_CACHE));
+ var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME));
cache.length.should.equal(1);
});