describe('__makeFragment unit tests', function() {
it('creates fragment from simple HTML', function () {
let {fragment} = htmx.__makeFragment('
Test
');
fragment.children[0].tagName.should.equal('DIV');
fragment.children[0].innerText.should.equal('Test');
})
it('creates fragment from multiple elements', function () {
let {fragment} = htmx.__makeFragment('A
B');
fragment.children.length.should.equal(2);
fragment.children[0].innerText.should.equal('A');
fragment.children[1].innerText.should.equal('B');
})
it('extracts title from HTML document', function () {
let {title} = htmx.__makeFragment('Test Title');
title.should.equal('Test Title');
})
it('handles html tag', function () {
let {fragment} = htmx.__makeFragment('Test
');
fragment.children[0].tagName.should.equal('BODY');
fragment.children[0].children[0].tagName.should.equal('DIV');
})
it('handles body tag', function () {
let {fragment} = htmx.__makeFragment('Test
');
fragment.children[0].tagName.should.equal('BODY');
fragment.children[0].children[0].tagName.should.equal('DIV');
})
it('converts partial tags to template', function () {
let {fragment} = htmx.__makeFragment('Content');
fragment.children[0].tagName.should.equal('TEMPLATE');
fragment.children[0].hasAttribute('hx').should.be.true;
fragment.children[0].getAttribute('type').should.equal('partial');
})
it('strips head content', function () {
let {fragment} = htmx.__makeFragment('TitleBody
');
assert.isNull(fragment.querySelector('head'));
fragment.children[0].tagName.should.equal('DIV');
})
it('handles table row content', function () {
let {fragment} = htmx.__makeFragment('| Cell 1 | Cell 2 |
');
fragment.children[0].tagName.should.equal('TR');
fragment.children[0].children.length.should.equal(2);
fragment.children[0].children[0].innerText.should.equal('Cell 1');
fragment.children[0].children[1].innerText.should.equal('Cell 2');
})
it('handles multiple table rows', function () {
let {fragment} = htmx.__makeFragment('| A |
| B |
');
fragment.children.length.should.equal(2);
fragment.children[0].tagName.should.equal('TR');
fragment.children[1].tagName.should.equal('TR');
})
it('handles table cell content', function () {
let {fragment} = htmx.__makeFragment('Cell Content | ');
fragment.children[0].tagName.should.equal('TD');
fragment.children[0].innerText.should.equal('Cell Content');
})
it('handles thead content', function () {
let {fragment} = htmx.__makeFragment('| Header |
');
fragment.children[0].tagName.should.equal('THEAD');
fragment.children[0].querySelector('th').innerText.should.equal('Header');
})
it('handles tbody content', function () {
let {fragment} = htmx.__makeFragment('| Data |
');
fragment.children[0].tagName.should.equal('TBODY');
fragment.children[0].querySelector('td').innerText.should.equal('Data');
})
it('handles mixed table elements', function () {
let {fragment} = htmx.__makeFragment('| H |
|---|
| D |
');
fragment.children.length.should.equal(2);
fragment.children[0].tagName.should.equal('THEAD');
fragment.children[1].tagName.should.equal('TBODY');
})
});