import {expect} from "chai"


import {Embed} from "../../../../source/i18n/providers/embed.mjs";
import {Translations} from "../../../../source/i18n/translations.mjs";
import {getGlobal} from "../../../../source/types/global.mjs";
import {initJSDOM} from "../../../util/jsdom.mjs";


const global = getGlobal();

const html1 = `
<script id="templocale" type="application/json">
{
        "key": "translation"
}
</script>
`;

describe('Translation Provider Embed', function () {

    before(function (done) {
        initJSDOM().then(() => {
            done()
        });
    });


    afterEach(() => {
        let mocks = document.getElementById('mocks');
        mocks.innerHTML = "";
    });

    beforeEach(() => {
        let mocks = document.getElementById('mocks');
        mocks.innerHTML = html1;

    })

    describe('get mock data and create translation', function () {

        it('embed', function (done) {

            const e = new Embed('templocale');
            let p = e.getTranslations('en');
            expect(p).is.instanceof(Promise);

            p.then(r => {

                try {
                    expect(r).is.instanceof(Translations);
 
                    let t = r.getText('key')
                    expect(t).is.equal('translation');


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


            }).catch(e => {
                done(e);
            })

        });

    });


});