0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00

Popover.js: Accept empty content through data-bs-content (#35514)

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
GeoSot 2021-12-15 10:41:31 +02:00 committed by GitHub
parent cd04fe015f
commit d40fae456e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 22 deletions

View File

@ -34,7 +34,7 @@ const Default = {
const DefaultType = {
...Tooltip.DefaultType,
content: '(string|element|function)'
content: '(null|string|element|function)'
}
const Event = {

View File

@ -1,4 +1,5 @@
import Popover from '../../src/popover'
import EventHandler from '../../src/dom/event-handler'
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
describe('Popover', () => {
@ -96,25 +97,6 @@ describe('Popover', () => {
popover.show()
})
it('should show a popover with just content', done => {
fixtureEl.innerHTML = '<a href="#">BS twitter</a>'
const popoverEl = fixtureEl.querySelector('a')
const popover = new Popover(popoverEl, {
content: 'Popover content'
})
popoverEl.addEventListener('shown.bs.popover', () => {
const popoverDisplayed = document.querySelector('.popover')
expect(popoverDisplayed).not.toBeNull()
expect(popoverDisplayed.querySelector('.popover-body').textContent).toEqual('Popover content')
done()
})
popover.show()
})
it('should show a popover with just content without having header', done => {
fixtureEl.innerHTML = '<a href="#">Nice link</a>'
@ -140,7 +122,7 @@ describe('Popover', () => {
const popoverEl = fixtureEl.querySelector('a')
const popover = new Popover(popoverEl, {
title: 'Title, which does not require content'
title: 'Title which does not require content'
})
popoverEl.addEventListener('shown.bs.popover', () => {
@ -148,7 +130,41 @@ describe('Popover', () => {
expect(popoverDisplayed).not.toBeNull()
expect(popoverDisplayed.querySelector('.popover-body')).toBeNull()
expect(popoverDisplayed.querySelector('.popover-header').textContent).toEqual('Title, which does not require content')
expect(popoverDisplayed.querySelector('.popover-header').textContent).toEqual('Title which does not require content')
done()
})
popover.show()
})
it('should show a popover with just title without having body using data-attribute to get config', done => {
fixtureEl.innerHTML = '<a href="#" data-bs-content="" title="Title which does not require content">Nice link</a>'
const popoverEl = fixtureEl.querySelector('a')
const popover = new Popover(popoverEl)
popoverEl.addEventListener('shown.bs.popover', () => {
const popoverDisplayed = document.querySelector('.popover')
expect(popoverDisplayed).not.toBeNull()
expect(popoverDisplayed.querySelector('.popover-body')).toBeNull()
expect(popoverDisplayed.querySelector('.popover-header').textContent).toEqual('Title which does not require content')
done()
})
popover.show()
})
it('should NOT show a popover without `title` and `content`', done => {
fixtureEl.innerHTML = '<a href="#" data-bs-content="" title="">Nice link</a>'
const popoverEl = fixtureEl.querySelector('a')
const popover = new Popover(popoverEl, { animation: false })
spyOn(EventHandler, 'trigger').and.callThrough()
setTimeout(() => {
expect(EventHandler.trigger).not.toHaveBeenCalled()
expect(document.querySelector('.popover')).toBeNull()
done()
})