'use strict';

import {expect} from "chai"

import {Locale} from "../../../source/i18n/locale.mjs";
import {getLocaleOfDocument} from "../../../source/dom/locale.mjs";
import {initJSDOM} from "../../util/jsdom.mjs";

describe('Attributes', function () {
    before(function (done) {
        initJSDOM().then(() => {
            done()
        });
    });

    describe('getLocaleOfDocument', function () {


        [
            ["de"],
            ["sl-IT-nedis"],
            ["en-GB"],

        ].forEach(function (data) {

            let a = data.shift()


            it('return language ' + a, function () {
                let html = document.getElementsByTagName('html');
                let node = html.item(0);

                node.setAttribute('lang', a);
                expect(getLocaleOfDocument().toString()).to.be.equal(a);
            })


        });


    });


    it('return language en', function () {
        let html = document.getElementsByTagName('html');
        let node = html.item(0);
        let lang= node.getAttribute('lang');

        node.removeAttribute('lang');
        const locale = getLocaleOfDocument();
        expect(locale).to.be.instanceOf(Locale);
        expect(locale.localeString).to.be.equal(navigator.language);

        node.setAttribute('lang', lang);
        
    })


})