| 1 |
describe('hx-disabled-elt attribute', function() { |
| 2 |
beforeEach(function() { |
| 3 |
this.server = sinon.fakeServer.create() |
| 4 |
clearWorkArea() |
| 5 |
}) |
| 6 |
afterEach(function() { |
| 7 |
this.server.restore() |
| 8 |
clearWorkArea() |
| 9 |
}) |
| 10 |
|
| 11 |
it('single element can be disabled w/ hx-disabled elts', function() { |
| 12 |
this.server.respondWith('GET', '/test', 'Clicked!') |
| 13 |
var btn = make('<button hx-get="/test" hx-disabled-elt="this">Click Me!</button>') |
| 14 |
btn.hasAttribute('disabled').should.equal(false) |
| 15 |
btn.click() |
| 16 |
btn.hasAttribute('disabled').should.equal(true) |
| 17 |
this.server.respond() |
| 18 |
btn.hasAttribute('disabled').should.equal(false) |
| 19 |
}) |
| 20 |
|
| 21 |
it('single element can be disabled w/ data-hx-disabled elts', function() { |
| 22 |
this.server.respondWith('GET', '/test', 'Clicked!') |
| 23 |
var btn = make('<button hx-get="/test" data-hx-disabled-elt="this">Click Me!</button>') |
| 24 |
btn.hasAttribute('disabled').should.equal(false) |
| 25 |
btn.click() |
| 26 |
btn.hasAttribute('disabled').should.equal(true) |
| 27 |
this.server.respond() |
| 28 |
btn.hasAttribute('disabled').should.equal(false) |
| 29 |
}) |
| 30 |
|
| 31 |
it('single element can be disabled w/ closest syntax', function() { |
| 32 |
this.server.respondWith('GET', '/test', 'Clicked!') |
| 33 |
var fieldset = make('<fieldset><button id="b1" hx-get="/test" hx-disabled-elt="closest fieldset">Click Me!</button></fieldset>') |
| 34 |
var btn = byId('b1') |
| 35 |
fieldset.hasAttribute('disabled').should.equal(false) |
| 36 |
btn.click() |
| 37 |
fieldset.hasAttribute('disabled').should.equal(true) |
| 38 |
this.server.respond() |
| 39 |
fieldset.hasAttribute('disabled').should.equal(false) |
| 40 |
}) |
| 41 |
|
| 42 |
it('multiple requests with same disabled elt are handled properly', function() { |
| 43 |
this.server.respondWith('GET', '/test', 'Clicked!') |
| 44 |
var b1 = make('<button hx-get="/test" hx-disabled-elt="#b3">Click Me!</button>') |
| 45 |
var b2 = make('<button hx-get="/test" hx-disabled-elt="#b3">Click Me!</button>') |
| 46 |
var b3 = make('<button id="b3">Demo</button>') |
| 47 |
b3.hasAttribute('disabled').should.equal(false) |
| 48 |
|
| 49 |
b1.click() |
| 50 |
b3.hasAttribute('disabled').should.equal(true) |
| 51 |
|
| 52 |
b2.click() |
| 53 |
b3.hasAttribute('disabled').should.equal(true) |
| 54 |
|
| 55 |
|
| 56 |
this.server.processRequest(this.server.queue.shift()) |
| 57 |
|
| 58 |
b3.hasAttribute('disabled').should.equal(true) |
| 59 |
|
| 60 |
this.server.respond() |
| 61 |
|
| 62 |
b3.hasAttribute('disabled').should.equal(false) |
| 63 |
}) |
| 64 |
|
| 65 |
it('multiple elts can be disabled', function() { |
| 66 |
this.server.respondWith('GET', '/test', 'Clicked!') |
| 67 |
var b1 = make('<button hx-get="/test" hx-disabled-elt="#b2, #b3">Click Me!</button>') |
| 68 |
var b2 = make('<button id="b2">Click Me!</button>') |
| 69 |
var b3 = make('<button id="b3">Demo</button>') |
| 70 |
|
| 71 |
b2.hasAttribute('disabled').should.equal(false) |
| 72 |
b3.hasAttribute('disabled').should.equal(false) |
| 73 |
|
| 74 |
b1.click() |
| 75 |
b2.hasAttribute('disabled').should.equal(true) |
| 76 |
b3.hasAttribute('disabled').should.equal(true) |
| 77 |
|
| 78 |
this.server.respond() |
| 79 |
|
| 80 |
b2.hasAttribute('disabled').should.equal(false) |
| 81 |
b3.hasAttribute('disabled').should.equal(false) |
| 82 |
}) |
| 83 |
|
| 84 |
it('load trigger does not prevent disabled element working', function() { |
| 85 |
this.server.respondWith('GET', '/test', 'Loaded!') |
| 86 |
var div1 = make('<div id="d1" hx-get="/test" hx-disabled-elt="#b1" hx-trigger="load">Load Me!</div><button id="b1">Demo</button>') |
| 87 |
var div = byId('d1') |
| 88 |
var btn = byId('b1') |
| 89 |
div.innerHTML.should.equal('Load Me!') |
| 90 |
btn.hasAttribute('disabled').should.equal(true) |
| 91 |
this.server.respond() |
| 92 |
div.innerHTML.should.equal('Loaded!') |
| 93 |
btn.hasAttribute('disabled').should.equal(false) |
| 94 |
}) |
| 95 |
|
| 96 |
it('hx-disabled-elt supports multiple extended selectors', function() { |
| 97 |
this.server.respondWith('GET', '/test', 'Clicked!') |
| 98 |
var form = make('<form hx-get="/test" hx-disabled-elt="find input[type=\'text\'], find button" hx-swap="none"><input id="i1" type="text" placeholder="Type here..."><button id="b2" type="submit">Send</button></form>') |
| 99 |
var i1 = byId('i1') |
| 100 |
var b2 = byId('b2') |
| 101 |
|
| 102 |
i1.hasAttribute('disabled').should.equal(false) |
| 103 |
b2.hasAttribute('disabled').should.equal(false) |
| 104 |
|
| 105 |
b2.click() |
| 106 |
i1.hasAttribute('disabled').should.equal(true) |
| 107 |
b2.hasAttribute('disabled').should.equal(true) |
| 108 |
|
| 109 |
this.server.respond() |
| 110 |
|
| 111 |
i1.hasAttribute('disabled').should.equal(false) |
| 112 |
b2.hasAttribute('disabled').should.equal(false) |
| 113 |
}) |
| 114 |
|
| 115 |
it('closest/find/next/previous handle nothing to find without exception', function() { |
| 116 |
this.server.respondWith('GET', '/test', 'Clicked!') |
| 117 |
var btn1 = make('<button hx-get="/test" hx-disabled-elt="closest input">Click Me!</button>') |
| 118 |
var btn2 = make('<button hx-get="/test" hx-disabled-elt="find input">Click Me!</button>') |
| 119 |
var btn3 = make('<button hx-get="/test" hx-disabled-elt="next input">Click Me!</button>') |
| 120 |
var btn4 = make('<button hx-get="/test" hx-disabled-elt="previous input">Click Me!</button>') |
| 121 |
btn1.click() |
| 122 |
btn1.hasAttribute('disabled').should.equal(false) |
| 123 |
this.server.respond() |
| 124 |
btn2.click() |
| 125 |
btn2.hasAttribute('disabled').should.equal(false) |
| 126 |
this.server.respond() |
| 127 |
btn3.click() |
| 128 |
btn3.hasAttribute('disabled').should.equal(false) |
| 129 |
this.server.respond() |
| 130 |
btn4.click() |
| 131 |
btn4.hasAttribute('disabled').should.equal(false) |
| 132 |
this.server.respond() |
| 133 |
}) |
| 134 |
}) |