| 1 |
describe('hx-history attribute', function() { |
| 2 |
var HTMX_HISTORY_CACHE_NAME = 'htmx-history-cache' |
| 3 |
|
| 4 |
beforeEach(function() { |
| 5 |
this.server = makeServer() |
| 6 |
clearWorkArea() |
| 7 |
sessionStorage.removeItem(HTMX_HISTORY_CACHE_NAME) |
| 8 |
}) |
| 9 |
afterEach(function() { |
| 10 |
this.server.restore() |
| 11 |
clearWorkArea() |
| 12 |
sessionStorage.removeItem(HTMX_HISTORY_CACHE_NAME) |
| 13 |
}) |
| 14 |
|
| 15 |
it('history cache should not contain embargoed content', function() { |
| 16 |
this.server.respondWith('GET', '/test1', '<div id="d2" hx-push-url="true" hx-get="/test2" hx-swap="outerHTML settle:0" hx-history="true">test1</div>') |
| 17 |
this.server.respondWith('GET', '/test2', '<div id="d3" hx-push-url="true" hx-get="/test3" hx-swap="outerHTML settle:0" hx-history="false">test2</div>') |
| 18 |
this.server.respondWith('GET', '/test3', '<div id="d4" hx-push-url="true" hx-get="/test3" hx-swap="outerHTML settle:0" hx-history="true">test3</div>') |
| 19 |
|
| 20 |
make('<div id="d1" hx-push-url="true" hx-get="/test1" hx-swap="outerHTML settle:0">init</div>') |
| 21 |
|
| 22 |
byId('d1').click() |
| 23 |
this.server.respond() |
| 24 |
var workArea = getWorkArea() |
| 25 |
workArea.textContent.should.equal('test1') |
| 26 |
|
| 27 |
byId('d2').click() |
| 28 |
this.server.respond() |
| 29 |
workArea.textContent.should.equal('test2') |
| 30 |
|
| 31 |
byId('d3').click() |
| 32 |
this.server.respond() |
| 33 |
workArea.textContent.should.equal('test3') |
| 34 |
|
| 35 |
|
| 36 |
var cache = JSON.parse(sessionStorage.getItem(HTMX_HISTORY_CACHE_NAME)) |
| 37 |
cache.length.should.equal(2) |
| 38 |
|
| 39 |
|
| 40 |
htmx._('restoreHistory')('/test2') |
| 41 |
this.server.respond() |
| 42 |
getWorkArea().textContent.should.equal('test2') |
| 43 |
}) |
| 44 |
}) |