<commit_before>/*
 * test.js
 */

'use strict';

require("mocha-as-promised")();

var normalizeTransformValue = require('../src/normalize-transform-value'),
    Zanimo = require('..'),
    Q = require('q'),
    prefix = require('prefix'),
    expect = require('expect.js');

Q.longStackSupport = true;

function createSquare(id) {
    var el = document.createElement("div");
    el.id = id;
    el.style.width = "100px";
    el.style.height = "100px";
    el.style.backgroundColor = "red";
    document.body.appendChild(el);
    return el;
};

function removeSquare(id) {
    document.body.removeChild(document.getElementById(id));
};

function setUp1 () { return createSquare("test-1"); }
function setDown1 (val) { removeSquare("test-1"); return val; }
function setUp2 () { return createSquare("test-2"); }
function setDown2 (val) { removeSquare("test-2"); return val; }

describe('normalizeTransformValue', function () {
    it('should return `translate3d(0,0,0)` when called with `translate3d(0px ,0, 0  )`', function () {
        expect(normalizeTransformValue('translate3d(0px ,0, 0  )')).to.eql('translate3d(0,0,0)');
    });
    it('should return `translate3d(0,200px,0) rotateY(280deg) translate3d(0,0,30px)` when called with `translate3d(0px ,200px, 0  )  rotateY(280deg)        translate3d( 0 , 0,30px)`', function () {
        expect(normalizeTransformValue('translate3d(0px ,200px, 0  )  rotateY(280deg)        translate3d( 0 , 0,30px)')).to.eql('translate3d(0,200px,0) rotateY(280deg) translate3d(0,0,30px)');
    });
    it('should return an empty string when called with no arg', function () {
        expect(normalizeTransformValue()).to.eql('');
    });
});

describe('Zanimo', function () {

    it('rejects with no DOM element', function () {
        return Q.all([Q.fcall(Zanimo, 'Oops'), Q.fcall(Zanimo), Q.fcall(Zanimo, [1,2,3])])
            .fail(function (err) {
                return expect(err).to.be.a(Error);
            });
    });

    it('succeeded with a DOM element', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(function (el) {
                    expect(el).to.be.a(window.Element);
                    setDown1();
                });
        });
    });

    it('succeeded with a promise of a DOM element', function () {
        var el = setUp1(),
            d = Q.defer();

        setTimeout(function () {
            d.resolve(el);
        }, 500);

        return Q.delay(200).then(function () {
            return Zanimo(d.promise)
                .then(function (el) {
                    expect(el).to.be.a(window.Element);
                    setDown1();
                });
        });
    });

    it('failed with a promise of number', function () {
        var el = setUp1(),
            d = Q.defer();

        setTimeout(function () {
            d.resolve(1);
        }, 500);

        return Q.delay(200).then(function () {
            return Zanimo(d.promise)
                .fail(function (err) {
                    setDown1();
                    expect(err).to.be.a(Error);
                });
        });
    });

    it('succeeded applying a style to an element', function () {
        var el = setUp1();

        return Zanimo(el).then(Zanimo.f('opacity', 0)).then(function (el) {
            expect(el.style.opacity).to.eql("0");
            setDown1();
        });
    });

    it('succeeded transitioning the width of a element from 100px to 300px in 400ms with ease-in-out timing function', function() {
        var el = setUp1();

        return Q.delay(200).then(function () {

            expect(el.style.width).to.eql('100px');

            return Zanimo(el, "width", "300px", 400, "ease-in-out")
                .then(function (el) {
                    expect(el.style.width).to.eql('300px');
                    setDown1();
                });
        });

     });

    it('succeeded transitioning the width and height of a element from 100px to 300px in 400ms with ease-in-out timing function', function() {
        var el = setUp1();

        return Q.delay(200).then(function () {

            expect(el.style.width).to.eql('100px');
            expect(el.style.height).to.eql('100px');

            return  Q.all([
                    Zanimo(el, "width", "300px", 400, "ease-in-out"),
                    Zanimo(el, "height", "300px", 400, "ease-in-out")
                ])
                .then(function (els) {
                    expect(els[0].style.width).to.eql('300px');
                    expect(els[0].style.height).to.eql('300px');
                    setDown1();
                });
        });

     });

    it('succeeded chaining of 2 transitions with 2 elements', function () {
        var el1 = setUp1(),
            el2 = setUp2(),
            down = function (r) {
                setDown1();
                return setDown2(r);
            };

        return Q.delay(200).then(function () {
            return Zanimo(el1, "transform", "translate(200px, 0)", 300)
                .then(function () {
                    expect(el1.style[prefix('transform')]).to.be.eql('translate(200px, 0)');
                    return Zanimo(el2, "transform", "translate(0, 200px)", 100);
                })
                .then(function (el) {
                    expect(el.style[prefix('transform')]).to.be.eql('translate(0, 200px)');
                    down();
                });
        });
    });

    it('failed when called with not a DOM element', function () {
        return Q.delay(200).then(function () {
            return Q.fcall(Zanimo, "Oops", "opacity", 1, 100)
                .fail(function (err) {
                    return expect(err).to.be.a(Error);
                });
        });
    });

    it('failed when called with a wrong transition property', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Q.fcall(Zanimo, el, "toto", "test", 100)
                .fail(function (err) {
                    setDown1();
                    return expect(err).to.be.a(Error);
                });
        });
    });

    it('failed when called with a wrong time value', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Q.fcall(Zanimo, el, "opacity", 0.5, "oops", "linear")
                .fail(function (err) {
                    setDown1();
                    return expect(err).to.be.a(Error);
                });
        });
    });

    it('succeeded while setting the transform css property of an element to `translate(200px, 0)`', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el, "transform", "translate(200px, 0)")
                .then(setDown1);
        });
    });


});

describe('Zanimo.f', function () {

    it('succeeded transitioning the opacity of an element from 1 to 0 in 200ms', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(Zanimo.f("opacity", 0, 200))
                .then(setDown1);
        });
    });

    it('failed when trying to perform a transition on the display css property', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(Zanimo.f("display", 1, 100))
                .fail(function (err) {
                    setDown1();
                    return expect(err).to.be.a(Error);
                });
        });
    });

    it('succeeded transitioning the transform property of an element from nothing to `translate(200px, 0)` in 200ms', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(Zanimo.f("transform", "translate(200px, 0)", 200))
                .then(setDown1);
        });
    });

    it('succeeded transitioning the background-color property of an element from red to blue in 200ms', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(Zanimo.f("background-color", "blue", 200))
                .then(setDown1);
        });
    });

    it('failed on the first call when called 2 times on the same element on the same css property', function () {
        var el = setUp1(),
            transition1 = Zanimo.f("transform", "translate(200px, 0)", 400),
            transition2 = Zanimo.f("transform", "translate(100px, 300px)", 100);

        Q.delay(200).then(function () {
            return Zanimo(el).delay(100).then(transition2);
        });

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(transition1)
                .fail(function (err) {
                    setDown1();<commit_msg>update tests<commit_after>/*
 * test.js
 */

'use strict';

require("mocha-as-promised")();

var normalizeTransformValue = require('../src/normalize-transform-value'),
    Zanimo = require('..'),
    Q = require('q'),
    prefix = require('prefix'),
    expect = require('expect.js');

Q.longStackSupport = true;

function createSquare(id) {
    var el = document.createElement("div");
    el.id = id;
    el.style.width = "100px";
    el.style.height = "100px";
    el.style.backgroundColor = "red";
    document.body.appendChild(el);
    return el;
};

function removeSquare(id) {
    document.body.removeChild(document.getElementById(id));
};

function setUp1 () { return createSquare("test-1"); }
function setDown1 (val) { removeSquare("test-1"); return val; }
function setUp2 () { return createSquare("test-2"); }
function setDown2 (val) { removeSquare("test-2"); return val; }

describe('normalizeTransformValue', function () {
    it('should return `translate3d(0,0,0)` when called with `translate3d(0px ,0, 0  )`', function () {
        expect(normalizeTransformValue('translate3d(0px ,0, 0  )')).to.eql('translate3d(0,0,0)');
    });
    it('should return `translate3d(0,200px,0) rotateY(280deg) translate3d(0,0,30px)` when called with `translate3d(0px ,200px, 0  )  rotateY(280deg)        translate3d( 0 , 0,30px)`', function () {
        expect(normalizeTransformValue('translate3d(0px ,200px, 0  )  rotateY(280deg)        translate3d( 0 , 0,30px)')).to.eql('translate3d(0,200px,0) rotateY(280deg) translate3d(0,0,30px)');
    });
    it('should return an empty string when called with no arg', function () {
        expect(normalizeTransformValue()).to.eql('');
    });
});

describe('Zanimo', function () {

    it('rejects with no DOM element', function () {
        return Q.all([Q.fcall(Zanimo, 'Oops'), Q.fcall(Zanimo), Q.fcall(Zanimo, [1,2,3])])
            .fail(function (err) {
                return expect(err).to.be.a(Error);
            });
    });

    it('succeeded with a DOM element', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(function (el) {
                    expect(el).to.be.a(window.Element);
                    setDown1();
                });
        });
    });

    it('succeeded with a promise of a DOM element', function () {
        var el = setUp1(),
            d = Q.defer();

        setTimeout(function () {
            d.resolve(el);
        }, 500);

        return Q.delay(200).then(function () {
            return Zanimo(d.promise)
                .then(function (el) {
                    expect(el).to.be.a(window.Element);
                    setDown1();
                });
        });
    });

    it('failed with a promise of number', function () {
        var el = setUp1(),
            d = Q.defer();

        setTimeout(function () {
            d.resolve(1);
        }, 500);

        return Q.delay(200).then(function () {
            return Zanimo(d.promise)
                .fail(function (err) {
                    setDown1();
                    expect(err).to.be.a(Error);
                });
        });
    });

    it('succeeded applying a style to an element', function () {
        var el = setUp1();

        return Zanimo(el).then(Zanimo.f('opacity', 0)).then(function (el) {
            expect(el.style.opacity).to.eql("0");
            setDown1();
        });
    });

    it('succeeded transitioning the width of a element from 100px to 300px in 400ms with ease-in-out timing function', function() {
        var el = setUp1();

        return Q.delay(200).then(function () {

            expect(el.style.width).to.eql('100px');

            return Zanimo(el, "width", "300px", 400, "ease-in-out")
                .then(function (el) {
                    expect(el.style.width).to.eql('300px');
                    setDown1();
                });
        });

     });

    it('succeeded transitioning the width and height of a element from 100px to 300px in 400ms with ease-in-out timing function', function() {
        var el = setUp1();

        return Q.delay(200).then(function () {

            expect(el.style.width).to.eql('100px');
            expect(el.style.height).to.eql('100px');

            return  Q.all([
                    Zanimo(el, "width", "300px", 400, "ease-in-out"),
                    Zanimo(el, "height", "300px", 400, "ease-in-out")
                ])
                .then(function (els) {
                    expect(els[0].style.width).to.eql('300px');
                    expect(els[0].style.height).to.eql('300px');
                    setDown1();
                });
        });

     });

    it('succeeded chaining of 2 transitions with 2 elements', function () {
        var el1 = setUp1(),
            el2 = setUp2(),
            down = function (r) {
                setDown1();
                return setDown2(r);
            };

        return Q.delay(200).then(function () {
            return Zanimo(el1, "transform", "translate(200px, 0)", 300)
                .then(function () {
                    expect(normalizeTransformValue(el1.style[prefix('transform')])).to.be.eql('translate(200px,0)');
                    return Zanimo(el2, "transform", "translate(0, 200px)", 100);
                })
                .then(function (el) {
                    expect(normalizeTransformValue(el.style[prefix('transform')])).to.be.eql('translate(0,200px)');
                    down();
                });
        });
    });

    it('failed when called with not a DOM element', function () {
        return Q.delay(200).then(function () {
            return Q.fcall(Zanimo, "Oops", "opacity", 1, 100)
                .fail(function (err) {
                    return expect(err).to.be.a(Error);
                });
        });
    });

    it('failed when called with a wrong transition property', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Q.fcall(Zanimo, el, "toto", "test", 100)
                .fail(function (err) {
                    setDown1();
                    return expect(err).to.be.a(Error);
                });
        });
    });

    it('failed when called with a wrong time value', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Q.fcall(Zanimo, el, "opacity", 0.5, "oops", "linear")
                .fail(function (err) {
                    setDown1();
                    return expect(err).to.be.a(Error);
                });
        });
    });

    it('succeeded while setting the transform css property of an element to `translate(200px, 0)`', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el, "transform", "translate(200px, 0)")
                .then(setDown1);
        });
    });


});

describe('Zanimo.f', function () {

    it('succeeded transitioning the opacity of an element from 1 to 0 in 200ms', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(Zanimo.f("opacity", 0, 200))
                .then(setDown1);
        });
    });

    it('failed when trying to perform a transition on the display css property', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(Zanimo.f("display", 1, 100))
                .fail(function (err) {
                    setDown1();
                    return expect(err).to.be.a(Error);
                });
        });
    });

    it('succeeded transitioning the transform property of an element from nothing to `translate(200px, 0)` in 200ms', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(Zanimo.f("transform", "translate(200px, 0)", 200))
                .then(setDown1);
        });
    });

    it('succeeded transitioning the background-color property of an element from red to blue in 200ms', function () {
        var el = setUp1();

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(Zanimo.f('background-color', 'blue', 200))
                .then(setDown1);
        });
    });

    it('failed on the first call when called 2 times on the same element on the same css property', function () {
        var el = setUp1(),
            transition1 = Zanimo.f("transform", "translate(200px, 0)", 400),
            transition2 = Zanimo.f("transform", "translate(100px, 300px)", 100);

        Q.delay(200).then(function () {
            return Zanimo(el).delay(100).then(transition2);
        });

        return Q.delay(200).then(function () {
            return Zanimo(el)
                .then(transition1)
                .fail(function (err) {
                    setDown1();
{'fraction_non_alphanumeric': 0.15492722101388656, 'fraction_numerical': 0.03758853382410351, 'mean_word_length': 1.8346506481188745, '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': '5659322', 'n_tokens_mistral': 5904, 'n_tokens_neox': 5255, 'n_words': 1156}