<commit_before>"use strict";

describe("events", function(){
    function sendClickTo(elem) {
        var e;
        try{
            e = new MouseEvent('click', {
                'view': window,
                'bubbles': true,
                'cancelable': true
            });
            elem.dispatchEvent(e);
        }catch(err){
            NOT_SUPPORTED_SITUATION({
                must: !err,
                description: 'error in creating MouseEvent: '+err,
                excluding: 'IE 11.0, PhantomJS 1.9.8, PhantomJS 2.1.1, Safari 5.1.7'.split(', ')
            });
            elem.click();
        }
    }
    it("must receive click and change the internal typed value of null to a boolean value", function(done){
        var id = 'id' + Math.random();
        var theElement = html.input({type:"checkbox", id:id}).create();
        Tedede.adaptElement(theElement,'boolean');
        var theLabel = html.label({"for": id}, "the text for this tri-state checkbox").create();
        document.body.appendChild(theElement);
        document.body.appendChild(theLabel);
        theElement.setTypedValue(null); 
        expect(theElement.indeterminate).to.be(true); 
        expect(theElement.getTypedValue()).to.be(null); 
        sendClickTo(theElement);
        expect(theElement.indeterminate).to.be(false); 
        expect(document.activeElement).to.be(theElement);
        var firstValue=theElement.getTypedValue();
        expect(firstValue===true || firstValue==false).to.ok();
        sendClickTo(theElement);
        expect(theElement.getTypedValue()).to.be(!firstValue);
        var elementToClick;
        if(NOT_SUPPORTED_SITUATION({
            must: 'click' in theLabel && typeof theLabel.click === 'function',
            description: "could'nt emulate label click'",
            excluding: ['Safari 5.1.7', 'PhantomJS 1.9.8']
        })){
            elementToClick = theElement;
        }else{
            elementToClick = theLabel;
        }
        sendClickTo(elementToClick);
        expect(theElement.getTypedValue()).to.be(!!firstValue);
        sendClickTo(elementToClick);
        expect(theElement.getTypedValue()).to.be(!!!firstValue);
        done();
    });
    function sendKeyTo(elem, keyCode, eventName) {
        // based in https://gist.github.com/ejoubaud/7d7c57cda1c10a4fae8c#file-simulate_keypress-js<commit_msg>Paso un test que fallaba en IE a sincrónico.<commit_after>"use strict";

describe("events", function(){
    function sendClickTo(elem) {
        var e;
        try{
            e = new MouseEvent('click', {
                'view': window,
                'bubbles': true,
                'cancelable': true
            });
            elem.dispatchEvent(e);
        }catch(err){
            NOT_SUPPORTED_SITUATION({
                must: !err,
                description: 'error in creating MouseEvent: '+err,
                excluding: 'IE 11.0, PhantomJS 1.9.8, PhantomJS 2.1.1, Safari 5.1.7'.split(', ')
            });
            elem.click();
        }
    }
    it("must receive click and change the internal typed value of null to a boolean value", function(){
        var id = 'id' + Math.random();
        var theElement = html.input({type:"checkbox", id:id}).create();
        Tedede.adaptElement(theElement,'boolean');
        var theLabel = html.label({"for": id}, "the text for this tri-state checkbox").create();
        document.body.appendChild(theElement);
        document.body.appendChild(theLabel);
        theElement.setTypedValue(null); 
        expect(theElement.indeterminate).to.be(true); 
        expect(theElement.getTypedValue()).to.be(null); 
        sendClickTo(theElement);
        expect(theElement.indeterminate).to.be(false); 
        expect(document.activeElement).to.be(theElement);
        var firstValue=theElement.getTypedValue();
        expect(firstValue===true || firstValue==false).to.ok();
        sendClickTo(theElement);
        expect(theElement.getTypedValue()).to.be(!firstValue);
        var elementToClick;
        if(NOT_SUPPORTED_SITUATION({
            must: 'click' in theLabel && typeof theLabel.click === 'function',
            description: "could'nt emulate label click'",
            excluding: ['Safari 5.1.7', 'PhantomJS 1.9.8']
        })){
            elementToClick = theElement;
        }else{
            elementToClick = theLabel;
        }
        sendClickTo(elementToClick);
        expect(theElement.getTypedValue()).to.be(!!firstValue);
        sendClickTo(elementToClick);
        expect(theElement.getTypedValue()).to.be(!!!firstValue);
        // done();
    });
    function sendKeyTo(elem, keyCode, eventName) {
        // based in https://gist.github.com/ejoubaud/7d7c57cda1c10a4fae8c#file-simulate_keypress-js
{'fraction_non_alphanumeric': 0.13609591922591502, 'fraction_numerical': 0.011358855700462769, 'mean_word_length': 2.3275017494751573, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3471636', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1385, 'n_words': 257}