describe('__shouldCancel() unit tests', function() { it('anchor with href should cancel click event', function() { const anchor = createDisconnectedHTML(''); const evt = { type: 'click', currentTarget: anchor, button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); }); it('anchor with # href should cancel click event', function() { const anchor = createDisconnectedHTML(''); const evt = { type: 'click', currentTarget: anchor, button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); }); it('anchor with #foo href should not cancel click event', function() { const evt = { type: 'click', currentTarget: createDisconnectedHTML(''), button: 0 }; assert.equal(htmx.__shouldCancel(evt), false); }); it('div should not cancel click event', function() { const evt = { type: 'click', currentTarget: createDisconnectedHTML('
'), button: 0 }; assert.equal(htmx.__shouldCancel(evt), false); }); it('form should cancel submit event', function() { const evt = { type: 'submit', currentTarget: createDisconnectedHTML('
') }; assert.equal(htmx.__shouldCancel(evt), true); }); it('button inside form should cancel click event', function() { const form = createDisconnectedHTML('
'); const evt = { type: 'click', currentTarget: form.firstElementChild, button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); }); it('submit button inside form should cancel click event', function() { const form = createDisconnectedHTML('
'); const evt = { type: 'click', currentTarget: form.firstElementChild, button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); }); it('input type=submit inside form should cancel click event', function() { const form = createDisconnectedHTML('
'); const evt = { type: 'click', currentTarget: form.firstElementChild, button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); }); it('input type=image inside form should cancel click event', function() { const form = createDisconnectedHTML('
'); const evt = { type: 'click', currentTarget: form.firstElementChild, button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); }); it('button type=reset inside form should not cancel click event', function() { const form = createDisconnectedHTML('
'); const evt = { type: 'click', currentTarget: form.firstElementChild, button: 0 }; assert.equal(htmx.__shouldCancel(evt), false); }); it('button type=button inside form should not cancel click event', function() { const form = createDisconnectedHTML('
'); const evt = { type: 'click', currentTarget: form.firstElementChild, button: 0 }; assert.equal(htmx.__shouldCancel(evt), false); }); it('button with form attribute should cancel click event', function() { const container = createHTMLNoProcessing('
'); try { const evt = { type: 'click', currentTarget: container.querySelector('button'), button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); } finally { container.remove(); } }); it('button with form attribute and type=submit should cancel click event', function() { const container = createHTMLNoProcessing('
'); try { const evt = { type: 'click', currentTarget: container.querySelector('button'), button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); } finally { container.remove(); } }); it('button with form attribute and type=button should not cancel click event', function() { const container = createHTMLNoProcessing('
'); try { const evt = { type: 'click', currentTarget: container.querySelector('button'), button: 0 }; assert.equal(htmx.__shouldCancel(evt), false); } finally { container.remove(); } }); it('button with form attribute and type=reset should not cancel click event', function() { const container = createHTMLNoProcessing('
'); try { const evt = { type: 'click', currentTarget: container.querySelector('button'), button: 0 }; assert.equal(htmx.__shouldCancel(evt), false); } finally { container.remove(); } }); it('button without form should not cancel click event', function() { const evt = { type: 'click', currentTarget: createDisconnectedHTML(''), button: 0 }; assert.equal(htmx.__shouldCancel(evt), false); }); it('disabled button should not cancel click event', function() { const form = createDisconnectedHTML('
'); const evt = { type: 'click', currentTarget: form.firstElementChild, button: 0 }; assert.equal(htmx.__shouldCancel(evt), false); }); it('right-click (button !== 0) should not cancel', function() { const evt = { type: 'click', currentTarget: createDisconnectedHTML(''), button: 2 }; assert.equal(htmx.__shouldCancel(evt), false); }); it('middle-click (button !== 0) should not cancel', function() { const evt = { type: 'click', currentTarget: createDisconnectedHTML(''), button: 1 }; assert.equal(htmx.__shouldCancel(evt), false); }); it('button inside htmx-enabled link should cancel', function() { const link = createDisconnectedHTML(''); const evt = { type: 'click', currentTarget: link.firstElementChild, button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); }); it('htmx-enabled button inside link should cancel', function() { const link = createDisconnectedHTML(''); const evt = { type: 'click', currentTarget: link.firstElementChild, button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); }); it('span inside button in form should cancel', function() { const form = createDisconnectedHTML('
'); const evt = { type: 'click', currentTarget: form.querySelector('span'), button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); }); it('element inside form button should cancel', function() { const form = createDisconnectedHTML('
'); const evt = { type: 'click', currentTarget: form.querySelector('span'), button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); }); it('submit button with form attribute outside form should cancel', function() { const container = createHTMLNoProcessing('
'); try { const evt = { type: 'click', currentTarget: container.querySelector('button'), button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); } finally { container.remove(); } }); it('input type=submit with form attribute outside form should cancel', function() { const container = createHTMLNoProcessing('
'); try { const evt = { type: 'click', currentTarget: container.querySelector('input'), button: 0 }; assert.equal(htmx.__shouldCancel(evt), true); } finally { container.remove(); } }); });