describe('hx-indicator attribute', function() { beforeEach(function() { this.server = sinon.fakeServer.create() clearWorkArea() }) afterEach(function() { this.server.restore() clearWorkArea() }) it('Indicator classes are properly put on element with no explicit indicator', function() { this.server.respondWith('GET', '/test', 'Clicked!') var btn = make('') btn.click() btn.classList.contains('htmx-request').should.equal(true) this.server.respond() btn.classList.contains('htmx-request').should.equal(false) }) it('Indicator classes are properly put on element with explicit indicator', function() { this.server.respondWith('GET', '/test', 'Clicked!') var btn = make('') var a1 = make('') var a2 = make('') btn.click() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(true) a2.classList.contains('htmx-request').should.equal(true) this.server.respond() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(false) a2.classList.contains('htmx-request').should.equal(false) }) it('Indicator classes are properly put on element with relative indicator', function() { this.server.respondWith('GET', '/test', 'Clicked!') var btn = make('') var a1 = make('') btn.click() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(true) this.server.respond() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(false) }) it('Indicator classes are properly put on element with explicit indicator w/ data-* prefix', function() { this.server.respondWith('GET', '/test', 'Clicked!') var btn = make('') var a1 = make('') var a2 = make('') btn.click() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(true) a2.classList.contains('htmx-request').should.equal(true) this.server.respond() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(false) a2.classList.contains('htmx-request').should.equal(false) }) it('allows closest syntax in hx-indicator', function() { this.server.respondWith('GET', '/test', 'Clicked!') var div = make('
') var btn = byId('b1') btn.click() btn.classList.contains('htmx-request').should.equal(false) div.classList.contains('htmx-request').should.equal(true) this.server.respond() btn.classList.contains('htmx-request').should.equal(false) div.classList.contains('htmx-request').should.equal(false) }) it('is removed when initiating element is removed from the DOM', function() { this.server.respondWith('GET', '/test', 'Clicked!') var indicator = make('
Indicator
') var div = make('
') var btn = byId('b1') btn.click() indicator.classList.contains('htmx-request').should.equal(true) this.server.respond() indicator.classList.contains('htmx-request').should.equal(false) }) it('allows this syntax in hx-indicator', function() { this.server.respondWith('GET', '/test', 'Clicked!') var div = make('
') var btn = byId('b1') btn.click() btn.classList.contains('htmx-request').should.equal(false) div.classList.contains('htmx-request').should.equal(true) this.server.respond() btn.classList.contains('htmx-request').should.equal(false) div.classList.contains('htmx-request').should.equal(false) }) it('multiple requests with same indicator are handled properly', function() { this.server.respondWith('GET', '/test', 'Clicked!') var b1 = make('') var b2 = make('') var a1 = make('') b1.click() b1.classList.contains('htmx-request').should.equal(false) b2.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(true) b2.click() b1.classList.contains('htmx-request').should.equal(false) b2.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(true) // hack to make sinon process only one response this.server.processRequest(this.server.queue.shift()) b1.classList.contains('htmx-request').should.equal(false) b2.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(true) this.server.respond() b1.classList.contains('htmx-request').should.equal(false) b2.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(false) }) it('`inherit` can be used to expand parent hx-indicator', function() { this.server.respondWith('GET', '/test', 'Clicked!') make('
' + ' ' + '
') var btn = byId('btn') var a1 = make('') var a2 = make('') btn.click() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(true) a2.classList.contains('htmx-request').should.equal(true) this.server.respond() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(false) a2.classList.contains('htmx-request').should.equal(false) }) it('`inherit` can be used to expand multiple parents hx-indicator', function() { this.server.respondWith('GET', '/test', 'Clicked!') make('
' + '
' + ' ' + '
' + '
') var btn = byId('btn') var a1 = make('') var a2 = make('') var a3 = make('') btn.click() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(true) a2.classList.contains('htmx-request').should.equal(true) a3.classList.contains('htmx-request').should.equal(true) this.server.respond() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(false) a2.classList.contains('htmx-request').should.equal(false) a3.classList.contains('htmx-request').should.equal(false) }) it('`inherit` chain breaks properly', function() { this.server.respondWith('GET', '/test', 'Clicked!') make('
' + '
' + ' ' + '
' + '
') var btn = byId('btn') var a1 = make('') var a2 = make('') var a3 = make('') btn.click() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(false) a2.classList.contains('htmx-request').should.equal(true) a3.classList.contains('htmx-request').should.equal(true) this.server.respond() btn.classList.contains('htmx-request').should.equal(false) a1.classList.contains('htmx-request').should.equal(false) a2.classList.contains('htmx-request').should.equal(false) a3.classList.contains('htmx-request').should.equal(false) }) })