|
| 1 | +import { parseDOM } from '../source/DOM/parser'; |
| 2 | + |
| 3 | +import { indexOf, insertTo, valueOf } from '../source/DOM/manipulate'; |
| 4 | + |
| 5 | +const form = parseDOM(`<form> |
| 6 | + <input type="radio" name="radio" value="r1" checked> |
| 7 | + <input type="radio" name="radio" value="r2"> |
| 8 | +
|
| 9 | + <input type="checkbox" name="check" value="c1" checked> |
| 10 | + <input type="checkbox" name="check" value="c2"> |
| 11 | + <input type="checkbox" name="check" value="c3" checked> |
| 12 | +
|
| 13 | + <select name="select" multiple> |
| 14 | + <option>s1</option> |
| 15 | + <option selected>s2</option> |
| 16 | + <option selected>s3</option> |
| 17 | + </select> |
| 18 | +
|
| 19 | + <textarea name="text">example</textarea> |
| 20 | +</form>`).firstChild; |
| 21 | + |
| 22 | +describe('DOM inserting', () => { |
| 23 | + /** |
| 24 | + * @test {indexOf} |
| 25 | + */ |
| 26 | + it('gets the index of DOM nodes', () => { |
| 27 | + indexOf(form.firstElementChild).should.be.equal(0); |
| 28 | + |
| 29 | + indexOf(form.firstElementChild, true).should.be.equal(1); |
| 30 | + }); |
| 31 | + |
| 32 | + /** |
| 33 | + * @test {insertTo} |
| 34 | + */ |
| 35 | + it('inserts Nodes to an Element by index', () => { |
| 36 | + insertTo(form, 'test', -2, true); |
| 37 | + |
| 38 | + insertTo(form, 'test', Infinity, true); |
| 39 | + |
| 40 | + form.outerHTML.should.be.equal(`<form> |
| 41 | + <input type="radio" name="radio" value="r1" checked=""> |
| 42 | + <input type="radio" name="radio" value="r2"> |
| 43 | +
|
| 44 | + <input type="checkbox" name="check" value="c1" checked=""> |
| 45 | + <input type="checkbox" name="check" value="c2"> |
| 46 | + <input type="checkbox" name="check" value="c3" checked=""> |
| 47 | +
|
| 48 | + <select name="select" multiple=""> |
| 49 | + <option>s1</option> |
| 50 | + <option selected="">s2</option> |
| 51 | + <option selected="">s3</option> |
| 52 | + </select> |
| 53 | +
|
| 54 | + test<textarea name="text">example</textarea> |
| 55 | +test</form>`); |
| 56 | + }); |
| 57 | + |
| 58 | + /** |
| 59 | + * @test {valueOf} |
| 60 | + */ |
| 61 | + it('gets values of Form fields', () => { |
| 62 | + const { radio, check, select, text } = form.elements; |
| 63 | + |
| 64 | + valueOf(radio).should.be.equal('r1'); |
| 65 | + valueOf(check).should.be.eql(['c1', 'c3']); |
| 66 | + valueOf(select).should.be.eql(['s2', 's3']); |
| 67 | + valueOf(text).should.be.equal('example'); |
| 68 | + }); |
| 69 | +}); |
0 commit comments