1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-22 15:39:59 +00:00

rewrite tooltip unit tests

This commit is contained in:
Johann-S 2019-05-10 21:57:27 +02:00
parent c9e650a56f
commit 85b70cef3c
8 changed files with 1027 additions and 1285 deletions

View File

@ -42,7 +42,7 @@ const bsPlugins = {
ScrollSpy: path.resolve(__dirname, '../js/src/scrollspy.js'), ScrollSpy: path.resolve(__dirname, '../js/src/scrollspy.js'),
Tab: path.resolve(__dirname, '../js/src/tab.js'), Tab: path.resolve(__dirname, '../js/src/tab.js'),
Toast: path.resolve(__dirname, '../js/src/toast/toast.js'), Toast: path.resolve(__dirname, '../js/src/toast/toast.js'),
Tooltip: path.resolve(__dirname, '../js/src/tooltip.js') Tooltip: path.resolve(__dirname, '../js/src/tooltip/tooltip.js')
} }
const rootPath = '../js/dist/' const rootPath = '../js/dist/'

View File

@ -15,7 +15,7 @@ import Popover from './src/popover/popover'
import ScrollSpy from './src/scrollspy' import ScrollSpy from './src/scrollspy'
import Tab from './src/tab' import Tab from './src/tab'
import Toast from './src/toast/toast' import Toast from './src/toast/toast'
import Tooltip from './src/tooltip' import Tooltip from './src/tooltip/tooltip'
export { export {
Alert, Alert,

View File

@ -15,7 +15,7 @@ import Popover from './src/popover/popover'
import ScrollSpy from './src/scrollspy' import ScrollSpy from './src/scrollspy'
import Tab from './src/tab' import Tab from './src/tab'
import Toast from './src/toast/toast' import Toast from './src/toast/toast'
import Tooltip from './src/tooltip' import Tooltip from './src/tooltip/tooltip'
export default { export default {
Alert, Alert,

View File

@ -8,7 +8,7 @@
import { jQuery as $ } from '../util/index' import { jQuery as $ } from '../util/index'
import Data from '../dom/data' import Data from '../dom/data'
import SelectorEngine from '../dom/selector-engine' import SelectorEngine from '../dom/selector-engine'
import Tooltip from '../tooltip' import Tooltip from '../tooltip/tooltip'
/** /**
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------

View File

@ -16,8 +16,8 @@ describe('Popover', () => {
const popoverList = makeArray(document.querySelectorAll('.popover')) const popoverList = makeArray(document.querySelectorAll('.popover'))
popoverList.forEach(backdrop => { popoverList.forEach(popoverEl => {
document.body.removeChild(backdrop) document.body.removeChild(popoverEl)
}) })
}) })

View File

@ -16,16 +16,16 @@ import {
makeArray, makeArray,
noop, noop,
typeCheckConfig typeCheckConfig
} from './util/index' } from '../util/index'
import { import {
DefaultWhitelist, DefaultWhitelist,
sanitizeHtml sanitizeHtml
} from './util/sanitizer' } from '../util/sanitizer'
import Data from './dom/data' import Data from '../dom/data'
import EventHandler from './dom/event-handler' import EventHandler from '../dom/event-handler'
import Manipulator from './dom/manipulator' import Manipulator from '../dom/manipulator'
import Popper from 'popper.js' import Popper from 'popper.js'
import SelectorEngine from './dom/selector-engine' import SelectorEngine from '../dom/selector-engine'
/** /**
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
@ -290,7 +290,7 @@ class Tooltip {
this.config.placement this.config.placement
const attachment = this._getAttachment(placement) const attachment = this._getAttachment(placement)
this.addAttachmentClass(attachment) this._addAttachmentClass(attachment)
const container = this._getContainer() const container = this._getContainer()
Data.setData(tip, this.constructor.DATA_KEY, this) Data.setData(tip, this.constructor.DATA_KEY, this)
@ -360,7 +360,7 @@ class Tooltip {
} }
} }
hide(callback) { hide() {
const tip = this.getTipElement() const tip = this.getTipElement()
const complete = () => { const complete = () => {
if (this._hoverState !== HoverState.SHOW && tip.parentNode) { if (this._hoverState !== HoverState.SHOW && tip.parentNode) {
@ -370,15 +370,9 @@ class Tooltip {
this._cleanTipClass() this._cleanTipClass()
this.element.removeAttribute('aria-describedby') this.element.removeAttribute('aria-describedby')
EventHandler.trigger(this.element, this.constructor.Event.HIDDEN) EventHandler.trigger(this.element, this.constructor.Event.HIDDEN)
if (this._popper !== null) {
this._popper.destroy() this._popper.destroy()
} }
if (callback) {
callback()
}
}
const hideEvent = EventHandler.trigger(this.element, this.constructor.Event.HIDE) const hideEvent = EventHandler.trigger(this.element, this.constructor.Event.HIDE)
if (hideEvent.defaultPrevented) { if (hideEvent.defaultPrevented) {
return return
@ -421,10 +415,6 @@ class Tooltip {
return Boolean(this.getTitle()) return Boolean(this.getTitle())
} }
addAttachmentClass(attachment) {
this.getTipElement().classList.add(`${CLASS_PREFIX}-${attachment}`)
}
getTipElement() { getTipElement() {
if (this.tip) { if (this.tip) {
return this.tip return this.tip
@ -449,7 +439,7 @@ class Tooltip {
return return
} }
if (typeof content === 'object' && (content.nodeType || content.jquery)) { if (typeof content === 'object' && isElement(content)) {
if (content.jquery) { if (content.jquery) {
content = content[0] content = content[0]
} }
@ -492,6 +482,10 @@ class Tooltip {
// Private // Private
_addAttachmentClass(attachment) {
this.getTipElement().classList.add(`${CLASS_PREFIX}-${attachment}`)
}
_getOffset() { _getOffset() {
const offset = {} const offset = {}
@ -757,7 +751,7 @@ class Tooltip {
const popperInstance = popperData.instance const popperInstance = popperData.instance
this.tip = popperInstance.popper this.tip = popperInstance.popper
this._cleanTipClass() this._cleanTipClass()
this.addAttachmentClass(this._getAttachment(popperData.placement)) this._addAttachmentClass(this._getAttachment(popperData.placement))
} }
_fixTransition() { _fixTransition() {
@ -810,7 +804,7 @@ class Tooltip {
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
* add .tooltip to jQuery only if jQuery is present * add .tooltip to jQuery only if jQuery is present
*/ */
/* istanbul ignore if */
if (typeof $ !== 'undefined') { if (typeof $ !== 'undefined') {
const JQUERY_NO_CONFLICT = $.fn[NAME] const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Tooltip._jQueryInterface $.fn[NAME] = Tooltip._jQueryInterface

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff