An error occurred while loading the file. Please try again.
-
Mark Otto authoredfc4ef0ce
import Tooltip from '../../src/tooltip'
import EventHandler from '../../src/dom/event-handler'
import { noop } from '../../src/util/index'
/** Test helpers */
import { getFixture, clearFixture, jQueryMock, createEvent } from '../helpers/fixture'
describe('Tooltip', () => {
let fixtureEl
beforeAll(() => {
fixtureEl = getFixture()
})
afterEach(() => {
clearFixture()
document.querySelectorAll('.tooltip').forEach(tooltipEl => {
document.body.removeChild(tooltipEl)
})
})
describe('VERSION', () => {
it('should return plugin version', () => {
expect(Tooltip.VERSION).toEqual(jasmine.any(String))
})
})
describe('Default', () => {
it('should return plugin default config', () => {
expect(Tooltip.Default).toEqual(jasmine.any(Object))
})
})
describe('NAME', () => {
it('should return plugin name', () => {
expect(Tooltip.NAME).toEqual(jasmine.any(String))
})
})
describe('DATA_KEY', () => {
it('should return plugin data key', () => {
expect(Tooltip.DATA_KEY).toEqual('bs.tooltip')
})
})
describe('Event', () => {
it('should return plugin events', () => {
expect(Tooltip.Event).toEqual(jasmine.any(Object))
})
})
describe('EVENT_KEY', () => {
it('should return plugin event key', () => {
expect(Tooltip.EVENT_KEY).toEqual('.bs.tooltip')
})
})
describe('DefaultType', () => {
it('should return plugin default type', () => {
expect(Tooltip.DefaultType).toEqual(jasmine.any(Object))
})
})
describe('constructor', () => {
it('should not take care of disallowed data attributes', () => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" data-sanitize="false" title="Another tooltip"/>'
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
expect(tooltip.config.sanitize).toEqual(true)
})
it('should convert title and content to string if numbers', () => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip"/>'
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl, {
title: 1,
content: 7
})
expect(tooltip.config.title).toEqual('1')
expect(tooltip.config.content).toEqual('7')
})
it('should enable selector delegation', done => {
fixtureEl.innerHTML = '<div></div>'
const containerEl = fixtureEl.querySelector('div')
const tooltipContainer = new Tooltip(containerEl, {
selector: 'a[rel="tooltip"]',
trigger: 'click'
})
containerEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip"/>'
const tooltipInContainerEl = containerEl.querySelector('a')
tooltipInContainerEl.addEventListener('shown.bs.tooltip', () => {
expect(document.querySelector('.tooltip')).not.toBeNull()
tooltipContainer.dispose()
done()
})
tooltipInContainerEl.click()
})
it('should allow to pass config to popper.js with `popperConfig`', () => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip"/>'
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl, {
popperConfig: {
placement: 'left'
}
})
const popperConfig = tooltip._getPopperConfig('top')
expect(popperConfig.placement).toEqual('left')
})
})
describe('enable', () => {
it('should enable a tooltip', done => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip"/>'
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
tooltip.enable()
tooltipEl.addEventListener('shown.bs.tooltip', () => {
expect(document.querySelector('.tooltip')).toBeDefined()
done()
})
tooltip.show()