describe('__shouldBoost() unit tests', function() { beforeEach(function() { setupTest(); }); afterEach(function() { cleanupTest(); }); // Anchor tag tests describe('Anchor tags', function() { it('should boost same-origin link with no target', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isTrue(result); }); it('should boost same-origin link with target="_self"', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isTrue(result); }); it('should boost relative URLs', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isTrue(result); }); it('should boost absolute same-origin URLs', function() { const origin = window.location.origin; const link = createDisconnectedHTML(`Link`); const result = htmx.__shouldBoost(link); assert.isTrue(result); }); it('should not boost hash-only links', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isFalse(result); }); it('should not boost links with download', function() { const link = createDisconnectedHTML('Download'); const result = htmx.__shouldBoost(link); assert.isFalse(result); }); it('should not boost links with target="_blank"', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isUndefined(result); }); it('should not boost links with target="_parent"', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isUndefined(result); }); it('should not boost links with target="_top"', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isUndefined(result); }); it('should not boost links with named target', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isUndefined(result); }); it('should not boost cross-origin links', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isFalse(result); }); it('should not boost protocol-relative cross-origin links', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isFalse(result); }); it('should boost links with hash after path', function() { const link = createDisconnectedHTML('Link'); const result = htmx.__shouldBoost(link); assert.isTrue(result); }); it('should not boost javascript: URLs', function() { const link = createDisconnectedHTML('Link'); // javascript: URLs will likely fail the same-origin check const result = htmx.__shouldBoost(link); assert.isFalse(result); }); }); // Form tag tests describe('Form tags', function() { it('should boost same-origin form with no action', function() { const form = createDisconnectedHTML('
'); const result = htmx.__shouldBoost(form); assert.isTrue(result); }); it('should boost same-origin form with relative action', function() { const form = createDisconnectedHTML('
'); const result = htmx.__shouldBoost(form); assert.isTrue(result); }); it('should boost form with absolute same-origin action', function() { const origin = window.location.origin; const form = createDisconnectedHTML(`
`); const result = htmx.__shouldBoost(form); assert.isTrue(result); }); it('should boost form with method="post"', function() { const form = createDisconnectedHTML('
'); const result = htmx.__shouldBoost(form); assert.isTrue(result); }); it('should boost form with method="get"', function() { const form = createDisconnectedHTML('
'); const result = htmx.__shouldBoost(form); assert.isTrue(result); }); it('should not boost form with method="dialog"', function() { const form = createDisconnectedHTML('
'); const result = htmx.__shouldBoost(form); assert.isFalse(result); }); it('should not boost form with cross-origin action', function() { const form = createDisconnectedHTML('
'); const result = htmx.__shouldBoost(form); assert.isFalse(result); }); it('should not boost form with protocol-relative cross-origin action', function() { const form = createDisconnectedHTML('
'); const result = htmx.__shouldBoost(form); assert.isFalse(result); }); }); // Other element tests describe('Other elements', function() { it('should return undefined for non-anchor, non-form elements', function() { const div = createDisconnectedHTML('
'); const result = htmx.__shouldBoost(div); assert.isUndefined(result); }); it('should return undefined for button elements', function() { const button = createDisconnectedHTML(''); const result = htmx.__shouldBoost(button); assert.isUndefined(result); }); it('should return undefined for input elements', function() { const input = createDisconnectedHTML(''); const result = htmx.__shouldBoost(input); assert.isUndefined(result); }); }); });