I came from a message2 oob swap I should be third but I am in the wrong spot
" +
"I'm page2 content (non-swap) I should be first")
var h1 = make('' +
"" +
"" +
"" +
"
Kutty CLICK ME
")
h1.click()
this.server.respond()
htmx.find('#page2').innerHTML.should.equal("I'm page2 content (non-swap) I should be first")
htmx.find('#message').innerHTML.should.equal('I came from message oob swap I should be second')
htmx.find('#message2').innerHTML.should.equal('I came from a message2 oob swap I should be third but I am in the wrong spot')
})
it('Handles https://github.com/bigskysoftware/htmx/issues/33 "empty values" properly', function() {
this.server.respondWith('POST', '/htmx.php', function(xhr) {
xhr.respond(200, {}, xhr.requestBody)
})
var form = make('')
form.click()
this.server.respond()
form.innerHTML.should.equal('variable=')
})
it('name=id doesnt cause an error', function() {
this.server.respondWith('GET', '/test', 'Foo')
var div = make('
Get It
')
div.click()
this.server.respond()
div.innerText.should.contain('Foo')
})
it('empty id doesnt cause an error', function() {
this.server.respondWith('GET', '/test', "Foo\n")
var div = make('
Get It
')
div.click()
this.server.respond()
div.innerText.should.contain('Foo')
})
it('id with dot in value doesnt cause an error', function() {
this.server.respondWith('GET', '/test', "Foo ")
var div = make('
Get It
')
div.click()
this.server.respond()
div.innerText.should.contain('Foo')
})
it('@ symbol in attributes does not break requests', function() {
this.server.respondWith('GET', '/test', "
Foo
")
var div = make('
Get It
')
div.click()
this.server.respond()
byId('d1').getAttribute('@foo').should.equal('bar')
})
it('@ symbol in attributes does not break attribute settling requests', function() {
this.server.respondWith('GET', '/test', "
Foo
")
var div = make('
Foo
')
div.click()
this.server.respond()
byId('d1').getAttribute('@foo').should.equal('bar')
})
it('selected element with ID does not cause NPE when it disappears', function() {
this.server.respondWith('GET', '/test', "
Replaced
")
var input = make('')
input.focus()
input.click()
this.server.respond()
byId('d1').innerText.should.equal('Replaced')
})
it('does not submit with a false condition on a form', function() {
this.server.respondWith('POST', '/test', 'Submitted')
var defaultPrevented = false
htmx.on('click', function(evt) {
defaultPrevented = evt.defaultPrevented
})
var form = make('')
form.click()
this.server.respond()
defaultPrevented.should.equal(true)
})
it('two elements can listen for the same event on another element', function() {
this.server.respondWith('GET', '/test', 'triggered')
make('' +
' ')
var div1 = byId('d1')
var div2 = byId('d2')
document.body.click()
this.server.respond()
div2.innerHTML.should.equal('triggered')
div1.innerHTML.should.equal('triggered')
})
it('a form can reset based on the htmx:afterRequest event', function() {
this.server.respondWith('POST', '/test', 'posted')
var form = make('')
htmx.trigger(form, 'htmx:load') // have to manually trigger the load event for non-AJAX dynamic content
var div1 = byId('d1')
var input = byId('i1')
input.value = 'foo'
var submit = byId('s1')
input.value.should.equal('foo')
submit.click()
this.server.respond()
div1.innerHTML.should.equal('posted')
input.value.should.equal('') // form should be reset
})
it('supports image maps', function() {
this.server.respondWith('GET', '/test', 'triggered')
make('
' +
' ' +
' ' +
'' +
' ' +
'
')
var div1 = byId('d1')
var area = document.getElementsByTagName('area')[0]
area.click()
this.server.respond()
div1.innerHTML.should.equal('triggered')
})
it('supports unset on hx-select', function() {
this.server.respondWith('GET', '/test', "FooBar")
make('')
var btn = byId('b1')
btn.click()
this.server.respond()
btn.innerText.should.equal('FooBar')
})
it("can trigger swaps from fields that don't support setSelectionRange", function() {
const template = ''
const response = ''
this.server.respondWith('GET', '/test', response)
make(template)
var input = byId('id_email')
// HTMX only attempts to restore the selection on inputs that have a current selection and are active.
// additionally we can't set the selection on email inputs (that's the whole bug) so start as a text input where you can set selection
// and replace with an email
input.focus()
input.selectionStart = 3
input.selectionEnd = 3
input.click()
this.server.respond()
var input = byId('id_email')
input.value.should.equal('supertest@test.com')
})
it('script tags only execute once', function(done) {
window.i = 0 // set count to 0
this.server.respondWith('GET', '/test', '') // increment the count by 1
// make a div w/ a short settle delay to make the problem more obvious
var div = make('')
div.click()
this.server.respond()
setTimeout(function() {
window.i.should.equal(1)
delete window.i
done()
}, 50)
})
it('script tags only execute once when nested', function(done) {
window.i = 0 // set count to 0
this.server.respondWith('GET', '/test', '
foo
') // increment the count by 1
// make a div w/ a short settle delay to make the problem more obvious
var div = make('')
div.click()
this.server.respond()
setTimeout(function() {
window.i.should.equal(1)
delete window.i
done()
}, 50)
})
it('htmx.config.allowScriptTags properly disables script tags', function(done) {
htmx.config.allowScriptTags = false
window.i = 0 // set count to 0
this.server.respondWith('GET', '/test', '') // increment the count by 1
// make a div w/ a short settle delay to make the problem more obvious
var div = make('')
div.click()
this.server.respond()
setTimeout(function() {
window.i.should.equal(0)
htmx.config.allowScriptTags = true
delete window.i
done()
}, 50)
})
it('htmx.config.allowScriptTags properly disables script tags when nested', function(done) {
htmx.config.allowScriptTags = false
window.i = 0 // set count to 0
this.server.respondWith('GET', '/test', '') // increment the count by 1
// make a div w/ a short settle delay to make the problem more obvious
var div = make('')
div.click()
this.server.respond()
setTimeout(function() {
window.i.should.equal(0)
htmx.config.allowScriptTags = true
delete window.i
done()
}, 50)
})
})