bootstrap-source/bootstrap-3.0.3/js/tests/unit/carousel.js
changeset 54 0ded9d7748b7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/bootstrap-source/bootstrap-3.0.3/js/tests/unit/carousel.js	Fri Dec 20 22:49:16 2013 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +$(function () {
     1.5 +
     1.6 +    module("carousel")
     1.7 +
     1.8 +      test("should provide no conflict", function () {
     1.9 +        var carousel = $.fn.carousel.noConflict()
    1.10 +        ok(!$.fn.carousel, 'carousel was set back to undefined (org value)')
    1.11 +        $.fn.carousel = carousel
    1.12 +      })
    1.13 +
    1.14 +      test("should be defined on jquery object", function () {
    1.15 +        ok($(document.body).carousel, 'carousel method is defined')
    1.16 +      })
    1.17 +
    1.18 +      test("should return element", function () {
    1.19 +        ok($(document.body).carousel()[0] == document.body, 'document.body returned')
    1.20 +      })
    1.21 +
    1.22 +      test("should not fire sliden when slide is prevented", function () {
    1.23 +        $.support.transition = false
    1.24 +        stop()
    1.25 +        $('<div class="carousel"/>')
    1.26 +          .on('slide.bs.carousel', function (e) {
    1.27 +            e.preventDefault();
    1.28 +            ok(true);
    1.29 +            start();
    1.30 +          })
    1.31 +          .on('slid.bs.carousel', function () {
    1.32 +            ok(false);
    1.33 +          })
    1.34 +          .carousel('next')
    1.35 +      })
    1.36 +
    1.37 +      test("should fire slide event with direction", function () {
    1.38 +        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>'
    1.39 +        $.support.transition = false
    1.40 +        stop()
    1.41 +        $(template).on('slide.bs.carousel', function (e) {
    1.42 +          e.preventDefault()
    1.43 +          ok(e.direction)
    1.44 +          ok(e.direction === 'right' || e.direction === 'left')
    1.45 +          start()
    1.46 +        }).carousel('next')
    1.47 +      })
    1.48 +
    1.49 +      test("should fire slide event with relatedTarget", function () {
    1.50 +        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>'
    1.51 +        $.support.transition = false
    1.52 +        stop()
    1.53 +        $(template)
    1.54 +          .on('slide.bs.carousel', function (e) {
    1.55 +            e.preventDefault();
    1.56 +            ok(e.relatedTarget);
    1.57 +            ok($(e.relatedTarget).hasClass('item'));
    1.58 +            start();
    1.59 +          })
    1.60 +          .carousel('next')
    1.61 +      })
    1.62 +
    1.63 +      test("should set interval from data attribute", 4, function () {
    1.64 +        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>');
    1.65 +        template.attr("data-interval", 1814);
    1.66 +
    1.67 +        template.appendTo("body");
    1.68 +        $('[data-slide]').first().click();
    1.69 +        ok($('#myCarousel').data('bs.carousel').options.interval == 1814);
    1.70 +        $('#myCarousel').remove();
    1.71 +
    1.72 +        template.appendTo("body").attr("data-modal", "foobar");
    1.73 +        $('[data-slide]').first().click();
    1.74 +        ok($('#myCarousel').data('bs.carousel').options.interval == 1814, "even if there is an data-modal attribute set");
    1.75 +        $('#myCarousel').remove();
    1.76 +
    1.77 +        template.appendTo("body");
    1.78 +        $('[data-slide]').first().click();
    1.79 +        $('#myCarousel').attr('data-interval', 1860);
    1.80 +        $('[data-slide]').first().click();
    1.81 +        ok($('#myCarousel').data('bs.carousel').options.interval == 1814, "attributes should be read only on intitialization");
    1.82 +        $('#myCarousel').remove();
    1.83 +
    1.84 +        template.attr("data-interval", false);
    1.85 +        template.appendTo("body");
    1.86 +        $('#myCarousel').carousel(1);
    1.87 +        ok($('#myCarousel').data('bs.carousel').options.interval === false, "data attribute has higher priority than default options");
    1.88 +        $('#myCarousel').remove();
    1.89 +      })
    1.90 +})
Impressum Datenschutzerklärung