<commit_before>var TouchendBtn = require('../../lib/index').Touchend,
    Q = require('q'),
    expect = require('expect.js');

describe('default/TouchendButton', function () {
    it('must be an function', function () {
        expect(TouchendBtn).to.be.an('function');
    });
});<commit_msg>default touchend tests<commit_after>var TouchendBtn = require('../../lib/index').Touchend,
    Q = require('q'),
    expect = require('expect.js');

describe('default/TouchendButton', function () {
    it('must be an function', function () {
        expect(TouchendBtn).to.be.an('function');
    });
    describe('instance', function () {
        it('should raise an Error when calling .bind() if already binded', function () {
            var btn = new TouchendBtn({
                    el : document.createElement('div'),
                    f : function () { }
                });
            btn.bind();
            expect(function () { btn.bind(); }).to.throwException("Can't bind an already binded button.");
        });
        it('should raise an Error when calling .unbind() if unbinded', function () {
            var btn = new TouchendBtn({
                    el : document.createElement('div'),
                    f : function () { }
                });
            expect(function () { btn.unbind(); }).to.throwException("Can't unbind a unbinded button.");
        });
        it('should have a setActiveBorder method', function () {
            var btn = new TouchendBtn({
                    el : document.createElement('div'),
                    f : function () { }
                });
            expect(btn.setActiveBorder).to.be.an('function');
        });
        it('can not be activated if already activated', function (done) {
            var i = 0,
                btn = new TouchendBtn({
                    el : document.createElement('div'),
                    f : function () { i = i+1; return Q.delay(200); }
                });
            btn.bind();
            // first fake activation
            btn.onTouchstart({ changedTouches:[{ identifier : 0 }] });
            btn.onTouchend({ changedTouches:[{ identifier : 0 }] });
            setTimeout(function () {
                // second activation while the first is not done
                btn.onTouchstart({ changedTouches:[{ identifier : 1 }] });
                btn.onTouchend({ changedTouches:[{ identifier : 1 }] });
            },50);
            setTimeout(function () {
                expect(i).to.be(1);
                done();
            },300);
        });
       it('should add the `.active` css class on the underlying DOM element when active', function (done) {
            var btn = new TouchendBtn({
                el : document.createElement('div'),
                f : function () { return Q.delay(200); }
            });

            btn.bind();
            // fake activation
            btn.onTouchstart({ changedTouches:[{ identifier : 0 }] });
            btn.onTouchend({ changedTouches:[{ identifier : 0 }] });

            setTimeout(function () {
                expect(btn.el.classList.contains('active')).to.be(true);
                done();
            },100);
        });
        it('should remove the `.active` css class on the underlying DOM element when callback ended', function (done) {
            var btn = new TouchendBtn({
                el : document.createElement('div'),
                f : function () { return Q.delay(100); }
            });

            btn.bind();
            // fake activation
            btn.onTouchstart({ changedTouches:[{ identifier : 0 }] });
            btn.onTouchend({ changedTouches:[{ identifier : 0 }] });

            setTimeout(function () {
                expect(btn.el.classList.contains('active')).to.be(false);
                done();
            },200);
        });
        it('.bind should return the button', function () {
            var btn = new TouchendBtn({
                el : document.createElement('div'),
                f : function () { }
            });
            expect(btn.bind()).to.be.equal(btn);
        });
        it('.unbind should return the button', function () {
            var btn = new TouchendBtn({
                el : document.createElement('div'),
                f : function () { }
            });
            expect(btn.bind().unbind()).to.be.equal(btn);
        });
    });
});
{'fraction_non_alphanumeric': 0.14965831435079727, 'fraction_numerical': 0.007061503416856492, 'mean_word_length': 1.6419975932611313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2632114', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1118, 'n_words': 270}