Skip to content

Commit

Permalink
Use transitionEnd in QUnit since we moved away from PhantomJS
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Mar 20, 2018
1 parent 2306f62 commit fbb3214
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 164 deletions.
3 changes: 1 addition & 2 deletions js/src/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ const Alert = (($) => {
_removeElement(element) {
$(element).removeClass(ClassName.SHOW)

if (!Util.supportsTransitionEnd() ||
!$(element).hasClass(ClassName.FADE)) {
if (!$(element).hasClass(ClassName.FADE)) {
this._destroyElement(element)
return
}
Expand Down
6 changes: 2 additions & 4 deletions js/src/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ const Carousel = (($) => {
this._isPaused = true
}

if ($(this._element).find(Selector.NEXT_PREV)[0] &&
Util.supportsTransitionEnd()) {
if ($(this._element).find(Selector.NEXT_PREV)[0]) {
Util.triggerTransitionEnd(this._element)
this.cycle(true)
}
Expand Down Expand Up @@ -376,8 +375,7 @@ const Carousel = (($) => {
to: nextElementIndex
})

if (Util.supportsTransitionEnd() &&
$(this._element).hasClass(ClassName.SLIDE)) {
if ($(this._element).hasClass(ClassName.SLIDE)) {
$(nextElement).addClass(orderClassName)

Util.reflow(nextElement)
Expand Down
11 changes: 0 additions & 11 deletions js/src/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ const Collapse = (($) => {
$(this._element).trigger(Event.SHOWN)
}

if (!Util.supportsTransitionEnd()) {
complete()
return
}

const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1)
const scrollSize = `scroll${capitalizedDimension}`
const transitionDuration = Util.getTransitionDurationFromElement(this._element)
Expand Down Expand Up @@ -246,12 +241,6 @@ const Collapse = (($) => {
}

this._element.style[dimension] = ''

if (!Util.supportsTransitionEnd()) {
complete()
return
}

const transitionDuration = Util.getTransitionDurationFromElement(this._element)

$(this._element)
Expand Down
17 changes: 6 additions & 11 deletions js/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const Modal = (($) => {
return
}

if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) {
if ($(this._element).hasClass(ClassName.FADE)) {
this._isTransitioning = true
}

Expand Down Expand Up @@ -168,8 +168,7 @@ const Modal = (($) => {
}

this._isShown = false

const transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)
const transition = $(this._element).hasClass(ClassName.FADE)

if (transition) {
this._isTransitioning = true
Expand Down Expand Up @@ -228,8 +227,7 @@ const Modal = (($) => {
}

_showElement(relatedTarget) {
const transition = Util.supportsTransitionEnd() &&
$(this._element).hasClass(ClassName.FADE)
const transition = $(this._element).hasClass(ClassName.FADE)

if (!this._element.parentNode ||
this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
Expand Down Expand Up @@ -331,8 +329,6 @@ const Modal = (($) => {
? ClassName.FADE : ''

if (this._isShown && this._config.backdrop) {
const doAnimate = Util.supportsTransitionEnd() && animate

this._backdrop = document.createElement('div')
this._backdrop.className = ClassName.BACKDROP

Expand All @@ -357,7 +353,7 @@ const Modal = (($) => {
}
})

if (doAnimate) {
if (animate) {
Util.reflow(this._backdrop)
}

Expand All @@ -367,7 +363,7 @@ const Modal = (($) => {
return
}

if (!doAnimate) {
if (!animate) {
callback()
return
}
Expand All @@ -387,8 +383,7 @@ const Modal = (($) => {
}
}

if (Util.supportsTransitionEnd() &&
$(this._element).hasClass(ClassName.FADE)) {
if ($(this._element).hasClass(ClassName.FADE)) {
const backdropTransitionDuration = Util.getTransitionDurationFromElement(this._backdrop)

$(this._backdrop)
Expand Down
1 change: 0 additions & 1 deletion js/src/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ const Tab = (($) => {

const active = activeElements[0]
const isTransitioning = callback &&
Util.supportsTransitionEnd() &&
(active && $(active).hasClass(ClassName.FADE))

const complete = () => this._transitionComplete(
Expand Down
5 changes: 2 additions & 3 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ const Tooltip = (($) => {
}
}

if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
if ($(this.tip).hasClass(ClassName.FADE)) {
const transitionDuration = Util.getTransitionDurationFromElement(this.tip)

$(this.tip)
Expand Down Expand Up @@ -383,8 +383,7 @@ const Tooltip = (($) => {
this._activeTrigger[Trigger.FOCUS] = false
this._activeTrigger[Trigger.HOVER] = false

if (Util.supportsTransitionEnd() &&
$(this.tip).hasClass(ClassName.FADE)) {
if ($(this.tip).hasClass(ClassName.FADE)) {
const transitionDuration = Util.getTransitionDurationFromElement(tip)

$(tip)
Expand Down
30 changes: 5 additions & 25 deletions js/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const Util = (($) => {
* ------------------------------------------------------------------------
*/

let transition = false

const TRANSITION_END = 'transitionend'
const MAX_UID = 1000000
const MILLISECONDS_MULTIPLIER = 1000

Expand All @@ -26,8 +25,8 @@ const Util = (($) => {

function getSpecialTransitionEndEvent() {
return {
bindType: transition.end,
delegateType: transition.end,
bindType: TRANSITION_END,
delegateType: TRANSITION_END,
handle(event) {
if ($(event.target).is(this)) {
return event.handleObj.handler.apply(this, arguments) // eslint-disable-line prefer-rest-params
Expand All @@ -37,16 +36,6 @@ const Util = (($) => {
}
}

function transitionEndTest() {
if (typeof window !== 'undefined' && window.QUnit) {
return false
}

return {
end: 'transitionend'
}
}

function transitionEndEmulator(duration) {
let called = false

Expand All @@ -64,13 +53,8 @@ const Util = (($) => {
}

function setTransitionEndSupport() {
transition = transitionEndTest()

$.fn.emulateTransitionEnd = transitionEndEmulator

if (Util.supportsTransitionEnd()) {
$.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent()
}
$.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent()
}

/**
Expand Down Expand Up @@ -130,11 +114,7 @@ const Util = (($) => {
},

triggerTransitionEnd(element) {
$(element).trigger(transition.end)
},

supportsTransitionEnd() {
return Boolean(transition)
$(element).trigger(TRANSITION_END)
},

isElement(obj) {
Expand Down
11 changes: 8 additions & 3 deletions js/tests/unit/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $(function () {

QUnit.test('should remove element when clicking .close', function (assert) {
assert.expect(2)
var done = assert.async()
var alertHTML = '<div class="alert alert-danger fade show">' +
'<a class="close" href="#" data-dismiss="alert">×</a>' +
'<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' +
Expand All @@ -56,9 +57,13 @@ $(function () {

assert.notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom')

$alert.find('.close').trigger('click')

assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom')
$alert
.one('closed.bs.alert', function () {
assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom')
done()
})
.find('.close')
.trigger('click')
})

QUnit.test('should not fire closed when close is prevented', function (assert) {
Expand Down
10 changes: 7 additions & 3 deletions js/tests/unit/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ $(function () {

QUnit.test('should show a collapsed element', function (assert) {
assert.expect(2)
var $el = $('<div class="collapse"/>').bootstrapCollapse('show')
var done = assert.async()
var $el = $('<div class="collapse"/>')

assert.ok($el.hasClass('show'), 'has class "show"')
assert.ok(!/height/i.test($el.attr('style')), 'has height reset')
$el.one('shown.bs.collapse', function () {
assert.ok($el.hasClass('show'), 'has class "show"')
assert.ok(!/height/i.test($el.attr('style')), 'has height reset')
done()
}).bootstrapCollapse('show')
})

QUnit.test('should show multiple collapsed elements', function (assert) {
Expand Down
Loading

0 comments on commit fbb3214

Please sign in to comment.