Debian Codegraph @

test/tests/unit/__makeFragment.js

raw symbols SCIP
1 describe('__makeFragment unit tests', function() {
2
3 it('creates fragment from simple HTML', function () {
4 let {fragment} = htmx.__makeFragment('<div>Test</div>');
5 fragment.children[0].tagName.should.equal('DIV');
6 fragment.children[0].innerText.should.equal('Test');
7 })
8
9 it('creates fragment from multiple elements', function () {
10 let {fragment} = htmx.__makeFragment('<div>A</div><span>B</span>');
11 fragment.children.length.should.equal(2);
12 fragment.children[0].innerText.should.equal('A');
13 fragment.children[1].innerText.should.equal('B');
14 })
15
16 it('extracts title from HTML document', function () {
17 let {title} = htmx.__makeFragment('<html><head><title>Test Title</title></head><body></body></html>');
18 title.should.equal('Test Title');
19 })
20
21 it('handles html tag', function () {
22 let {fragment} = htmx.__makeFragment('<html><body><div>Test</div></body></html>');
23 fragment.children[0].tagName.should.equal('BODY');
24 fragment.children[0].children[0].tagName.should.equal('DIV');
25 })
26
27 it('handles body tag', function () {
28 let {fragment} = htmx.__makeFragment('<body><div>Test</div></body>');
29 fragment.children[0].tagName.should.equal('BODY');
30 fragment.children[0].children[0].tagName.should.equal('DIV');
31 })
32
33 it('converts partial tags to template', function () {
34 let {fragment} = htmx.__makeFragment('<hx-partial hx-target="#foo">Content</hx-partial>');
35 fragment.children[0].tagName.should.equal('TEMPLATE');
36 fragment.children[0].hasAttribute('hx').should.be.true;
37 fragment.children[0].getAttribute('type').should.equal('partial');
38 })
39
40 it('strips head content', function () {
41 let {fragment} = htmx.__makeFragment('<head><title>Title</title></head><div>Body</div>');
42 assert.isNull(fragment.querySelector('head'));
43 fragment.children[0].tagName.should.equal('DIV');
44 })
45
46 it('handles table row content', function () {
47 let {fragment} = htmx.__makeFragment('<tr><td>Cell 1</td><td>Cell 2</td></tr>');
48 fragment.children[0].tagName.should.equal('TR');
49 fragment.children[0].children.length.should.equal(2);
50 fragment.children[0].children[0].innerText.should.equal('Cell 1');
51 fragment.children[0].children[1].innerText.should.equal('Cell 2');
52 })
53
54 it('handles multiple table rows', function () {
55 let {fragment} = htmx.__makeFragment('<tr><td>A</td></tr><tr><td>B</td></tr>');
56 fragment.children.length.should.equal(2);
57 fragment.children[0].tagName.should.equal('TR');
58 fragment.children[1].tagName.should.equal('TR');
59 })
60
61 it('handles table cell content', function () {
62 let {fragment} = htmx.__makeFragment('<td>Cell Content</td>');
63 fragment.children[0].tagName.should.equal('TD');
64 fragment.children[0].innerText.should.equal('Cell Content');
65 })
66
67 it('handles thead content', function () {
68 let {fragment} = htmx.__makeFragment('<thead><tr><th>Header</th></tr></thead>');
69 fragment.children[0].tagName.should.equal('THEAD');
70 fragment.children[0].querySelector('th').innerText.should.equal('Header');
71 })
72
73 it('handles tbody content', function () {
74 let {fragment} = htmx.__makeFragment('<tbody><tr><td>Data</td></tr></tbody>');
75 fragment.children[0].tagName.should.equal('TBODY');
76 fragment.children[0].querySelector('td').innerText.should.equal('Data');
77 })
78
79 it('handles mixed table elements', function () {
80 let {fragment} = htmx.__makeFragment('<thead><tr><th>H</th></tr></thead><tbody><tr><td>D</td></tr></tbody>');
81 fragment.children.length.should.equal(2);
82 fragment.children[0].tagName.should.equal('THEAD');
83 fragment.children[1].tagName.should.equal('TBODY');
84 })
85
86 });