'use strict';

import {expect} from "chai"
import {Node} from "../../../source/types/node.mjs";
import {NodeList} from "../../../source/types/nodelist.mjs";

describe('NodeList', function () {
    describe('#constructor', function () {
        it('should create an empty NodeList', function () {
            let nodeList = new NodeList();

            expect(nodeList.size).to.equal(0);
        });

        it('should create a NodeList from an array', function () {
            let nodeList = new NodeList([
                new Node('div'),
                new Node('div'),
                new Node('div')
            ]);

            expect(nodeList.size).to.equal(3);
        });

        it('should create a NodeList from a NodeList', function () {
            let nodeList = new NodeList([
                new Node('div'),
                new Node('div'),
                new Node('div')
            ]);

            let nodeList2 = new NodeList(nodeList);

            expect(nodeList2.size).to.equal(3);
        });
        
    });
    
     
    it('create NodeList', function () {
        expect(new NodeList()).is.instanceof(NodeList);
    })

    it('add Node', function () {
        expect(new NodeList().add(new Node())).to.be.instanceof(NodeList);
    })

    it('remove Node', function () {
        expect(new NodeList().remove(new Node())).to.be.instanceof(NodeList);
    })

    it('has unknown Node', function () {
        expect(new NodeList().has(new Node)).to.be.false;
    })

    it('has added Node', function () {
        const n = new Node;
        expect(new NodeList().add(n).has(n)).to.be.true;
    })
    
    it('toString', function () {
        const n = new Node;
        expect(new NodeList().add(new Node('a').appendChild(new Node('b'))).toString()).to.be.equal('a\n └b');
    })

    it('throw exception', function () {
        expect(() => new NodeList().add(1)).to.throw(Error);
    })


});