Skip to content

Commit

Permalink
use qunit css for our fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S authored and XhmikosR committed Jul 23, 2019
1 parent 5ff6c15 commit ac0733d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 47 deletions.
8 changes: 6 additions & 2 deletions js/src/carousel/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,13 @@ describe('Carousel', () => {

describe('nextWhenVisible', () => {
it('should not call next when the page is not visible', () => {
fixtureEl.innerHTML = '<div class="carousel" data-interval="false"></div>'
fixtureEl.innerHTML = [
'<div style="display: none;">',
' <div class="carousel" data-interval="false"></div>',
'</div>'
].join('')

const carouselEl = fixtureEl.querySelector('div')
const carouselEl = fixtureEl.querySelector('.carousel')
const carousel = new Carousel(carouselEl)

spyOn(carousel, 'next')
Expand Down
16 changes: 0 additions & 16 deletions js/src/dropdown/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,9 +1152,6 @@ describe('Dropdown', () => {
'</div>'
].join('')

// the element must be displayed, without that activeElement won't change
fixtureEl.style.display = 'block'

const triggerDropdown = fixtureEl.querySelector('[data-toggle="dropdown"]')
const dropdown = fixtureEl.querySelector('.dropdown')
const input = fixtureEl.querySelector('input')
Expand All @@ -1173,7 +1170,6 @@ describe('Dropdown', () => {
textarea.dispatchEvent(keyDown)

expect(document.activeElement).toEqual(textarea, 'textarea still focused')
fixtureEl.style.display = 'none'
done()
})

Expand All @@ -1195,9 +1191,6 @@ describe('Dropdown', () => {
const triggerDropdown = fixtureEl.querySelector('[data-toggle="dropdown"]')
const dropdown = fixtureEl.querySelector('.dropdown')

// the element must be displayed, without that activeElement won't change
fixtureEl.style.display = 'block'

dropdown.addEventListener('shown.bs.dropdown', () => {
const keyDown = createEvent('keydown')
keyDown.which = 40
Expand All @@ -1207,7 +1200,6 @@ describe('Dropdown', () => {

expect(document.activeElement.classList.contains('disabled')).toEqual(false, '.disabled not focused')
expect(document.activeElement.hasAttribute('disabled')).toEqual(false, ':disabled not focused')
fixtureEl.style.display = 'none'
done()
})

Expand All @@ -1230,9 +1222,6 @@ describe('Dropdown', () => {
const item1 = fixtureEl.querySelector('#item1')
const item2 = fixtureEl.querySelector('#item2')

// the element must be displayed, without that activeElement won't change
fixtureEl.style.display = 'block'

dropdown.addEventListener('shown.bs.dropdown', () => {
const keyDown40 = createEvent('keydown')
keyDown40.which = 40
Expand All @@ -1249,7 +1238,6 @@ describe('Dropdown', () => {
document.activeElement.dispatchEvent(keyDown38)
expect(document.activeElement).toEqual(item1, 'item1 is focused')

fixtureEl.style.display = 'none'
done()
})

Expand Down Expand Up @@ -1322,9 +1310,6 @@ describe('Dropdown', () => {
'</div>'
].join('')

// the element must be displayed, without that activeElement won't change
fixtureEl.style.display = 'block'

const triggerDropdown = fixtureEl.querySelector('[data-toggle="dropdown"]')
const dropdown = fixtureEl.querySelector('.dropdown')
const input = fixtureEl.querySelector('input')
Expand Down Expand Up @@ -1385,7 +1370,6 @@ describe('Dropdown', () => {
input.dispatchEvent(keyDownEscape)

expect(dropdown.classList.contains('show')).toEqual(false, 'dropdown menu is not shown')
fixtureEl.style.display = 'none'
done()
})

Expand Down
8 changes: 2 additions & 6 deletions js/src/modal/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,6 @@ describe('Modal', () => {
'<div id="exampleModal" class="modal"><div class="modal-dialog" /></div>'
].join('')

// the element must be displayed, without that activeElement won't change
fixtureEl.style.display = 'block'

const modalEl = fixtureEl.querySelector('.modal')
const trigger = fixtureEl.querySelector('[data-toggle="modal"]')

Expand All @@ -807,7 +804,6 @@ describe('Modal', () => {
const hideListener = () => {
setTimeout(() => {
expect(trigger.focus).toHaveBeenCalled()
fixtureEl.style.display = 'none'
done()
}, 20)
}
Expand All @@ -821,8 +817,8 @@ describe('Modal', () => {

it('should not focus the trigger if the modal is not visible', done => {
fixtureEl.innerHTML = [
'<a data-toggle="modal" href="#" data-target="#exampleModal"></a>',
'<div id="exampleModal" class="modal"><div class="modal-dialog" /></div>'
'<a data-toggle="modal" href="#" data-target="#exampleModal" style="display: none;"></a>',
'<div id="exampleModal" class="modal" style="display: none;"><div class="modal-dialog" /></div>'
].join('')

const modalEl = fixtureEl.querySelector('.modal')
Expand Down
24 changes: 4 additions & 20 deletions js/src/scrollspy/scrollspy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('ScrollSpy', () => {
})

afterEach(() => {
fixtureEl.style.display = 'none'
clearFixture()
})

Expand Down Expand Up @@ -80,7 +79,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'
const scrollSpy = new ScrollSpy(fixtureEl.querySelector('#content'), {
target: '#navigation'
})
Expand Down Expand Up @@ -114,7 +112,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'
const scrollSpyEl = fixtureEl.querySelector('#scrollspy-example')
const rootEl = fixtureEl.querySelector('#root')
const scrollSpy = new ScrollSpy(scrollSpyEl, {
Expand Down Expand Up @@ -172,7 +169,6 @@ describe('ScrollSpy', () => {
done()
})

fixtureEl.style.display = 'block'
scrollSpyEl.scrollTop = 350
})

Expand All @@ -193,7 +189,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'
const contentEl = fixtureEl.querySelector('#content')
const scrollSpy = new ScrollSpy(contentEl, {
target: '#navigation',
Expand Down Expand Up @@ -227,7 +222,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'
const contentEl = fixtureEl.querySelector('.content')
const scrollSpy = new ScrollSpy(contentEl, {
offset: 0,
Expand Down Expand Up @@ -268,7 +262,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'
const contentEl = fixtureEl.querySelector('.content')
const scrollSpy = new ScrollSpy(contentEl, {
offset: 0,
Expand Down Expand Up @@ -309,7 +302,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'
const contentEl = fixtureEl.querySelector('.content')
const scrollSpy = new ScrollSpy(contentEl, {
offset: 0,
Expand Down Expand Up @@ -355,8 +347,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'

const contentEl = fixtureEl.querySelector('#content')
const scrollSpy = new ScrollSpy(contentEl, {
target: '#navigation',
Expand Down Expand Up @@ -403,8 +393,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'

const negativeHeight = -10
const startOfSectionTwo = 101
const contentEl = fixtureEl.querySelector('#content')
Expand Down Expand Up @@ -456,8 +444,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'

const contentEl = fixtureEl.querySelector('.content')
const scrollSpy = new ScrollSpy(contentEl, {
offset: 0,
Expand Down Expand Up @@ -531,8 +517,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'

const contentEl = fixtureEl.querySelector('.content')
const targetEl = fixtureEl.querySelector('#div-jsm-2')
const scrollSpy = new ScrollSpy(contentEl, {
Expand Down Expand Up @@ -561,8 +545,6 @@ describe('ScrollSpy', () => {
'</div>'
].join('')

fixtureEl.style.display = 'block'

const contentEl = fixtureEl.querySelector('.content')
const targetEl = fixtureEl.querySelector('#div-jsm-2')
const scrollSpy = new ScrollSpy(contentEl, {
Expand All @@ -579,11 +561,13 @@ describe('ScrollSpy', () => {
describe('dispose', () => {
it('should dispose a scrollspy', () => {
spyOn(EventHandler, 'off')
fixtureEl.innerHTML = '<div style="display: none;"></div>'

const scrollSpy = new ScrollSpy(fixtureEl)
const divEl = fixtureEl.querySelector('div')
const scrollSpy = new ScrollSpy(divEl)

scrollSpy.dispose()
expect(EventHandler.off).toHaveBeenCalledWith(fixtureEl, '.bs.scrollspy')
expect(EventHandler.off).toHaveBeenCalledWith(divEl, '.bs.scrollspy')
})
})

Expand Down
8 changes: 6 additions & 2 deletions js/src/util/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,13 @@ describe('Util', () => {
})

it('should return false if the parent element is not visible', () => {
fixtureEl.innerHTML = '<div></div>'
fixtureEl.innerHTML = [
'<div style="display: none;">',
' <div class="content"></div>',
'</div>'
].join('')

const div = fixtureEl.querySelector('div')
const div = fixtureEl.querySelector('.content')

expect(Util.isVisible(div)).toEqual(false)
})
Expand Down
6 changes: 5 additions & 1 deletion js/tests/helpers/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export const getFixture = () => {
if (!fixtureEl) {
fixtureEl = document.createElement('div')
fixtureEl.setAttribute('id', fixtureId)
fixtureEl.style.display = 'none'
fixtureEl.style.position = 'absolute'
fixtureEl.style.top = '-10000px'
fixtureEl.style.left = '-10000px'
fixtureEl.style.width = '10000px'
fixtureEl.style.height = '10000px'
document.body.appendChild(fixtureEl)
}

Expand Down

0 comments on commit ac0733d

Please sign in to comment.