{"size": 5837, "ext": "js", "max_stars_repo_path": "src/aui-image-viewer/tests/unit/js/aui-image-viewer-slideshow-tests.js", "max_stars_repo_name": "dsanz/alloy-ui", "max_stars_repo_stars_event_min_datetime": "2015-01-05T18:02:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-17T07:03:30.000Z", "max_issues_repo_path": "src/aui-image-viewer/tests/unit/js/aui-image-viewer-slideshow-tests.js", "max_issues_repo_name": "dsanz/alloy-ui", "max_issues_repo_issues_event_min_datetime": "2015-01-08T01:00:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T03:38:49.000Z", "max_forks_repo_path": "src/aui-image-viewer/tests/unit/js/aui-image-viewer-slideshow-tests.js", "max_forks_repo_name": "dsanz/alloy-ui", "max_forks_repo_forks_event_min_datetime": "2015-01-08T15:11:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T01:44:05.000Z"}
{"max_stars_count": 792, "max_issues_count": 137, "max_forks_count": 461, "avg_line_length": 32.7921348315, "max_line_length": 115, "alphanum_fraction": 0.4997430187}
YUI.add('aui-image-viewer-slideshow-tests', function(Y) {

    var suite = new Y.Test.Suite('aui-image-viewer-slideshow'),
        ImageViewerWithSlideshow = Y.Base.create(
            'test-slideshow',
            Y.ImageViewerBase, [Y.ImageViewerSlideshow]
        );

    suite.add(new Y.Test.Case({
        name: 'Image Viewer Slideshow Tests',

        tearDown: function() {
            if (this._imageViewer) {
                this._imageViewer.destroy();
            }
        },

        assertPaused: function(callback) {
            var instance = this,
                previousIndex = this._imageViewer.get('currentIndex');

            this.wait(function() {
                Y.Assert.areEqual(
                    previousIndex,
                    instance._imageViewer.get('currentIndex'),
                    'Carousel was paused, so currentIndex should not have been updated'
                );

                callback && callback();
            }, (this._imageViewer.get('imageAnim').duration + this._imageViewer.get('intervalTime')) * 1000 + 100);
        },

        waitForNext: function(callback) {
            var instance = this,
                timeBefore = new Date().getTime();

            this._imageViewer.onceAfter('currentIndexChange', function() {
                instance.resume(function() {
                    callback(Math.round((new Date().getTime() - timeBefore) / 1000));
                });
            });

            this.wait();
        },

        _createImageViewer: function(config) {
            this._imageViewer = new ImageViewerWithSlideshow(Y.merge({
                intervalTime: 1,
                sources: [
                    'assets/lfr-soccer-2.jpg',
                    'assets/lfr-soccer-3.jpg',
                    'assets/lfr-soccer-4.jpg',
                    'assets/lfr-soccer-5.jpg',
                    'assets/lfr-soccer-6.jpg'
                ]
            }, config)).render('#container');
        },

        'should change the interval time': function() {
            var instance = this;

            this._createImageViewer();

            this.waitForNext(function(intervalTime1) {
                Y.Assert.isTrue(
                    intervalTime1 >= 1,
                    'Initial interval time is of at least 1 second'
                );

                instance._imageViewer.set('intervalTime', 2);
                instance.waitForNext(function(intervalTime2) {
                    Y.Assert.isTrue(
                        intervalTime2 >= 2,
                        'Interval time should have been updated to at least 2 seconds'
                    );
                });
            });
        },

        'should play/pause when functions are called': function() {
            var instance = this;

            this._createImageViewer();

            this._imageViewer.pause();

            this.assertPaused(function() {
                instance._imageViewer.play();

                instance.waitForNext(function() {
                    Y.Assert.areEqual(
                        1,
                        instance._imageViewer.get('currentIndex'),
                        'Carousel was resumed, so currentIndex should have been updated to 1'
                    );
                });
            });
        },

        'should play/pause when user clicks the button': function() {
            var instance = this,
                playerButton;

            this._createImageViewer();

            playerButton = this._imageViewer.get('boundingBox').one('.image-viewer-player');
            playerButton.simulate('click');

            this.assertPaused(function() {
                playerButton.simulate('click');

                instance.waitForNext(function() {
                    Y.Assert.areEqual(
                        1,
                        instance._imageViewer.get('currentIndex'),
                        'The viewer was resumed, so currentIndex should have been updated to 1'
                    );
                });
            });
        },

        'should work without a player when requested': function() {
            var playerButton;

            this._createImageViewer({
                showPlayer: false
            });

            playerButton = this._imageViewer.get('boundingBox').one('.image-viewer-player');
            Y.Assert.isNull(playerButton, 'Player should not have been rendered');
        },

        'should show/hide player as requested': function() {
            var playerButton;

            this._createImageViewer({
                showPlayer: false
            });

            this._imageViewer.set('showPlayer', true);

            playerButton = this._imageViewer.get('boundingBox').one('.image-viewer-player');
            Y.Assert.isNotNull(playerButton, 'Player should have been rendered');
            Y.Assert.areNotEqual(
                'none',
                playerButton.getStyle('display'),
                'Player should be visible'
            );

            this._imageViewer.set('showPlayer', false);
            Y.Assert.areEqual(
                'none',
                playerButton.getStyle('display'),
                'Player should have been hidden'
            );

            this._imageViewer.set('showPlayer', true);
            Y.Assert.areNotEqual(
                'none',
                playerButton.getStyle('display'),
                'Player should have been shown'
            );
        },

        'should pause when widget becomes invisible': function() {
            this._createImageViewer();

            this._imageViewer.set('visible', false);
            this.assertPaused();
        }
    }));

    Y.Test.Runner.add(suite);

}, '', {
    requires: ['aui-image-viewer-base', 'aui-image-viewer-slideshow', 'node-event-simulate', 'test']
});
