0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00
Bootstrap/js/tests/unit/carousel.js

88 lines
6.2 KiB
JavaScript
Raw Normal View History

$(function () {
2013-09-18 18:50:02 +02:00
module('carousel')
2013-09-18 18:50:02 +02:00
test('should provide no conflict', function () {
var carousel = $.fn.carousel.noConflict()
ok(!$.fn.carousel, 'carousel was set back to undefined (org value)')
$.fn.carousel = carousel
})
2013-09-18 18:50:02 +02:00
test('should be defined on jquery object', function () {
ok($(document.body).carousel, 'carousel method is defined')
})
2013-09-18 18:50:02 +02:00
test('should return element', function () {
ok($(document.body).carousel()[0] == document.body, 'document.body returned')
})
2013-09-18 18:50:02 +02:00
test('should not fire sliden when slide is prevented', function () {
$.support.transition = false
stop()
$('<div class="carousel"/>')
.on('slide.bs.carousel', function (e) {
e.preventDefault();
ok(true);
start();
})
.on('slid.bs.carousel', function () {
ok(false);
})
.carousel('next')
})
2013-09-18 18:50:02 +02:00
test('should fire slide event with direction', function () {
var template = '<div id="myCarousel" class="carousel slide"><div class="carousel-inner"><div class="item active"><img alt=""><div class="carousel-caption"><h4>{{_i}}First Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img alt=""><div class="carousel-caption"><h4>{{_i}}Second Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img alt=""><div class="carousel-caption"><h4>{{_i}}Third Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div></div><a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a><a class="right carousel-control" href="#myCarousel" data-slide="next">&rsaquo;</a></div>'
$.support.transition = false
stop()
$(template).on('slide.bs.carousel', function (e) {
e.preventDefault()
ok(e.direction)
ok(e.direction === 'right' || e.direction === 'left')
start()
}).carousel('next')
})
2013-09-18 18:50:02 +02:00
test('should fire slide event with relatedTarget', function () {
2012-09-21 01:31:10 +02:00
var template = '<div id="myCarousel" class="carousel slide"><div class="carousel-inner"><div class="item active"><img alt=""><div class="carousel-caption"><h4>{{_i}}First Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img alt=""><div class="carousel-caption"><h4>{{_i}}Second Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img alt=""><div class="carousel-caption"><h4>{{_i}}Third Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div></div><a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a><a class="right carousel-control" href="#myCarousel" data-slide="next">&rsaquo;</a></div>'
$.support.transition = false
stop()
$(template)
.on('slide.bs.carousel', function (e) {
e.preventDefault();
ok(e.relatedTarget);
ok($(e.relatedTarget).hasClass('item'));
start();
})
.carousel('next')
2012-10-16 08:49:01 +02:00
})
2013-09-18 18:50:02 +02:00
test('should set interval from data attribute', 4, function () {
2012-10-15 20:55:32 +02:00
var template = $('<div id="myCarousel" class="carousel slide"> <div class="carousel-inner"> <div class="item active"> <img alt=""> <div class="carousel-caption"> <h4>{{_i}}First Thumbnail label{{/i}}</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> <div class="item"> <img alt=""> <div class="carousel-caption"> <h4>{{_i}}Second Thumbnail label{{/i}}</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> <div class="item"> <img alt=""> <div class="carousel-caption"> <h4>{{_i}}Third Thumbnail label{{/i}}</h4> <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> </div> </div> </div> <a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a> <a class="right carousel-control" href="#myCarousel" data-slide="next">&rsaquo;</a> </div>');
2013-09-18 18:50:02 +02:00
template.attr('data-interval', 1814);
2012-10-16 08:49:01 +02:00
2013-09-18 18:50:02 +02:00
template.appendTo('body');
2012-10-15 20:55:32 +02:00
$('[data-slide]').first().click();
ok($('#myCarousel').data('bs.carousel').options.interval == 1814);
2012-10-15 20:55:32 +02:00
$('#myCarousel').remove();
2013-09-18 18:50:02 +02:00
template.appendTo('body').attr('data-modal', 'foobar');
2012-10-15 20:55:32 +02:00
$('[data-slide]').first().click();
2013-09-18 18:50:02 +02:00
ok($('#myCarousel').data('bs.carousel').options.interval == 1814, 'even if there is an data-modal attribute set');
2012-10-15 20:55:32 +02:00
$('#myCarousel').remove();
2012-10-16 08:49:01 +02:00
2013-09-18 18:50:02 +02:00
template.appendTo('body');
2012-10-15 20:55:32 +02:00
$('[data-slide]').first().click();
$('#myCarousel').attr('data-interval', 1860);
$('[data-slide]').first().click();
2013-09-18 18:50:02 +02:00
ok($('#myCarousel').data('bs.carousel').options.interval == 1814, 'attributes should be read only on intitialization');
2012-10-15 20:55:32 +02:00
$('#myCarousel').remove();
2013-07-24 03:56:00 +02:00
2013-09-18 18:50:02 +02:00
template.attr('data-interval', false);
template.appendTo('body');
2013-07-24 03:56:00 +02:00
$('#myCarousel').carousel(1);
2013-09-18 18:50:02 +02:00
ok($('#myCarousel').data('bs.carousel').options.interval === false, 'data attribute has higher priority than default options');
2013-07-24 03:56:00 +02:00
$('#myCarousel').remove();
2012-10-15 20:55:32 +02:00
})
})