<commit_before>var jsdom = require('jsdom');
var connect = require('connect');


describe('PageSlider', function () {
    var $;
    var staticServer;
    var slider;

    beforeAll(function () {
        // Start a local server for lib files
        var serveStatic = require('serve-static');
        staticServer = connect().use(serveStatic(__dirname + '/..')).listen(4242);
    });

    beforeEach(function (done) {
        // Create the DOM env
        jsdom.env({
            html: '<html><body></body></html>',
            scripts: [
                'http://localhost:4242/bower_components/jquery/dist/jquery.min.js',
                'http://localhost:4242/lib/page-slider.min.js',
            ],
            done: function (err, window) {
                if (err) console.log(err);
                $ = window.jQuery;
                PageSlider = window.PageSlider;

                slider = new PageSlider($('body'));
                done();
            }
        });
    });

    describe('once instantiated', function() {
        it('should add inline style to the container', function () {

            expect(slider.$container.css('height')).toEqual('100%');
            expect(slider.$container.css('width')).toEqual('100%');
            expect(slider.$container.css('overflow')).toEqual('hidden');
        });
    });

    describe('when the first page is slided in', function() {
        it('should call callbacks synchronously', function () {

            var beforeCalled = false;
            var afterCalled = false;

            slider.slidePageFrom($('<div>'), 'left', {
                beforeTransition: function () {
                    beforeCalled = true;
                },
                afterTransition: function () {
                    afterCalled = true;
                },
            });

            expect(beforeCalled && afterCalled).toBe(true);
        });
    });

    describe('on page slide (except the first one)', function () {

        beforeEach(function () {
            // Force the first page slide
            slider.slidePage($('<div>'));
        });

        it('should call both callbacks', function (done) {

            var beforeCalled = false;

            slider.slidePage($('<div>'), {
                beforeTransition: function () {
                    beforeCalled = true;
                },
                afterTransition: function () {
                    expect(beforeCalled).toBe(true);
                    done();
                },
            });
        });

        describe('when transition duration is modified', function() {

            beforeEach(function () {
                slider.setTransitionDurationMs(100);
            });

            it('should have modified transition duration', function () {
                expect(slider.transitionDurationMs).toBe(100);
            });

            it('should have transitions that reflect their duration', function (done) {

                var time100ms;
                var time300ms;
                var startTime = (new Date()).getTime();

                slider.slidePageFrom($('<div>'), 'left', {
                    afterTransition: function () {

                        time100ms = (new Date()).getTime() - startTime;

                        slider.setTransitionDurationMs(300);

                        startTime = (new Date()).getTime();

                        slider.slidePageFrom($('<div>'), 'left', {
                            afterTransition: function () {
                                time300ms = (new Date()).getTime() - startTime;
                                expect(time300ms).toBeGreaterThan(time100ms);
                                done();
                            },
                        });
                    },
                });

            });
        });

    });

    describe('when transitions are disabled', function() {

        beforeEach(function () {
            slider.disableTransitions();
        });

        it('should have disabled transitions', function () {
            expect(slider.transitionsEnabled).toBe(false);
        });

        it('should call callbacks synchronously', function () {
            var beforeCalled = false;
            var afterCalled = false;

            // slide in a first page
            slider.slidePage($('<div>'));

            slider.slidePageFrom($('<div>'), 'left', {
                beforeTransition: function () {
                    beforeCalled = true;
                },
                afterTransition: function () {
                    afterCalled = true;
                },
            });

            expect(beforeCalled && afterCalled).toBe(true);
        });
    });


    afterAll(function () {
        staticServer.close();
    });
});<commit_msg>Improve tests structure<commit_after>var jsdom = require('jsdom');
var connect = require('connect');


describe('PageSlider', function () {
    var $;
    var staticServer;
    var slider;

    beforeAll(function () {
        // Start a local server for lib files
        var serveStatic = require('serve-static');
        staticServer = connect().use(serveStatic(__dirname + '/..')).listen(4242);
    });

    beforeEach(function (done) {
        // Create the DOM env
        jsdom.env({
            html: '<html><body></body></html>',
            scripts: [
                'http://localhost:4242/bower_components/jquery/dist/jquery.min.js',
                'http://localhost:4242/lib/page-slider.min.js',
            ],
            done: function (err, window) {
                if (err) console.log(err);
                $ = window.jQuery;
                PageSlider = window.PageSlider;

                slider = new PageSlider($('body'));
                done();
            }
        });
    });

    describe('once instantiated', function() {

        it('should add inline style to the container', function () {
            expect(slider.$container.css('height')).toEqual('100%');
            expect(slider.$container.css('width')).toEqual('100%');
            expect(slider.$container.css('overflow')).toEqual('hidden');
        });

        it('should have a default transition duration of 300ms', function () {
            expect(slider.transitionDurationMs).toEqual(300);
        });
    });

    describe('when the first page is slided in', function() {

        it('should call callbacks synchronously', function () {

            var beforeCalled = false;
            var afterCalled = false;

            slider.slidePageFrom($('<div>'), 'left', {
                beforeTransition: function () {
                    beforeCalled = true;
                },
                afterTransition: function () {
                    afterCalled = true;
                },
            });

            expect(beforeCalled && afterCalled).toBe(true);
        });
    });

    describe('on page slide (except the first one)', function () {

        beforeEach(function () {
            // Force the first page slide
            var defaultTransitionDuration = slider.transitionDurationMs;
            slider.setTransitionDurationMs(0);
            slider.slidePage($('<div>'));
            slider.setTransitionDurationMs(defaultTransitionDuration);
        });

        it('should call both callbacks', function (done) {

            var beforeCalled = false;
            // Reduce transition duration
            slider.setTransitionDurationMs(50);

            slider.slidePage($('<div>'), {
                beforeTransition: function () {
                    beforeCalled = true;
                },
                afterTransition: function () {
                    expect(beforeCalled).toBe(true);
                    done();
                },
            });
        });

        describe('when transition duration is modified', function() {

            beforeEach(function () {
                slider.setTransitionDurationMs(50);
            });

            it('should have modified transition duration', function () {
                expect(slider.transitionDurationMs).toBe(50);
            });

            it('should have transitions that reflect their duration', function (done) {

                var time50ms;
                var time200ms;
                var startTime = (new Date()).getTime();

                slider.slidePageFrom($('<div>'), 'left', {
                    afterTransition: function () {

                        time100ms = (new Date()).getTime() - startTime;

                        slider.setTransitionDurationMs(200);

                        startTime = (new Date()).getTime();

                        slider.slidePageFrom($('<div>'), 'left', {
                            afterTransition: function () {
                                time300ms = (new Date()).getTime() - startTime;
                                expect(time300ms).toBeGreaterThan(time100ms);
                                done();
                            },
                        });
                    },
                });

            });
        });

        describe('when transitions are disabled', function() {

            beforeEach(function () {
                slider.disableTransitions();
            });

            it('should have disabled transitions', function () {
                expect(slider.transitionsEnabled).toBe(false);
            });

            it('should call callbacks synchronously', function () {
                var beforeCalled = false;
                var afterCalled = false;

                // slide in a first page
                slider.slidePage($('<div>'));

                slider.slidePageFrom($('<div>'), 'left', {
                    beforeTransition: function () {
                        beforeCalled = true;
                    },
                    afterTransition: function () {
                        afterCalled = true;
                    },
                });

                expect(beforeCalled && afterCalled).toBe(true);
            });
        });

    });


    afterAll(function () {
        staticServer.close();
    });
});
{'fraction_non_alphanumeric': 0.12788280708700386, 'fraction_numerical': 0.009502128080768089, 'mean_word_length': 1.4294301514787209, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '4087724', 'n_tokens_mistral': 2474, 'n_tokens_neox': 2267, 'n_words': 479}