mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-22 13:13:03 +02:00
Allow constructors to accept a CSS selector (#32245)
Co-authored-by: XhmikosR <xhmikosr@gmail.com> Co-authored-by: Mark Otto <otto@github.com>
This commit is contained in:
@@ -15,6 +15,17 @@ describe('Alert', () => {
|
||||
clearFixture()
|
||||
})
|
||||
|
||||
it('should take care of element either passed as a CSS selector or DOM element', () => {
|
||||
fixtureEl.innerHTML = '<div class="alert"></div>'
|
||||
|
||||
const alertEl = fixtureEl.querySelector('.alert')
|
||||
const alertBySelector = new Alert('.alert')
|
||||
const alertByElement = new Alert(alertEl)
|
||||
|
||||
expect(alertBySelector._element).toEqual(alertEl)
|
||||
expect(alertByElement._element).toEqual(alertEl)
|
||||
})
|
||||
|
||||
it('should return version', () => {
|
||||
expect(typeof Alert.VERSION).toEqual('string')
|
||||
})
|
||||
|
@@ -18,6 +18,16 @@ describe('Button', () => {
|
||||
clearFixture()
|
||||
})
|
||||
|
||||
it('should take care of element either passed as a CSS selector or DOM element', () => {
|
||||
fixtureEl.innerHTML = '<button data-bs-toggle="button">Placeholder</button>'
|
||||
const buttonEl = fixtureEl.querySelector('[data-bs-toggle="button"]')
|
||||
const buttonBySelector = new Button('[data-bs-toggle="button"]')
|
||||
const buttonByElement = new Button(buttonEl)
|
||||
|
||||
expect(buttonBySelector._element).toEqual(buttonEl)
|
||||
expect(buttonByElement._element).toEqual(buttonEl)
|
||||
})
|
||||
|
||||
describe('VERSION', () => {
|
||||
it('should return plugin version', () => {
|
||||
expect(Button.VERSION).toEqual(jasmine.any(String))
|
||||
|
@@ -52,6 +52,17 @@ describe('Carousel', () => {
|
||||
})
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should take care of element either passed as a CSS selector or DOM element', () => {
|
||||
fixtureEl.innerHTML = '<div id="myCarousel" class="carousel slide"></div>'
|
||||
|
||||
const carouselEl = fixtureEl.querySelector('#myCarousel')
|
||||
const carouselBySelector = new Carousel('#myCarousel')
|
||||
const carouselByElement = new Carousel(carouselEl)
|
||||
|
||||
expect(carouselBySelector._element).toEqual(carouselEl)
|
||||
expect(carouselByElement._element).toEqual(carouselEl)
|
||||
})
|
||||
|
||||
it('should go to next item if right arrow key is pressed', done => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div id="myCarousel" class="carousel slide">',
|
||||
|
@@ -34,6 +34,17 @@ describe('Collapse', () => {
|
||||
})
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should take care of element either passed as a CSS selector or DOM element', () => {
|
||||
fixtureEl.innerHTML = '<div class="my-collapse"></div>'
|
||||
|
||||
const collapseEl = fixtureEl.querySelector('div.my-collapse')
|
||||
const collapseBySelector = new Collapse('div.my-collapse')
|
||||
const collapseByElement = new Collapse(collapseEl)
|
||||
|
||||
expect(collapseBySelector._element).toEqual(collapseEl)
|
||||
expect(collapseByElement._element).toEqual(collapseEl)
|
||||
})
|
||||
|
||||
it('should allow jquery object in parent config', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div class="my-collapse">',
|
||||
|
@@ -40,6 +40,24 @@ describe('Dropdown', () => {
|
||||
})
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should take care of element either passed as a CSS selector or DOM element', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div class="dropdown">',
|
||||
' <button class="btn dropdown-toggle" data-bs-toggle="dropdown">Dropdown</button>',
|
||||
' <div class="dropdown-menu">',
|
||||
' <a class="dropdown-item" href="#">Link</a>',
|
||||
' </div>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
|
||||
const dropdownBySelector = new Dropdown('[data-bs-toggle="dropdown"]')
|
||||
const dropdownByElement = new Dropdown(btnDropdown)
|
||||
|
||||
expect(dropdownBySelector._element).toEqual(btnDropdown)
|
||||
expect(dropdownByElement._element).toEqual(btnDropdown)
|
||||
})
|
||||
|
||||
it('should add a listener on trigger which do not have data-bs-toggle="dropdown"', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div class="dropdown">',
|
||||
|
@@ -62,6 +62,19 @@ describe('Modal', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should take care of element either passed as a CSS selector or DOM element', () => {
|
||||
fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog"></div></div>'
|
||||
|
||||
const modalEl = fixtureEl.querySelector('.modal')
|
||||
const modalBySelector = new Modal('.modal')
|
||||
const modalByElement = new Modal(modalEl)
|
||||
|
||||
expect(modalBySelector._element).toEqual(modalEl)
|
||||
expect(modalByElement._element).toEqual(modalEl)
|
||||
})
|
||||
})
|
||||
|
||||
describe('toggle', () => {
|
||||
it('should toggle a modal', done => {
|
||||
fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog"></div></div>'
|
||||
|
@@ -54,6 +54,17 @@ describe('ScrollSpy', () => {
|
||||
})
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should take care of element either passed as a CSS selector or DOM element', () => {
|
||||
fixtureEl.innerHTML = '<nav id="navigation"></nav><div class="content"></div>'
|
||||
|
||||
const sSpyEl = fixtureEl.querySelector('#navigation')
|
||||
const sSpyBySelector = new ScrollSpy('#navigation')
|
||||
const sSpyByElement = new ScrollSpy(sSpyEl)
|
||||
|
||||
expect(sSpyBySelector._element).toEqual(sSpyEl)
|
||||
expect(sSpyByElement._element).toEqual(sSpyEl)
|
||||
})
|
||||
|
||||
it('should generate an id when there is not one', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<nav></nav>',
|
||||
|
@@ -20,6 +20,22 @@ describe('Tab', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should take care of element either passed as a CSS selector or DOM element', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<ul class="nav"><li><a href="#home" role="tab">Home</a></li></ul>',
|
||||
'<ul><li id="home"></li></ul>'
|
||||
].join('')
|
||||
|
||||
const tabEl = fixtureEl.querySelector('[href="#home"]')
|
||||
const tabBySelector = new Tab('[href="#home"]')
|
||||
const tabByElement = new Tab(tabEl)
|
||||
|
||||
expect(tabBySelector._element).toEqual(tabEl)
|
||||
expect(tabByElement._element).toEqual(tabEl)
|
||||
})
|
||||
})
|
||||
|
||||
describe('show', () => {
|
||||
it('should activate element by tab id (using buttons, the preferred semantic way)', done => {
|
||||
fixtureEl.innerHTML = [
|
||||
|
@@ -27,6 +27,17 @@ describe('Toast', () => {
|
||||
})
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should take care of element either passed as a CSS selector or DOM element', () => {
|
||||
fixtureEl.innerHTML = '<div class="toast"></div>'
|
||||
|
||||
const toastEl = fixtureEl.querySelector('.toast')
|
||||
const toastBySelector = new Toast('.toast')
|
||||
const toastByElement = new Toast(toastEl)
|
||||
|
||||
expect(toastBySelector._element).toEqual(toastEl)
|
||||
expect(toastByElement._element).toEqual(toastEl)
|
||||
})
|
||||
|
||||
it('should allow to config in js', done => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div class="toast">',
|
||||
|
@@ -63,6 +63,17 @@ describe('Tooltip', () => {
|
||||
})
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should take care of element either passed as a CSS selector or DOM element', () => {
|
||||
fixtureEl.innerHTML = '<a href="#" id="tooltipEl" rel="tooltip" title="Nice and short title">'
|
||||
|
||||
const tooltipEl = fixtureEl.querySelector('#tooltipEl')
|
||||
const tooltipBySelector = new Tooltip('#tooltipEl')
|
||||
const tooltipByElement = new Tooltip(tooltipEl)
|
||||
|
||||
expect(tooltipBySelector._element).toEqual(tooltipEl)
|
||||
expect(tooltipByElement._element).toEqual(tooltipEl)
|
||||
})
|
||||
|
||||
it('should not take care of disallowed data attributes', () => {
|
||||
fixtureEl.innerHTML = '<a href="#" rel="tooltip" data-bs-sanitize="false" title="Another tooltip">'
|
||||
|
||||
|
Reference in New Issue
Block a user