<commit_before>/* eslint-env mocha */

import {
    isFunction,
    isString,
    isObject,
    isUndefined,
    isArray,
    isFalsy,
} from '../../src/lib/typeof.js';
import * as DOM from '../../src/lib/dom.js';
import { render } from '../../src/lib/render.js';
import { define } from '../../src/lib/define.js';
import { bootstrap } from '../../src/lib/bootstrap.js';

import { BaseComponent } from '../../index.js';

const WRAPPER = document.body;

class TestComponent extends BaseComponent {
    static get observedAttributes() {
        return ['age'];
    }

    constructor(node) {
        super(node);
        this.name = 'Alan';
        this.lastName = 'Turing';
        this.connectedTimes = 0;
        this.disconnectedTimes = 0;
        this.attributeChanges = 0;
    }

    connectedCallback() {
        super.connectedCallback();
        this.connectedTimes++;
    }

    disconnectedCallback() {
        super.disconnectedCallback();
        this.disconnectedTimes++;
    }

    attributeChangedCallback(...args) {
        super.attributeChangedCallback(...args);
        this.attributeChanges++;
    }
}

class TestComponent2 extends TestComponent {}

define('test1-helper-component', TestComponent);
define('helper-define-component', TestComponent2, { extends: 'div' });

describe('Unit: lib', () => {
    describe('typeof', () => {
        it('should correctly check type of objects', () => {
            assert(isFunction(() => {}));
            assert(!isFunction({}));
            assert(isString(''));
            assert(!isString(4));
            assert(isObject({}));
            assert(!isObject([]));
            assert(isUndefined(undefined));
            assert(!isUndefined(null));
            assert(!isUndefined(false));
            assert(!isUndefined(''));
            assert(isArray([]));
            assert(!isArray({}));
            assert(!isArray(''));
            assert(isFalsy(undefined));
            assert(isFalsy(null));
            assert(isFalsy(false));
            assert(!isFalsy(''));
        });
    });

    describe('define', () => {
        describe('a simple element', () => {
            it('should define a custom element', () => {
                const elem = new TestComponent();
                assert.equal(elem.node.tagName.toLowerCase(), 'test1-helper-component');
                assert.equal(elem.name, 'Alan');
                assert.equal(elem.lastName, 'Turing');
            });
        });

        describe('an element with extends field', () => {
            it('a custom element with extends field', () => {
                const elem = render(WRAPPER, TestComponent2);
                assert.equal(elem.node.localName.toLowerCase(), 'div');
                assert.equal(elem.name, 'Alan');
                assert.equal(elem.lastName, 'Turing');
            });
        });
    });

    describe('DOM helpers', () => {
        const elem = new TestComponent();
        const elem2 = render(WRAPPER, TestComponent2);
        it('should do nothing', () => {
            const tmp = document.createElement('div');
            assert(!DOM.connect(tmp));
            assert(!DOM.disconnect(tmp));
        });
        it('should create a component instance', () => {
            assert.equal(elem.node.tagName.toLowerCase(), 'test1-helper-component');
            assert.equal(elem.name, 'Alan');
            assert.equal(elem.lastName, 'Turing');
        });
        it('should append a component', () => {
            DOM.appendChild(WRAPPER, elem);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem.disconnectedTimes, 0);
            assert.equal(elem.connectedTimes, 1);
            assert.equal(elem2.disconnectedTimes, 0);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should append a component before another', () => {
            DOM.insertBefore(WRAPPER, elem, elem2);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem2.node.parentNode, WRAPPER);
            assert.equal(elem.node.nextSibling, elem2.node);
            assert.equal(elem.disconnectedTimes, 1);
            assert.equal(elem.connectedTimes, 2);
            assert.equal(elem2.disconnectedTimes, 0);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should do nothing if already before another', () => {
            DOM.insertBefore(WRAPPER, elem, elem2);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem2.node.parentNode, WRAPPER);
            assert.equal(elem.node.nextSibling, elem2.node);
            assert.equal(elem.disconnectedTimes, 1);
            assert.equal(elem.connectedTimes, 2);
            assert.equal(elem2.disconnectedTimes, 0);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should append again a component', () => {
            DOM.appendChild(WRAPPER, elem);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem.disconnectedTimes, 2);
            assert.equal(elem.connectedTimes, 3);
            assert.equal(elem2.disconnectedTimes, 0);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should do nothing if already last child of parent', () => {
            DOM.appendChild(WRAPPER, elem);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem.disconnectedTimes, 2);
            assert.equal(elem.connectedTimes, 3);
            assert.equal(elem2.disconnectedTimes, 0);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should replace a child', () => {
            DOM.replaceChild(WRAPPER, elem, elem2);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem.disconnectedTimes, 3);
            assert.equal(elem.connectedTimes, 4);
            assert.equal(elem2.disconnectedTimes, 1);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should set attributes', () => {
            DOM.setAttribute(elem, 'age', 20);
            DOM.setAttribute(elem, 'married', '');
            assert.equal(elem.attributeChanges, 1);
            assert.equal(elem.node.getAttribute('age'), '20');
            assert.equal(elem.node.getAttribute('married'), '');
        });
        it('should remove attributes', () => {
            DOM.removeAttribute(elem, 'age');
            DOM.removeAttribute(elem, 'married');
            assert.equal(elem.attributeChanges, 2);
            assert.equal(elem.node.getAttribute('age'), null);
            assert.equal(elem.node.getAttribute('married'), null);
        });
    });

    describe('bootstrap', () => {
        let WRAPPER = document.createElement('div');
        WRAPPER.innerHTML = '<p>Hello <test1-helper-component age="21"></test1-helper-component></p>';
        it('should instantiate all components', () => {
            bootstrap(WRAPPER);
            const elem = DOM.getNodeComponent(
                WRAPPER.querySelector('.test1-helper-component')
            );
            assert.equal(elem.node.localName.toLowerCase(), 'test1-helper-component');
            assert.equal(elem.node.getAttribute('age'), '21');
            assert.equal(elem.node.getAttribute('class'), 'test1-helper-component');
            assert.equal(elem.name, 'Alan');
            assert.equal(elem.lastName, 'Turing');
        });

        let WRAPPER2 = document.createElement('div');
        WRAPPER.innerHTML = '<p>Hello again <test1-helper-component age="21"/><test1-helper-component age="22"/></p>';
        it('should call callback for every component', () => {
            let count = 0;
            bootstrap(WRAPPER2, () => {
                count++;
            });
            assert.equal(count, 2);
        });
    });
});<commit_msg>test: fix var name.. doh!<commit_after>/* eslint-env mocha */

import {
    isFunction,
    isString,
    isObject,
    isUndefined,
    isArray,
    isFalsy,
} from '../../src/lib/typeof.js';
import * as DOM from '../../src/lib/dom.js';
import { render } from '../../src/lib/render.js';
import { define } from '../../src/lib/define.js';
import { bootstrap } from '../../src/lib/bootstrap.js';

import { BaseComponent } from '../../index.js';

const WRAPPER = document.body;

class TestComponent extends BaseComponent {
    static get observedAttributes() {
        return ['age'];
    }

    constructor(node) {
        super(node);
        this.name = 'Alan';
        this.lastName = 'Turing';
        this.connectedTimes = 0;
        this.disconnectedTimes = 0;
        this.attributeChanges = 0;
    }

    connectedCallback() {
        super.connectedCallback();
        this.connectedTimes++;
    }

    disconnectedCallback() {
        super.disconnectedCallback();
        this.disconnectedTimes++;
    }

    attributeChangedCallback(...args) {
        super.attributeChangedCallback(...args);
        this.attributeChanges++;
    }
}

class TestComponent2 extends TestComponent {}

define('test1-helper-component', TestComponent);
define('helper-define-component', TestComponent2, { extends: 'div' });

describe('Unit: lib', () => {
    describe('typeof', () => {
        it('should correctly check type of objects', () => {
            assert(isFunction(() => {}));
            assert(!isFunction({}));
            assert(isString(''));
            assert(!isString(4));
            assert(isObject({}));
            assert(!isObject([]));
            assert(isUndefined(undefined));
            assert(!isUndefined(null));
            assert(!isUndefined(false));
            assert(!isUndefined(''));
            assert(isArray([]));
            assert(!isArray({}));
            assert(!isArray(''));
            assert(isFalsy(undefined));
            assert(isFalsy(null));
            assert(isFalsy(false));
            assert(!isFalsy(''));
        });
    });

    describe('define', () => {
        describe('a simple element', () => {
            it('should define a custom element', () => {
                const elem = new TestComponent();
                assert.equal(elem.node.tagName.toLowerCase(), 'test1-helper-component');
                assert.equal(elem.name, 'Alan');
                assert.equal(elem.lastName, 'Turing');
            });
        });

        describe('an element with extends field', () => {
            it('a custom element with extends field', () => {
                const elem = render(WRAPPER, TestComponent2);
                assert.equal(elem.node.localName.toLowerCase(), 'div');
                assert.equal(elem.name, 'Alan');
                assert.equal(elem.lastName, 'Turing');
            });
        });
    });

    describe('DOM helpers', () => {
        const elem = new TestComponent();
        const elem2 = render(WRAPPER, TestComponent2);
        it('should do nothing', () => {
            const tmp = document.createElement('div');
            assert(!DOM.connect(tmp));
            assert(!DOM.disconnect(tmp));
        });
        it('should create a component instance', () => {
            assert.equal(elem.node.tagName.toLowerCase(), 'test1-helper-component');
            assert.equal(elem.name, 'Alan');
            assert.equal(elem.lastName, 'Turing');
        });
        it('should append a component', () => {
            DOM.appendChild(WRAPPER, elem);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem.disconnectedTimes, 0);
            assert.equal(elem.connectedTimes, 1);
            assert.equal(elem2.disconnectedTimes, 0);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should append a component before another', () => {
            DOM.insertBefore(WRAPPER, elem, elem2);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem2.node.parentNode, WRAPPER);
            assert.equal(elem.node.nextSibling, elem2.node);
            assert.equal(elem.disconnectedTimes, 1);
            assert.equal(elem.connectedTimes, 2);
            assert.equal(elem2.disconnectedTimes, 0);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should do nothing if already before another', () => {
            DOM.insertBefore(WRAPPER, elem, elem2);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem2.node.parentNode, WRAPPER);
            assert.equal(elem.node.nextSibling, elem2.node);
            assert.equal(elem.disconnectedTimes, 1);
            assert.equal(elem.connectedTimes, 2);
            assert.equal(elem2.disconnectedTimes, 0);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should append again a component', () => {
            DOM.appendChild(WRAPPER, elem);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem.disconnectedTimes, 2);
            assert.equal(elem.connectedTimes, 3);
            assert.equal(elem2.disconnectedTimes, 0);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should do nothing if already last child of parent', () => {
            DOM.appendChild(WRAPPER, elem);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem.disconnectedTimes, 2);
            assert.equal(elem.connectedTimes, 3);
            assert.equal(elem2.disconnectedTimes, 0);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should replace a child', () => {
            DOM.replaceChild(WRAPPER, elem, elem2);
            assert.equal(elem.node.parentNode, WRAPPER);
            assert.equal(elem.disconnectedTimes, 3);
            assert.equal(elem.connectedTimes, 4);
            assert.equal(elem2.disconnectedTimes, 1);
            assert.equal(elem2.connectedTimes, 1);
        });
        it('should set attributes', () => {
            DOM.setAttribute(elem, 'age', 20);
            DOM.setAttribute(elem, 'married', '');
            assert.equal(elem.attributeChanges, 1);
            assert.equal(elem.node.getAttribute('age'), '20');
            assert.equal(elem.node.getAttribute('married'), '');
        });
        it('should remove attributes', () => {
            DOM.removeAttribute(elem, 'age');
            DOM.removeAttribute(elem, 'married');
            assert.equal(elem.attributeChanges, 2);
            assert.equal(elem.node.getAttribute('age'), null);
            assert.equal(elem.node.getAttribute('married'), null);
        });
    });

    describe('bootstrap', () => {
        let WRAPPER = document.createElement('div');
        WRAPPER.innerHTML = '<p>Hello <test1-helper-component age="21"></test1-helper-component></p>';
        it('should instantiate all components', () => {
            bootstrap(WRAPPER);
            const elem = DOM.getNodeComponent(
                WRAPPER.querySelector('.test1-helper-component')
            );
            assert.equal(elem.node.localName.toLowerCase(), 'test1-helper-component');
            assert.equal(elem.node.getAttribute('age'), '21');
            assert.equal(elem.node.getAttribute('class'), 'test1-helper-component');
            assert.equal(elem.name, 'Alan');
            assert.equal(elem.lastName, 'Turing');
        });

        let WRAPPER2 = document.createElement('div');
        WRAPPER2.innerHTML = '<p>Hello again <test1-helper-component age="21"/><test1-helper-component age="22"/></p>';
        it('should call callback for every component', () => {
            let count = 0;
            bootstrap(WRAPPER2, () => {
                count++;
            });
            assert.equal(count, 2);
        });
    });
});
{'fraction_non_alphanumeric': 0.15484036086761788, 'fraction_numerical': 0.010301362851110116, 'mean_word_length': 2.132892363199038, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4204875', 'n_tokens_mistral': 4300, 'n_tokens_neox': 4233, 'n_words': 732}