<commit_before>/**
 * @preserve Copyright (c) 2013 British Broadcasting Corporation
 * (http://www.bbc.co.uk) and TAL Contributors (1)
 *
 * (1) TAL Contributors are listed in the AUTHORS file and at
 *     https://github.com/fmtvp/TAL/AUTHORS - please extend this file,
 *     not this notice.
 *
 * @license Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * All rights reserved
 * Please contact us for an alternative licence
 */

(function() {
    // How many milliseconds to give a 'no animation' transition to complete
    var noAnimToleranceMs = 20;

    // The default animation duration in tween.js is 840, so it's reasonable to think we should only need to tick for
    // 840 to get the onComplete callback to be fired. However the callback passed to shifty that invokes onComplete
    // doesn't run until tick 866.666666666667. This seems to be because the Shifty timeoutHandler waits for the
    // animation to complete and it's only on the next tick (as determined by the easing function) that the Shifty stop
    // method is called, and it is that which invokes the callback which invokes onComplete.
    var DEFAULT_ONCOMPLETE_TIMEOUT = 867;


    // jshint newcap: false
    this.StyleTopLeftAnimationTest = AsyncTestCase("StyleTopLeftAnimation");

    this.StyleTopLeftAnimationTest.prototype.setUp = function() {
        this.sandbox = sinon.sandbox.create();
    };

    this.StyleTopLeftAnimationTest.prototype.tearDown = function() {
        this.sandbox.restore();
    };

    this.StyleTopLeftAnimationTest.prototype.getDefaultConfig = function() {
        var config = {
            "modules": {
                "base": "antie/devices/browserdevice",
                "modifiers": [
                    'antie/devices/anim/styletopleft'
                ]
            },
            "input": {
                "map": {}
            },
            "layouts": [
                {
                    "width": 960,
                    "height": 540,
                    "module": "fixtures/layouts/default",
                    "classes": ["browserdevice540p"]
                }
            ],
            "deviceConfigurationKey": "devices-html5-1"
        };
        return config;
    };

    this.StyleTopLeftAnimationTest.prototype.testScrollElementToWithAnim = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div, inner, startTime;
            device = application.getDevice();
            div = device.createContainer("id_mask");
            inner = device.createContainer("id");
            startTime = Date.now();
            device.appendChildElement(div, inner);

            var clock = sinon.useFakeTimers();
            var onComplete = this.sandbox.stub();

            device.scrollElementTo({
                el: div,
                style: div.style,
                to: {
                    left: 100,
                    top: 200
                },
                skipAnim: false,
                onComplete: onComplete
            });

            clock.tick(DEFAULT_ONCOMPLETE_TIMEOUT);

            assertEquals(-100, parseFloat(inner.style.left.replace(/px$/, '')));
            assertEquals(-200, parseFloat(inner.style.top.replace(/px$/, '')));
            assert(onComplete.calledOnce);

            clock.restore();

        }, config);
    };
    this.StyleTopLeftAnimationTest.prototype.testScrollElementToWithAnimNoMovement = function(queue) {
        expectAsserts(1);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div, inner;
            device = application.getDevice();
            div = device.createContainer("id_mask");
            inner = device.createContainer("id");
            device.appendChildElement(div, inner);

            inner.style.top = "200px";
            inner.style.left = "100px";

            var onComplete = this.sandbox.stub();

            device.scrollElementTo({
                el: div,
                style: div.style,
                to: {
                    left: 100,
                    top: 200
                },
                onComplete: onComplete
            });

             assert(onComplete.calledOnce);

        }, config);
    };
    this.StyleTopLeftAnimationTest.prototype.testScrollElementToWithNoAnim = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div, inner, startTime;
            device = application.getDevice();
            div = device.createContainer("id_mask");
            inner = device.createContainer("id");
            startTime = Date.now();
            device.appendChildElement(div, inner);

            var onComplete = this.sandbox.stub();

            device.scrollElementTo({
                el: div,
                style: div.style,
                to: {
                    left: 100,
                    top: 200
                },
                skipAnim: true,
                onComplete: onComplete
            });

            assertEquals(-100, parseFloat(inner.style.left.replace(/px$/, '')));
            assertEquals(-200, parseFloat(inner.style.top.replace(/px$/, '')));
            assert(onComplete.calledOnce);

        }, config);
    };

    /**
     * Test scrollElementTo() skips animation when specified in config.
     */
    this.StyleTopLeftAnimationTest.prototype.testScrollElementToWithNoAnimInConfig = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig(); 
        config.animationDisabled = "true";
        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div, inner, startTime;
            device = application.getDevice();
            div = device.createContainer("id_mask");
            inner = device.createContainer("id");
            startTime = Date.now();
            device.appendChildElement(div, inner);

            var onComplete = this.sandbox.stub();

            device.scrollElementTo({
                el: div,
                style: div.style,
                to: {
                    left: 100,
                    top: 200
                },
                onComplete: onComplete
            });
            assertEquals(-100, parseFloat(inner.style.left.replace(/px$/, '')));
            assertEquals(-200, parseFloat(inner.style.top.replace(/px$/, '')));
            assert(onComplete.calledOnce);

        }, config);
    };


    this.StyleTopLeftAnimationTest.prototype.testMoveElementToWithAnim = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div, startTime;
            device = application.getDevice();
            div = device.createContainer("id");

            var clock = sinon.useFakeTimers();

            var onComplete = this.sandbox.stub();
            device.moveElementTo({
                el: div,
                style: div.style,
                from: {
                    left: 100,
                    top: 200
                },
                to: {
                    left: 100,
                    top: 200
                },
                skipAnim: false,
                onComplete: onComplete
            });

            clock.tick(DEFAULT_ONCOMPLETE_TIMEOUT);

            assertEquals(100, parseFloat(div.style.left.replace(/px$/, '')));
            assertEquals(200, parseFloat(div.style.top.replace(/px$/, '')));
            assert(onComplete.calledOnce);

            clock.restore();
        }, config);
    };

    this.StyleTopLeftAnimationTest.prototype.testMoveElementToWithAnimAndNoDefaultValues = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div;
            device = application.getDevice();
            div = device.createContainer("id");

            var clock = sinon.useFakeTimers();
            var onComplete = this.sandbox.stub();

            device.moveElementTo({
                el: div,
                style: div.style,
                from: {
                    left: div.style.left,
                    top: div.style.top
                },
                to: {
                    left: 100,
                    top: 200
                },
                skipAnim: false,
                onComplete: onComplete
            });

            clock.tick(DEFAULT_ONCOMPLETE_TIMEOUT);

            assertEquals(100, parseFloat(div.style.left.replace(/px$/, '')));
            assertEquals(200, parseFloat(div.style.top.replace(/px$/, '')));
            assert(onComplete.calledOnce);

            clock.restore();

        }, config);
    };

    this.StyleTopLeftAnimationTest.prototype.testHideElementWithAnimAndNoDefaultOpacity = function(queue) {
        expectAsserts(2);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div;
            device = application.getDevice();
            div = device.createContainer("id");

            var clock = sinon.useFakeTimers();
            var onComplete = this.sandbox.stub();

            device.hideElement({
                el: div,
                style: div.style,
                from: {
                    opacity: div.style.opacity
                },
                to: {
                    opacity: 0
                },
                skipAnim: false,
                onComplete: onComplete
            });

            clock.tick(DEFAULT_ONCOMPLETE_TIMEOUT);

            assertEquals(0, parseFloat(div.style.opacity));
            assert(onComplete.calledOnce);

            clock.restore();

        }, config);
    };

    /**
     * This test is designed to icolate an edge case which existed in the framework in which if an element is shown
     * and hidden without an opacity value set the animation fails
     * @param queue
     */
    this.StyleTopLeftAnimationTest.prototype.testShowAndHideElementToWithAnimAndNoDefaultOpacity = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div;
            device = application.getDevice();
            div = device.createContainer("id");

            queue.call("Wait for tween", function(callbacks) {
                var tweenSpy, hideElement, showElementonComplete, hideElementonComplete;
                tweenSpy = this.sandbox.spy(device, '_tween');

                hideElement = function() {
                    device.hideElement({
                        el: div,
                        style: div.style,
                        from: {
                            opacity: div.style.opacity
                        },
                        to: {
                            opacity: 0
                        },
                        skipAnim: false,
                        onComplete: hideElementonComplete
                    });
                };

                showElementonComplete = callbacks.add(function() {
                    assertEquals(1, parseFloat(div.style.opacity));
                    hideElement();
                });

                hideElementonComplete = callbacks.add(function() {
                    assertEquals(0, parseFloat(div.style.opacity));
                });

                device.showElement({
                    el: div,
                    style: div.style,
                    from: {
                        opacity: div.style.opacity
                    },
                    to: {
                        opacity: 1
                    },
                    skipAnim: false,
                    onComplete: showElementonComplete
                });
                assert(tweenSpy.called);
            });
        }, config);
    };


    this.StyleTopLeftAnimationTest.prototype.testMoveElementToWithNoLeftValue = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div;
            device = application.getDevice();
            div = device.createContainer("id");

            queue.call("Wait for tween", function(callbacks) {
                var tweenSpy, onComplete;
                tweenSpy = this.sandbox.spy(device, '_tween');

                onComplete = callbacks.add(function() {
                    assertEquals(0, parseFloat(div.style.left.replace(/px$/, '')));
                    assertEquals(200, parseFloat(div.style.top.replace(/px$/, '')));<commit_msg>Replaced queue.call test with Jasmine adapter compatible version.<commit_after>/**
 * @preserve Copyright (c) 2013 British Broadcasting Corporation
 * (http://www.bbc.co.uk) and TAL Contributors (1)
 *
 * (1) TAL Contributors are listed in the AUTHORS file and at
 *     https://github.com/fmtvp/TAL/AUTHORS - please extend this file,
 *     not this notice.
 *
 * @license Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * All rights reserved
 * Please contact us for an alternative licence
 */

(function() {
    // How many milliseconds to give a 'no animation' transition to complete
    var noAnimToleranceMs = 20;

    // The default animation duration in tween.js is 840, so it's reasonable to think we should only need to tick for
    // 840 to get the onComplete callback to be fired. However the callback passed to shifty that invokes onComplete
    // doesn't run until tick 866.666666666667. This seems to be because the Shifty timeoutHandler waits for the
    // animation to complete and it's only on the next tick (as determined by the easing function) that the Shifty stop
    // method is called, and it is that which invokes the callback which invokes onComplete.
    var DEFAULT_ONCOMPLETE_TIMEOUT = 867;


    // jshint newcap: false
    this.StyleTopLeftAnimationTest = AsyncTestCase("StyleTopLeftAnimation");

    this.StyleTopLeftAnimationTest.prototype.setUp = function() {
        this.sandbox = sinon.sandbox.create();
    };

    this.StyleTopLeftAnimationTest.prototype.tearDown = function() {
        this.sandbox.restore();
    };

    this.StyleTopLeftAnimationTest.prototype.getDefaultConfig = function() {
        var config = {
            "modules": {
                "base": "antie/devices/browserdevice",
                "modifiers": [
                    'antie/devices/anim/styletopleft'
                ]
            },
            "input": {
                "map": {}
            },
            "layouts": [
                {
                    "width": 960,
                    "height": 540,
                    "module": "fixtures/layouts/default",
                    "classes": ["browserdevice540p"]
                }
            ],
            "deviceConfigurationKey": "devices-html5-1"
        };
        return config;
    };

    this.StyleTopLeftAnimationTest.prototype.testScrollElementToWithAnim = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div, inner, startTime;
            device = application.getDevice();
            div = device.createContainer("id_mask");
            inner = device.createContainer("id");
            startTime = Date.now();
            device.appendChildElement(div, inner);

            var clock = sinon.useFakeTimers();
            var onComplete = this.sandbox.stub();

            device.scrollElementTo({
                el: div,
                style: div.style,
                to: {
                    left: 100,
                    top: 200
                },
                skipAnim: false,
                onComplete: onComplete
            });

            clock.tick(DEFAULT_ONCOMPLETE_TIMEOUT);

            assertEquals(-100, parseFloat(inner.style.left.replace(/px$/, '')));
            assertEquals(-200, parseFloat(inner.style.top.replace(/px$/, '')));
            assert(onComplete.calledOnce);

            clock.restore();

        }, config);
    };
    this.StyleTopLeftAnimationTest.prototype.testScrollElementToWithAnimNoMovement = function(queue) {
        expectAsserts(1);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div, inner;
            device = application.getDevice();
            div = device.createContainer("id_mask");
            inner = device.createContainer("id");
            device.appendChildElement(div, inner);

            inner.style.top = "200px";
            inner.style.left = "100px";

            var onComplete = this.sandbox.stub();

            device.scrollElementTo({
                el: div,
                style: div.style,
                to: {
                    left: 100,
                    top: 200
                },
                onComplete: onComplete
            });

             assert(onComplete.calledOnce);

        }, config);
    };
    this.StyleTopLeftAnimationTest.prototype.testScrollElementToWithNoAnim = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div, inner, startTime;
            device = application.getDevice();
            div = device.createContainer("id_mask");
            inner = device.createContainer("id");
            startTime = Date.now();
            device.appendChildElement(div, inner);

            var onComplete = this.sandbox.stub();

            device.scrollElementTo({
                el: div,
                style: div.style,
                to: {
                    left: 100,
                    top: 200
                },
                skipAnim: true,
                onComplete: onComplete
            });

            assertEquals(-100, parseFloat(inner.style.left.replace(/px$/, '')));
            assertEquals(-200, parseFloat(inner.style.top.replace(/px$/, '')));
            assert(onComplete.calledOnce);

        }, config);
    };

    /**
     * Test scrollElementTo() skips animation when specified in config.
     */
    this.StyleTopLeftAnimationTest.prototype.testScrollElementToWithNoAnimInConfig = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig(); 
        config.animationDisabled = "true";
        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div, inner, startTime;
            device = application.getDevice();
            div = device.createContainer("id_mask");
            inner = device.createContainer("id");
            startTime = Date.now();
            device.appendChildElement(div, inner);

            var onComplete = this.sandbox.stub();

            device.scrollElementTo({
                el: div,
                style: div.style,
                to: {
                    left: 100,
                    top: 200
                },
                onComplete: onComplete
            });
            assertEquals(-100, parseFloat(inner.style.left.replace(/px$/, '')));
            assertEquals(-200, parseFloat(inner.style.top.replace(/px$/, '')));
            assert(onComplete.calledOnce);

        }, config);
    };


    this.StyleTopLeftAnimationTest.prototype.testMoveElementToWithAnim = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div, startTime;
            device = application.getDevice();
            div = device.createContainer("id");

            var clock = sinon.useFakeTimers();

            var onComplete = this.sandbox.stub();
            device.moveElementTo({
                el: div,
                style: div.style,
                from: {
                    left: 100,
                    top: 200
                },
                to: {
                    left: 100,
                    top: 200
                },
                skipAnim: false,
                onComplete: onComplete
            });

            clock.tick(DEFAULT_ONCOMPLETE_TIMEOUT);

            assertEquals(100, parseFloat(div.style.left.replace(/px$/, '')));
            assertEquals(200, parseFloat(div.style.top.replace(/px$/, '')));
            assert(onComplete.calledOnce);

            clock.restore();
        }, config);
    };

    this.StyleTopLeftAnimationTest.prototype.testMoveElementToWithAnimAndNoDefaultValues = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div;
            device = application.getDevice();
            div = device.createContainer("id");

            var clock = sinon.useFakeTimers();
            var onComplete = this.sandbox.stub();

            device.moveElementTo({
                el: div,
                style: div.style,
                from: {
                    left: div.style.left,
                    top: div.style.top
                },
                to: {
                    left: 100,
                    top: 200
                },
                skipAnim: false,
                onComplete: onComplete
            });

            clock.tick(DEFAULT_ONCOMPLETE_TIMEOUT);

            assertEquals(100, parseFloat(div.style.left.replace(/px$/, '')));
            assertEquals(200, parseFloat(div.style.top.replace(/px$/, '')));
            assert(onComplete.calledOnce);

            clock.restore();

        }, config);
    };

    this.StyleTopLeftAnimationTest.prototype.testHideElementWithAnimAndNoDefaultOpacity = function(queue) {
        expectAsserts(2);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div;
            device = application.getDevice();
            div = device.createContainer("id");

            var clock = sinon.useFakeTimers();
            var onComplete = this.sandbox.stub();

            device.hideElement({
                el: div,
                style: div.style,
                from: {
                    opacity: div.style.opacity
                },
                to: {
                    opacity: 0
                },
                skipAnim: false,
                onComplete: onComplete
            });

            clock.tick(DEFAULT_ONCOMPLETE_TIMEOUT);

            assertEquals(0, parseFloat(div.style.opacity));
            assert(onComplete.calledOnce);

            clock.restore();

        }, config);
    };

    /**
     * This test is designed to icolate an edge case which existed in the framework in which if an element is shown
     * and hidden without an opacity value set the animation fails
     * @param queue
     */
    this.StyleTopLeftAnimationTest.prototype.testShowAndHideElementToWithAnimAndNoDefaultOpacity = function(queue) {
        expectAsserts(4);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div;
            device = application.getDevice();
            div = device.createContainer("id");


            var clock = sinon.useFakeTimers();
            var showComplete = this.sandbox.stub();

            device.showElement({
                el: div,
                style: div.style,
                from: {
                    opacity: div.style.opacity
                },
                to: {
                    opacity: 1
                },
                skipAnim: false,
                onComplete: showComplete
            });

            clock.tick(DEFAULT_ONCOMPLETE_TIMEOUT);

            assert(showComplete.calledOnce);
            assertEquals(1, parseFloat(div.style.opacity));

            var hideComplete = this.sandbox.stub();

            device.hideElement({
                el: div,
                style: div.style,
                from: {
                    opacity: div.style.opacity
                },
                to: {
                    opacity: 0
                },
                skipAnim: false,
                onComplete: hideComplete
            });

            clock.tick(DEFAULT_ONCOMPLETE_TIMEOUT);

            assert(hideComplete.calledOnce);
            assertEquals(0, parseFloat(div.style.opacity));

            clock.restore();

        }, config);
    };


    this.StyleTopLeftAnimationTest.prototype.testMoveElementToWithNoLeftValue = function(queue) {
        expectAsserts(3);

        var config = this.getDefaultConfig();

        queuedApplicationInit(queue, 'lib/mockapplication', [], function(application) {
            var device, div;
            device = application.getDevice();
            div = device.createContainer("id");

            queue.call("Wait for tween", function(callbacks) {
                var tweenSpy, onComplete;
                tweenSpy = this.sandbox.spy(device, '_tween');

                onComplete = callbacks.add(function() {
                    assertEquals(0, parseFloat(div.style.left.replace(/px$/, '')));
                    assertEquals(200, parseFloat(div.style.top.replace(/px$/, '')));
{'fraction_non_alphanumeric': 0.10425067515075284, 'fraction_numerical': 0.01065443379823166, 'mean_word_length': 1.6645638245441103, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1787220', 'n_tokens_mistral': 7033, 'n_tokens_neox': 6471, 'n_words': 1475}