| 1 | describe('hx-inherit attribute', function() { |
| 2 | beforeEach(function() { |
| 3 | this.server = makeServer() |
| 4 | clearWorkArea() |
| 5 | htmx.config.disableInheritance = true |
| 6 | }) |
| 7 | afterEach(function() { |
| 8 | this.server.restore() |
| 9 | clearWorkArea() |
| 10 | htmx.config.disableInheritance = false |
| 11 | }) |
| 12 | |
| 13 | it('can disable inheritance', function() { |
| 14 | this.server.respondWith('GET', '/test', 'Test') |
| 15 | var div = make('<div hx-target="#cta">' + |
| 16 | '<button id="btn1" hx-get="/test"></button>' + |
| 17 | '<span id="cta">Click Me!</span>' + |
| 18 | '</div>') |
| 19 | var btn = byId('btn1') |
| 20 | btn.click() |
| 21 | this.server.respond() |
| 22 | btn.innerText.should.equal('Test') |
| 23 | }) |
| 24 | |
| 25 | it('can enable inheritance for all', function() { |
| 26 | this.server.respondWith('GET', '/test', 'Test') |
| 27 | var div = make('<div hx-target="#cta" hx-inherit="*">' + |
| 28 | '<button id="btn1" hx-get="/test"></button>' + |
| 29 | '<span id="cta">Click Me!</span>' + |
| 30 | '</div>') |
| 31 | var btn = byId('btn1') |
| 32 | var span = byId('cta') |
| 33 | btn.click() |
| 34 | this.server.respond() |
| 35 | btn.innerText.should.equal('') |
| 36 | span.innerText.should.equal('Test') |
| 37 | }) |
| 38 | |
| 39 | it('can enable inheritance by name', function() { |
| 40 | this.server.respondWith('GET', '/test', 'Test') |
| 41 | var div = make('<div hx-target="#cta" hx-inherit="hx-target">' + |
| 42 | '<button id="btn1" hx-get="/test"></button>' + |
| 43 | '<span id="cta">Click Me!</span>' + |
| 44 | '</div>') |
| 45 | var btn = byId('btn1') |
| 46 | var span = byId('cta') |
| 47 | btn.click() |
| 48 | this.server.respond() |
| 49 | btn.innerText.should.equal('') |
| 50 | span.innerText.should.equal('Test') |
| 51 | }) |
| 52 | |
| 53 | it('can enable inheritance by name (bad name, no inheritance)', function() { |
| 54 | this.server.respondWith('GET', '/test', 'Test') |
| 55 | var div = make('<div hx-target="#cta" hx-inherit="hx-swap">' + |
| 56 | '<button id="btn1" hx-get="/test"></button>' + |
| 57 | '<span id="cta">Click Me!</span>' + |
| 58 | '</div>') |
| 59 | var btn = byId('btn1') |
| 60 | var span = byId('cta') |
| 61 | btn.click() |
| 62 | this.server.respond() |
| 63 | btn.innerText.should.equal('Test') |
| 64 | span.innerText.should.equal('Click Me!') |
| 65 | }) |
| 66 | |
| 67 | it('can enable inheritance by name with multiple attributes', function() { |
| 68 | this.server.respondWith('GET', '/test', 'Test') |
| 69 | var div = make('<div hx-target="#cta" hx-swap="outerHTML" hx-inherit="hx-target hx-swap">' + |
| 70 | '<button id="btn1" hx-get="/test"></button>' + |
| 71 | '<div id="d2"><span id="cta">Click Me!</span></div>' + |
| 72 | '</div>') |
| 73 | var btn = byId('btn1') |
| 74 | var div = byId('d2') |
| 75 | btn.click() |
| 76 | this.server.respond() |
| 77 | div.innerHTML.should.equal('Test') |
| 78 | }) |
| 79 | }) |