import {expect} from "chai"

import {ATTRIBUTEPREFIX, Assembler} from "../../../source/dom/assembler.mjs";
import {initJSDOM} from "../../util/jsdom.mjs";

describe('Assembler', function () {
    before(async function () {
        initJSDOM();
    })
    describe('createDocumentFragment()', function () {
        it('should return <div>One</div><div>Two</div>', function () {

            let fragment = document.createRange().createContextualFragment('<div>One</div><div>Two</div>');

            let f = new Assembler(fragment);

            // convert to string
            let container = document.createElement('div');
            container.appendChild(f.createDocumentFragment().cloneNode(true));

            expect(container.innerHTML).to.be.equal('<div>One</div><div>Two</div>');
        });
    });

    describe('createDocumentFragment()', function () {
        it('should return DocumentFragment object', function () {
            let d = new Assembler(document.createDocumentFragment());
            expect(d.createDocumentFragment()).to.be.instanceOf(DocumentFragment);
        });
    });

    describe('new', function () {
        it('new Renderer() should return Assembler object', function () {
            let d = new Assembler(document.createDocumentFragment());
            expect(d).to.be.instanceOf(Assembler);
        });
    });

    describe('getAttributePrefix()', function () {
        it('should return ' + ATTRIBUTEPREFIX, function () {
            let d = new Assembler(document.createDocumentFragment());
            expect(d.getAttributePrefix()).to.be.equal(ATTRIBUTEPREFIX);
        });
    });

    describe('setAttributePrefix().getAttributePrefix()', function () {
        it('should return same value', function () {
            let d = new Assembler(document.createDocumentFragment());
            expect(d.setAttributePrefix('test01').getAttributePrefix()).to.be.equal('test01');
        });
    });


});