1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333 |
- $(function () {
- 'use strict'
- window.Carousel = typeof bootstrap !== 'undefined' ? bootstrap.Carousel : Carousel
- var originWinPointerEvent = window.PointerEvent
- window.MSPointerEvent = null
- var supportPointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent)
- function clearPointerEvents() {
- window.PointerEvent = null
- }
- function restorePointerEvents() {
- window.PointerEvent = originWinPointerEvent
- }
- var stylesCarousel = [
- '<style>',
- ' .carousel.pointer-event { -ms-touch-action: none; touch-action: none; }',
- '</style>'
- ].join('')
- QUnit.module('carousel plugin')
- QUnit.test('should be defined on jQuery object', function (assert) {
- assert.expect(1)
- assert.ok($(document.body).carousel, 'carousel method is defined')
- })
- QUnit.module('carousel', {
- beforeEach: function () {
- // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
- $.fn.bootstrapCarousel = $.fn.carousel.noConflict()
- },
- afterEach: function () {
- $.fn.carousel = $.fn.bootstrapCarousel
- delete $.fn.bootstrapCarousel
- $('#qunit-fixture').html('')
- }
- })
- QUnit.test('should provide no conflict', function (assert) {
- assert.expect(1)
- assert.strictEqual(typeof $.fn.carousel, 'undefined', 'carousel was set back to undefined (orig value)')
- })
- QUnit.test('should return version', function (assert) {
- assert.expect(1)
- assert.strictEqual(typeof Carousel.VERSION, 'string')
- })
- QUnit.test('should return default parameters', function (assert) {
- assert.expect(1)
- var defaultConfig = Carousel.Default
- assert.strictEqual(defaultConfig.touch, true)
- })
- QUnit.test('should throw explicit error on undefined method', function (assert) {
- assert.expect(1)
- var $el = $('<div/>')
- $el.bootstrapCarousel()
- try {
- $el.bootstrapCarousel('noMethod')
- } catch (err) {
- assert.strictEqual(err.message, 'No method named "noMethod"')
- }
- })
- QUnit.test('should return jquery collection containing the element', function (assert) {
- assert.expect(2)
- var $el = $('<div/>')
- var $carousel = $el.bootstrapCarousel()
- assert.ok($carousel instanceof $, 'returns jquery collection')
- assert.strictEqual($carousel[0], $el[0], 'collection contains element')
- })
- QUnit.test('should type check config options', function (assert) {
- assert.expect(2)
- var message
- var expectedMessage = 'CAROUSEL: Option "interval" provided type "string" but expected type "(number|boolean)".'
- var config = {
- interval: 'fat sux'
- }
- try {
- $('<div/>').bootstrapCarousel(config)
- } catch (err) {
- message = err.message
- }
- assert.ok(message === expectedMessage, 'correct error message')
- config = {
- keyboard: document.createElement('div')
- }
- expectedMessage = 'CAROUSEL: Option "keyboard" provided type "element" but expected type "boolean".'
- try {
- $('<div/>').bootstrapCarousel(config)
- } catch (err) {
- message = err.message
- }
- assert.ok(message === expectedMessage, 'correct error message')
- })
- QUnit.test('should not fire slid when slide is prevented', function (assert) {
- assert.expect(1)
- var done = assert.async()
- $('<div class="carousel"/>')
- .on('slide.bs.carousel', function (e) {
- e.preventDefault()
- assert.ok(true, 'slide event fired')
- done()
- })
- .on('slid.bs.carousel', function () {
- assert.ok(false, 'slid event fired')
- })
- .bootstrapCarousel('next')
- })
- QUnit.test('should reset when slide is prevented', function (assert) {
- assert.expect(6)
- var carouselHTML = '<div id="carousel-example-generic" class="carousel slide">' +
- '<ol class="carousel-indicators">' +
- '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' +
- '<li data-target="#carousel-example-generic" data-slide-to="1"/>' +
- '<li data-target="#carousel-example-generic" data-slide-to="2"/>' +
- '</ol>' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '<div class="carousel-item">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '<div class="carousel-item">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '</div>' +
- '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>' +
- '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>' +
- '</div>'
- var $carousel = $(carouselHTML)
- var done = assert.async()
- $carousel
- .one('slide.bs.carousel', function (e) {
- e.preventDefault()
- setTimeout(function () {
- assert.ok($carousel.find('.carousel-item:nth-child(1)').is('.active'), 'first item still active')
- assert.ok($carousel.find('.carousel-indicators li:nth-child(1)').is('.active'), 'first indicator still active')
- $carousel.bootstrapCarousel('next')
- }, 0)
- })
- .one('slid.bs.carousel', function () {
- setTimeout(function () {
- assert.ok(!$carousel.find('.carousel-item:nth-child(1)').is('.active'), 'first item still active')
- assert.ok(!$carousel.find('.carousel-indicators li:nth-child(1)').is('.active'), 'first indicator still active')
- assert.ok($carousel.find('.carousel-item:nth-child(2)').is('.active'), 'second item active')
- assert.ok($carousel.find('.carousel-indicators li:nth-child(2)').is('.active'), 'second indicator active')
- done()
- }, 0)
- })
- .bootstrapCarousel('next')
- })
- QUnit.test('should fire slide event with direction', function (assert) {
- assert.expect(4)
- var carouselHTML = '<div id="myCarousel" class="carousel slide">' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>First Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Second Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Third Thumbnail label</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">‹</a>' +
- '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' +
- '</div>'
- var $carousel = $(carouselHTML)
- var done = assert.async()
- $carousel
- .one('slide.bs.carousel', function (e) {
- assert.ok(e.direction, 'direction present on next')
- assert.strictEqual(e.direction, 'left', 'direction is left on next')
- $carousel
- .one('slide.bs.carousel', function (e) {
- assert.ok(e.direction, 'direction present on prev')
- assert.strictEqual(e.direction, 'right', 'direction is right on prev')
- done()
- })
- .bootstrapCarousel('prev')
- })
- .bootstrapCarousel('next')
- })
- QUnit.test('should fire slid event with direction', function (assert) {
- assert.expect(4)
- var carouselHTML = '<div id="myCarousel" class="carousel slide">' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>First Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Second Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Third Thumbnail label</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">‹</a>' +
- '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' +
- '</div>'
- var $carousel = $(carouselHTML)
- var done = assert.async()
- $carousel
- .one('slid.bs.carousel', function (e) {
- assert.ok(e.direction, 'direction present on next')
- assert.strictEqual(e.direction, 'left', 'direction is left on next')
- $carousel
- .one('slid.bs.carousel', function (e) {
- assert.ok(e.direction, 'direction present on prev')
- assert.strictEqual(e.direction, 'right', 'direction is right on prev')
- done()
- })
- .bootstrapCarousel('prev')
- })
- .bootstrapCarousel('next')
- })
- QUnit.test('should fire slide event with relatedTarget', function (assert) {
- assert.expect(2)
- var template = '<div id="myCarousel" class="carousel slide">' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>First Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Second Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Third Thumbnail label</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">‹</a>' +
- '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' +
- '</div>'
- var done = assert.async()
- $(template)
- .on('slide.bs.carousel', function (e) {
- assert.ok(e.relatedTarget, 'relatedTarget present')
- assert.ok($(e.relatedTarget).hasClass('carousel-item'), 'relatedTarget has class "item"')
- done()
- })
- .bootstrapCarousel('next')
- })
- QUnit.test('should fire slid event with relatedTarget', function (assert) {
- assert.expect(2)
- var template = '<div id="myCarousel" class="carousel slide">' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>First Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Second Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Third Thumbnail label</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">‹</a>' +
- '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' +
- '</div>'
- var done = assert.async()
- $(template)
- .on('slid.bs.carousel', function (e) {
- assert.ok(e.relatedTarget, 'relatedTarget present')
- assert.ok($(e.relatedTarget).hasClass('carousel-item'), 'relatedTarget has class "item"')
- done()
- })
- .bootstrapCarousel('next')
- })
- QUnit.test('should fire slid and slide events with from and to', function (assert) {
- assert.expect(4)
- var template = '<div id="myCarousel" class="carousel slide">' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>First Thumbnail label</h4>' +
- '</div>' +
- '</div>' +
- '<div class="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Second Thumbnail label</h4>' +
- '</div>' +
- '</div>' +
- '<div class="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Third Thumbnail label</h4>' +
- '</div>' +
- '</div>' +
- '</div>' +
- '<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' +
- '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' +
- '</div>'
- var done = assert.async()
- $(template)
- .on('slid.bs.carousel', function (e) {
- assert.ok(typeof e.from !== 'undefined', 'from present')
- assert.ok(typeof e.to !== 'undefined', 'to present')
- $(this).off()
- done()
- })
- .on('slide.bs.carousel', function (e) {
- assert.ok(typeof e.from !== 'undefined', 'from present')
- assert.ok(typeof e.to !== 'undefined', 'to present')
- $(this).off('slide.bs.carousel')
- })
- .bootstrapCarousel('next')
- })
- QUnit.test('should set interval from data attribute', function (assert) {
- assert.expect(4)
- var templateHTML = '<div id="myCarousel" class="carousel slide">' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>First Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Second Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Third Thumbnail label</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">‹</a>' +
- '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' +
- '</div>'
- var $carousel = $(templateHTML)
- $carousel.attr('data-interval', 1814)
- $carousel.appendTo('body')
- $('[data-slide]').first().trigger('click')
- assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814)
- $carousel.remove()
- $carousel.appendTo('body').attr('data-modal', 'foobar')
- $('[data-slide]').first().trigger('click')
- assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814, 'even if there is an data-modal attribute set')
- $carousel.remove()
- $carousel.appendTo('body')
- $('[data-slide]').first().trigger('click')
- $carousel.attr('data-interval', 1860)
- $('[data-slide]').first().trigger('click')
- assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814, 'attributes should be read only on initialization')
- $carousel.remove()
- $carousel.attr('data-interval', false)
- $carousel.appendTo('body')
- $carousel.bootstrapCarousel(1)
- assert.strictEqual($carousel.data('bs.carousel')._config.interval, false, 'data attribute has higher priority than default options')
- $carousel.remove()
- })
- QUnit.test('should set interval from data attribute on individual carousel-item', function (assert) {
- assert.expect(2)
- var templateHTML = '<div id="myCarousel" class="carousel slide" data-interval="1814">' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active" data-interval="2814">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>First Thumbnail label</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="carousel-item" data-interval="3814">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Second Thumbnail label</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="carousel-item">' +
- '<img alt="">' +
- '<div class="carousel-caption">' +
- '<h4>Third Thumbnail label</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">‹</a>' +
- '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' +
- '</div>'
- var $carousel = $(templateHTML)
- $carousel.appendTo('body')
- $carousel.bootstrapCarousel(1)
- assert.strictEqual($carousel.data('bs.carousel')._config.interval, 3814)
- $carousel.remove()
- $carousel.appendTo('body')
- $carousel.bootstrapCarousel(2)
- assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814, 'reverts to default interval if no data-interval is set')
- $carousel.remove()
- })
- QUnit.test('should skip over non-items when using item indices', function (assert) {
- assert.expect(2)
- var templateHTML = '<div id="myCarousel" class="carousel" data-interval="1814">' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active">' +
- '<img alt="">' +
- '</div>' +
- '<script type="text/x-metamorph" id="thingy"/>' +
- '<div class="carousel-item">' +
- '<img alt="">' +
- '</div>' +
- '<div class="carousel-item">' +
- '</div>' +
- '</div>' +
- '</div>'
- var $template = $(templateHTML)
- $template.bootstrapCarousel()
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active')
- $template.bootstrapCarousel(1)
- assert.strictEqual($template.find('.carousel-item')[1], $template.find('.active')[0], 'second item active')
- })
- QUnit.test('should skip over non-items when using next/prev methods', function (assert) {
- assert.expect(2)
- var templateHTML = '<div id="myCarousel" class="carousel" data-interval="1814">' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active">' +
- '<img alt="">' +
- '</div>' +
- '<script type="text/x-metamorph" id="thingy"/>' +
- '<div class="carousel-item">' +
- '<img alt="">' +
- '</div>' +
- '<div class="carousel-item">' +
- '</div>' +
- '</div>' +
- '</div>'
- var $template = $(templateHTML)
- $template.bootstrapCarousel()
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active')
- $template.bootstrapCarousel('next')
- assert.strictEqual($template.find('.carousel-item')[1], $template.find('.active')[0], 'second item active')
- })
- QUnit.test('should go to previous item if left arrow key is pressed', function (assert) {
- assert.expect(2)
- var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' +
- '<div class="carousel-inner">' +
- '<div id="first" class="carousel-item">' +
- '<img alt="">' +
- '</div>' +
- '<div id="second" class="carousel-item active">' +
- '<img alt="">' +
- '</div>' +
- '<div id="third" class="carousel-item">' +
- '<img alt="">' +
- '</div>' +
- '</div>' +
- '</div>'
- var $template = $(templateHTML)
- $template.bootstrapCarousel()
- assert.strictEqual($template.find('.carousel-item')[1], $template.find('.active')[0], 'second item active')
- $template.trigger($.Event('keydown', {
- which: 37
- }))
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active')
- })
- QUnit.test('should go to next item if right arrow key is pressed', function (assert) {
- assert.expect(2)
- var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' +
- '<div class="carousel-inner">' +
- '<div id="first" class="carousel-item active">' +
- '<img alt="">' +
- '</div>' +
- '<div id="second" class="carousel-item">' +
- '<img alt="">' +
- '</div>' +
- '<div id="third" class="carousel-item">' +
- '<img alt="">' +
- '</div>' +
- '</div>' +
- '</div>'
- var $template = $(templateHTML)
- $template.bootstrapCarousel()
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active')
- $template.trigger($.Event('keydown', {
- which: 39
- }))
- assert.strictEqual($template.find('.carousel-item')[1], $template.find('.active')[0], 'second item active')
- })
- QUnit.test('should not prevent keydown if key is not ARROW_LEFT or ARROW_RIGHT', function (assert) {
- assert.expect(2)
- var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' +
- '<div class="carousel-inner">' +
- '<div id="first" class="carousel-item active">' +
- '<img alt="">' +
- '</div>' +
- '</div>' +
- '</div>'
- var $template = $(templateHTML)
- $template.bootstrapCarousel()
- var done = assert.async()
- var eventArrowDown = $.Event('keydown', {
- which: 40
- })
- var eventArrowUp = $.Event('keydown', {
- which: 38
- })
- $template.one('keydown', function (event) {
- assert.strictEqual(event.isDefaultPrevented(), false)
- })
- $template.trigger(eventArrowDown)
- $template.one('keydown', function (event) {
- assert.strictEqual(event.isDefaultPrevented(), false)
- done()
- })
- $template.trigger(eventArrowUp)
- })
- QUnit.test('should support disabling the keyboard navigation', function (assert) {
- assert.expect(3)
- var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false" data-keyboard="false">' +
- '<div class="carousel-inner">' +
- '<div id="first" class="carousel-item active">' +
- '<img alt="">' +
- '</div>' +
- '<div id="second" class="carousel-item">' +
- '<img alt="">' +
- '</div>' +
- '<div id="third" class="carousel-item">' +
- '<img alt="">' +
- '</div>' +
- '</div>' +
- '</div>'
- var $template = $(templateHTML)
- $template.bootstrapCarousel()
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active')
- $template.trigger($.Event('keydown', {
- which: 39
- }))
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after right arrow press')
- $template.trigger($.Event('keydown', {
- which: 37
- }))
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after left arrow press')
- })
- QUnit.test('should ignore keyboard events within <input>s and <textarea>s', function (assert) {
- assert.expect(7)
- var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' +
- '<div class="carousel-inner">' +
- '<div id="first" class="carousel-item active">' +
- '<img alt="">' +
- '<input type="text" id="in-put">' +
- '<textarea id="text-area"></textarea>' +
- '</div>' +
- '<div id="second" class="carousel-item">' +
- '<img alt="">' +
- '</div>' +
- '<div id="third" class="carousel-item">' +
- '<img alt="">' +
- '</div>' +
- '</div>' +
- '</div>'
- var $template = $(templateHTML)
- var $input = $template.find('#in-put')
- var $textarea = $template.find('#text-area')
- assert.strictEqual($input.length, 1, 'found <input>')
- assert.strictEqual($textarea.length, 1, 'found <textarea>')
- $template.bootstrapCarousel()
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active')
- $input.trigger($.Event('keydown', {
- which: 39
- }))
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after right arrow press in <input>')
- $input.trigger($.Event('keydown', {
- which: 37
- }))
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after left arrow press in <input>')
- $textarea.trigger($.Event('keydown', {
- which: 39
- }))
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after right arrow press in <textarea>')
- $textarea.trigger($.Event('keydown', {
- which: 37
- }))
- assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after left arrow press in <textarea>')
- })
- QUnit.test('should wrap around from end to start when wrap option is true', function (assert) {
- assert.expect(3)
- var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="true">' +
- '<ol class="carousel-indicators">' +
- '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' +
- '<li data-target="#carousel-example-generic" data-slide-to="1"/>' +
- '<li data-target="#carousel-example-generic" data-slide-to="2"/>' +
- '</ol>' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active" id="one">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '<div class="carousel-item" id="two">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '<div class="carousel-item" id="three">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '</div>' +
- '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>' +
- '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>' +
- '</div>'
- var $carousel = $(carouselHTML)
- var getActiveId = function () {
- return $carousel.find('.carousel-item.active').attr('id')
- }
- var done = assert.async()
- $carousel
- .one('slid.bs.carousel', function () {
- assert.strictEqual(getActiveId(), 'two', 'carousel slid from 1st to 2nd slide')
- $carousel
- .one('slid.bs.carousel', function () {
- assert.strictEqual(getActiveId(), 'three', 'carousel slid from 2nd to 3rd slide')
- $carousel
- .one('slid.bs.carousel', function () {
- assert.strictEqual(getActiveId(), 'one', 'carousel wrapped around and slid from 3rd to 1st slide')
- done()
- })
- .bootstrapCarousel('next')
- })
- .bootstrapCarousel('next')
- })
- .bootstrapCarousel('next')
- })
- QUnit.test('should wrap around from start to end when wrap option is true', function (assert) {
- assert.expect(1)
- var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="true">' +
- '<ol class="carousel-indicators">' +
- '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' +
- '<li data-target="#carousel-example-generic" data-slide-to="1"/>' +
- '<li data-target="#carousel-example-generic" data-slide-to="2"/>' +
- '</ol>' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active" id="one">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '<div class="carousel-item" id="two">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '<div class="carousel-item" id="three">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '</div>' +
- '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>' +
- '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>' +
- '</div>'
- var $carousel = $(carouselHTML)
- var done = assert.async()
- $carousel
- .on('slid.bs.carousel', function () {
- assert.strictEqual($carousel.find('.carousel-item.active').attr('id'), 'three', 'carousel wrapped around and slid from 1st to 3rd slide')
- done()
- })
- .bootstrapCarousel('prev')
- })
- QUnit.test('should stay at the end when the next method is called and wrap is false', function (assert) {
- assert.expect(3)
- var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="false">' +
- '<ol class="carousel-indicators">' +
- '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' +
- '<li data-target="#carousel-example-generic" data-slide-to="1"/>' +
- '<li data-target="#carousel-example-generic" data-slide-to="2"/>' +
- '</ol>' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active" id="one">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '<div class="carousel-item" id="two">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '<div class="carousel-item" id="three">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '</div>' +
- '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>' +
- '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>' +
- '</div>'
- var $carousel = $(carouselHTML)
- var getActiveId = function () {
- return $carousel.find('.carousel-item.active').attr('id')
- }
- var done = assert.async()
- $carousel
- .one('slid.bs.carousel', function () {
- assert.strictEqual(getActiveId(), 'two', 'carousel slid from 1st to 2nd slide')
- $carousel
- .one('slid.bs.carousel', function () {
- assert.strictEqual(getActiveId(), 'three', 'carousel slid from 2nd to 3rd slide')
- $carousel
- .one('slid.bs.carousel', function () {
- assert.ok(false, 'carousel slid when it should not have slid')
- })
- .bootstrapCarousel('next')
- assert.strictEqual(getActiveId(), 'three', 'carousel did not wrap around and stayed on 3rd slide')
- done()
- })
- .bootstrapCarousel('next')
- })
- .bootstrapCarousel('next')
- })
- QUnit.test('should stay at the start when the prev method is called and wrap is false', function (assert) {
- assert.expect(1)
- var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="false">' +
- '<ol class="carousel-indicators">' +
- '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' +
- '<li data-target="#carousel-example-generic" data-slide-to="1"/>' +
- '<li data-target="#carousel-example-generic" data-slide-to="2"/>' +
- '</ol>' +
- '<div class="carousel-inner">' +
- '<div class="carousel-item active" id="one">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '<div class="carousel-item" id="two">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '<div class="carousel-item" id="three">' +
- '<div class="carousel-caption"/>' +
- '</div>' +
- '</div>' +
- '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>' +
- '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>' +
- '</div>'
- var $carousel = $(carouselHTML)
- $carousel
- .on('slid.bs.carousel', function () {
- assert.ok(false, 'carousel slid when it should not have slid')
- })
- .bootstrapCarousel('prev')
- assert.strictEqual($carousel.find('.carousel-item.active').attr('id'), 'one', 'carousel did not wrap around and stayed on 1st slide')
- })
- QUnit.test('should not prevent keydown for inputs and textareas', function (assert) {
- assert.expect(2)
- var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' +
- '<div class="carousel-inner">' +
- '<div id="first" class="carousel-item">' +
- '<input type="text" id="inputText" />' +
- '</div>' +
- '<div id="second" class="carousel-item active">' +
- '<textarea id="txtArea"></textarea>' +
- '</div>' +
- '</div>' +
- '</div>'
- var $template = $(templateHTML)
- var done = assert.async()
- $template.appendTo('#qunit-fixture')
- var $inputText = $template.find('#inputText')
- var $textArea = $template.find('#txtArea')
- $template.bootstrapCarousel()
- var eventKeyDown = $.Event('keydown', {
- which: 65
- }) // 65 for "a"
- $inputText.on('keydown', function (event) {
- assert.strictEqual(event.isDefaultPrevented(), false)
- })
- $inputText.trigger(eventKeyDown)
- $textArea.on('keydown', function (event) {
- assert.strictEqual(event.isDefaultPrevented(), false)
- done()
- })
- $textArea.trigger(eventKeyDown)
- })
- QUnit.test('should not go to the next item when the carousel is not visible', function (assert) {
- assert.expect(2)
- var done = assert.async()
- var html = '<div id="myCarousel" class="carousel slide" data-interval="50" style="display: none;">' +
- ' <div class="carousel-inner">' +
- ' <div id="firstItem" class="carousel-item active">' +
- ' <img alt="">' +
- ' </div>' +
- ' <div class="carousel-item">' +
- ' <img alt="">' +
- ' </div>' +
- ' <div class="carousel-item">' +
- ' <img alt="">' +
- ' </div>' +
- ' <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' +
- ' <a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' +
- '</div>'
- var $html = $(html)
- $html
- .appendTo('#qunit-fixture')
- .bootstrapCarousel()
- var $firstItem = $('#firstItem')
- setTimeout(function () {
- assert.ok($firstItem.hasClass('active'))
- $html
- .bootstrapCarousel('dispose')
- .attr('style', 'visibility: hidden;')
- .bootstrapCarousel()
- setTimeout(function () {
- assert.ok($firstItem.hasClass('active'))
- done()
- }, 80)
- }, 80)
- })
- QUnit.test('should not go to the next item when the parent of the carousel is not visible', function (assert) {
- assert.expect(2)
- var done = assert.async()
- var html = '<div id="parent" style="display: none;">' +
- ' <div id="myCarousel" class="carousel slide" data-interval="50" style="display: none;">' +
- ' <div class="carousel-inner">' +
- ' <div id="firstItem" class="carousel-item active">' +
- ' <img alt="">' +
- ' </div>' +
- ' <div class="carousel-item">' +
- ' <img alt="">' +
- ' </div>' +
- ' <div class="carousel-item">' +
- ' <img alt="">' +
- ' </div>' +
- ' <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' +
- ' <a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' +
- ' </div>' +
- '</div>'
- var $html = $(html)
- $html.appendTo('#qunit-fixture')
- var $parent = $html.find('#parent')
- var $carousel = $html.find('#myCarousel')
- $carousel.bootstrapCarousel()
- var $firstItem = $('#firstItem')
- setTimeout(function () {
- assert.ok($firstItem.hasClass('active'))
- $carousel.bootstrapCarousel('dispose')
- $parent.attr('style', 'visibility: hidden;')
- $carousel.bootstrapCarousel()
- setTimeout(function () {
- assert.ok($firstItem.hasClass('active'))
- done()
- }, 80)
- }, 80)
- })
- QUnit.test('should allow swiperight and call prev with pointer events', function (assert) {
- if (!supportPointerEvent) {
- assert.expect(0)
- return
- }
- document.documentElement.ontouchstart = $.noop
- Simulator.setType('pointer')
- assert.expect(3)
- var $styles = $(stylesCarousel).appendTo('head')
- var done = assert.async()
- var carouselHTML =
- '<div class="carousel" data-interval="false">' +
- ' <div class="carousel-inner">' +
- ' <div id="item" class="carousel-item">' +
- ' <img alt="">' +
- ' </div>' +
- ' <div class="carousel-item active">' +
- ' <img alt="">' +
- ' </div>' +
- ' </div>' +
- '</div>'
- var $carousel = $(carouselHTML).appendTo('#qunit-fixture')
- var $item = $('#item')
- $carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
- var spy = sinon.spy(carousel, 'prev')
- $carousel.one('slid.bs.carousel', function () {
- assert.ok(true, 'slid event fired')
- assert.ok($item.hasClass('active'))
- assert.ok(spy.called)
- $styles.remove()
- delete document.documentElement.ontouchstart
- done()
- })
- Simulator.gestures.swipe($carousel[0], {
- deltaX: 300,
- deltaY: 0
- })
- })
- QUnit.test('should allow swiperight and call prev with touch events', function (assert) {
- Simulator.setType('touch')
- clearPointerEvents()
- assert.expect(3)
- var done = assert.async()
- document.documentElement.ontouchstart = $.noop
- var carouselHTML =
- '<div class="carousel" data-interval="false">' +
- ' <div class="carousel-inner">' +
- ' <div id="item" class="carousel-item">' +
- ' <img alt="">' +
- ' </div>' +
- ' <div class="carousel-item active">' +
- ' <img alt="">' +
- ' </div>' +
- ' </div>' +
- '</div>'
- var $carousel = $(carouselHTML)
- $carousel.appendTo('#qunit-fixture')
- var $item = $('#item')
- $carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
- var spy = sinon.spy(carousel, 'prev')
- $carousel.one('slid.bs.carousel', function () {
- assert.ok(true, 'slid event fired')
- assert.ok($item.hasClass('active'))
- assert.ok(spy.called)
- delete document.documentElement.ontouchstart
- restorePointerEvents()
- done()
- })
- Simulator.gestures.swipe($carousel[0], {
- deltaX: 300,
- deltaY: 0
- })
- })
- QUnit.test('should allow swipeleft and call next with pointer events', function (assert) {
- if (!supportPointerEvent) {
- assert.expect(0)
- return
- }
- document.documentElement.ontouchstart = $.noop
- assert.expect(3)
- Simulator.setType('pointer')
- var $styles = $(stylesCarousel).appendTo('head')
- var done = assert.async()
- var carouselHTML =
- '<div class="carousel" data-interval="false">' +
- ' <div class="carousel-inner">' +
- ' <div id="item" class="carousel-item active">' +
- ' <img alt="">' +
- ' </div>' +
- ' <div class="carousel-item">' +
- ' <img alt="">' +
- ' </div>' +
- ' </div>' +
- '</div>'
- var $carousel = $(carouselHTML)
- $carousel.appendTo('#qunit-fixture')
- var $item = $('#item')
- $carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
- var spy = sinon.spy(carousel, 'next')
- $carousel.one('slid.bs.carousel', function () {
- assert.ok(true, 'slid event fired')
- assert.ok(!$item.hasClass('active'))
- assert.ok(spy.called)
- $styles.remove()
- delete document.documentElement.ontouchstart
- done()
- })
- Simulator.gestures.swipe($carousel[0], {
- pos: [300, 10],
- deltaX: -300,
- deltaY: 0
- })
- })
- QUnit.test('should allow swipeleft and call next with touch events', function (assert) {
- assert.expect(3)
- clearPointerEvents()
- Simulator.setType('touch')
- document.documentElement.ontouchstart = $.noop
- var done = assert.async()
- var carouselHTML =
- '<div class="carousel" data-interval="false">' +
- ' <div class="carousel-inner">' +
- ' <div id="item" class="carousel-item active">' +
- ' <img alt="">' +
- ' </div>' +
- ' <div class="carousel-item">' +
- ' <img alt="">' +
- ' </div>' +
- ' </div>' +
- '</div>'
- var $carousel = $(carouselHTML)
- $carousel.appendTo('#qunit-fixture')
- var $item = $('#item')
- $carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
- var spy = sinon.spy(carousel, 'next')
- $carousel.one('slid.bs.carousel', function () {
- assert.ok(true, 'slid event fired')
- assert.ok(!$item.hasClass('active'))
- assert.ok(spy.called)
- restorePointerEvents()
- delete document.documentElement.ontouchstart
- done()
- })
- Simulator.gestures.swipe($carousel[0], {
- pos: [300, 10],
- deltaX: -300,
- deltaY: 0
- })
- })
- QUnit.test('should not allow pinch with touch events', function (assert) {
- assert.expect(0)
- clearPointerEvents()
- Simulator.setType('touch')
- var done = assert.async()
- document.documentElement.ontouchstart = $.noop
- var carouselHTML = '<div class="carousel" data-interval="false"></div>'
- var $carousel = $(carouselHTML)
- $carousel.appendTo('#qunit-fixture')
- $carousel.bootstrapCarousel()
- Simulator.gestures.swipe($carousel[0], {
- pos: [300, 10],
- deltaX: -300,
- deltaY: 0,
- touches: 2
- }, function () {
- restorePointerEvents()
- delete document.documentElement.ontouchstart
- done()
- })
- })
- QUnit.test('should not call _slide if the carousel is sliding', function (assert) {
- assert.expect(1)
- var carouselHTML = '<div class="carousel" data-interval="false"></div>'
- var $carousel = $(carouselHTML)
- $carousel.appendTo('#qunit-fixture')
- $carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
- var spy = sinon.spy(carousel, '_slide')
- carousel._isSliding = true
- carousel.next()
- assert.strictEqual(spy.called, false)
- })
- QUnit.test('should call next when the page is visible', function (assert) {
- assert.expect(1)
- var carouselHTML = '<div class="carousel" data-interval="false"></div>'
- var $carousel = $(carouselHTML)
- $carousel.appendTo('#qunit-fixture')
- $carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
- var spy = sinon.spy(carousel, 'next')
- var sandbox = sinon.createSandbox()
- sandbox.replaceGetter(document, 'hidden', function () {
- return false
- })
- sandbox.stub($carousel, 'is').returns(true)
- sandbox.stub($carousel, 'css').returns('block')
- carousel.nextWhenVisible()
- assert.strictEqual(spy.called, true)
- sandbox.restore()
- })
- QUnit.test('should not cycle when there is no attribute data-ride', function (assert) {
- assert.expect(1)
- var spy = sinon.spy(Carousel.prototype, 'cycle')
- var carouselHTML = '<div class="carousel"></div>'
- var $carousel = $(carouselHTML)
- $carousel.appendTo('#qunit-fixture')
- $carousel.bootstrapCarousel()
- assert.strictEqual(spy.called, false)
- spy.restore()
- })
- QUnit.test('should cycle when there is data-ride attribute', function (assert) {
- assert.expect(1)
- var spy = sinon.spy(Carousel.prototype, 'cycle')
- var carouselHTML = '<div class="carousel" data-ride="carousel"></div>'
- var $carousel = $(carouselHTML)
- $carousel.appendTo('#qunit-fixture')
- $carousel.bootstrapCarousel()
- assert.strictEqual(spy.called, true)
- spy.restore()
- })
- QUnit.test('should init carousels with data-ride on load event', function (assert) {
- assert.expect(1)
- var done = assert.async()
- var spy = sinon.spy(Carousel, '_jQueryInterface')
- var carouselHTML = '<div class="carousel" data-ride="carousel"></div>'
- var $carousel = $(carouselHTML)
- $carousel.appendTo('#qunit-fixture')
- $(window).trigger($.Event('load'))
- setTimeout(function () {
- assert.strictEqual(spy.called, true)
- spy.restore()
- done()
- }, 5)
- })
- QUnit.test('should not add touch event listeners when touch option set to false', function (assert) {
- assert.expect(1)
- var spy = sinon.spy(Carousel.prototype, '_addTouchEventListeners')
- var $carousel = $('<div class="carousel" data-ride="carousel" data-touch="false"></div>')
- $carousel.appendTo('#qunit-fixture')
- $carousel.bootstrapCarousel()
- assert.strictEqual(spy.called, false)
- spy.restore()
- })
- })
|