//import {getGlobal} from "../../../../source/types/global.mjs";
import * as chai from 'chai';
import {chaiDom} from "../../../util/chai-dom.mjs";
import {initJSDOM} from "../../../util/jsdom.mjs";

let expect = chai.expect;
chai.use(chaiDom);

// const global = getGlobal();
//
// let html1 = `
//     <div id="test1">
//     </div>
// `;
//
// // language=HTML
// let html2 = `
//     <div id="test2">
//         <monster-notify data-monster-options='{}'></monster-notitfy>
//     </div>
// `;

let Notify, fetchReference;

describe('Notify', function () {

    before(function (done) {
        initJSDOM().then(() => {
            import("../../../../source/components/notify/notify.mjs").then((m) => {
                Notify = m['Notify'];
                done()
            }).catch(e => done(e))
        });
    })

    describe('document.createElement', function () {
        it('should instance of notify', function () {

            
                expect(document.createElement('monster-notify')).is.instanceof(Notify);
            


        });

        it('should have messages', function (done) {

            let mocks = document.getElementById('mocks');
            const notify = document.createElement('monster-notify');
            let i = 0;
            notify.push("this is message " + i++);
            notify.push("this is message " + i++);
            notify.push("this is message " + i++);

            const mutationobserver = new MutationObserver(function (mutations) {

                for (const [, mutation] of mutations.entries()) {
                    if (mutation.addedNodes[0].tagName === 'MONSTER-NOTIFY') {

                        setTimeout(() => {
                            mutationobserver.disconnect();
                            try {

                                const messages = notify.shadowRoot.querySelectorAll('monster-notify-message');
                                // 3 options (see fetch above)
                                expect(messages.length).is.equal(3);

                            } catch (e) {
                                return done(e);
                            }

                            done();


                        }, 0)
                    }
                }

            });

            mutationobserver.observe(mocks, {childList: true});
            mocks.appendChild(notify);

        });

    });


})
