Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix random BrowserStack failures in scrollbar #33612

Merged
merged 1 commit into from Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 9 additions & 10 deletions js/tests/unit/modal.spec.js
Expand Up @@ -16,19 +16,20 @@ describe('Modal', () => {
clearFixture()

document.body.classList.remove('modal-open')
document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')

document.querySelectorAll('.modal-backdrop')
.forEach(backdrop => {
document.body.removeChild(backdrop)
})

document.body.style.removeProperty('paddingRight')
})

afterAll(() => {
document.documentElement.style.removeProperty('paddingRight')
beforeEach(() => {
document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')
})

describe('VERSION', () => {
Expand Down Expand Up @@ -104,15 +105,15 @@ describe('Modal', () => {
const expectedPadding = originalPadding + getScrollBarWidth()
const currentPadding = Number.parseInt(window.getComputedStyle(modalEl).paddingRight, 10)

expect(fixedEl.getAttribute('data-bs-padding-right')).toEqual('0px', 'original fixed element padding should be stored in data-bs-padding-right')
expect(fixedEl.getAttribute('data-bs-padding-right')).toEqual(`${originalPadding}px`, 'original fixed element padding should be stored in data-bs-padding-right')
expect(currentPadding).toEqual(expectedPadding, 'fixed element padding should be adjusted while opening')
modal.toggle()
})

modalEl.addEventListener('hidden.bs.modal', () => {
const currentPadding = Number.parseInt(window.getComputedStyle(modalEl).paddingRight, 10)

expect(fixedEl.getAttribute('data-bs-padding-right')).toEqual(null, 'data-bs-padding-right should be cleared after closing')
expect(fixedEl.hasAttribute('data-bs-padding-right')).toEqual(false, 'data-bs-padding-right should be cleared after closing')
expect(currentPadding).toEqual(originalPadding, 'fixed element padding should be reset after closing')
document.documentElement.style.overflowY = 'auto'
done()
Expand All @@ -138,15 +139,15 @@ describe('Modal', () => {
const expectedMargin = originalMargin - getScrollBarWidth()
const currentMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10)

expect(stickyTopEl.getAttribute('data-bs-margin-right')).toEqual('0px', 'original sticky element margin should be stored in data-bs-margin-right')
expect(stickyTopEl.getAttribute('data-bs-margin-right')).toEqual(`${originalMargin}px`, 'original sticky element margin should be stored in data-bs-margin-right')
expect(currentMargin).toEqual(expectedMargin, 'sticky element margin should be adjusted while opening')
modal.toggle()
})

modalEl.addEventListener('hidden.bs.modal', () => {
const currentMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10)

expect(stickyTopEl.getAttribute('data-bs-margin-right')).toEqual(null, 'data-bs-margin-right should be cleared after closing')
expect(stickyTopEl.hasAttribute('data-bs-margin-right')).toEqual(false, 'data-bs-margin-right should be cleared after closing')
expect(currentMargin).toEqual(originalMargin, 'sticky element margin should be reset after closing')

document.documentElement.style.overflowY = 'auto'
Expand Down Expand Up @@ -679,7 +680,6 @@ describe('Modal', () => {

// Restore scrollbars
document.body.style.overflow = 'auto'
document.documentElement.style.paddingRight = '16px'
done()
})

Expand Down Expand Up @@ -711,7 +711,6 @@ describe('Modal', () => {
// Restore overridden css
document.body.style.removeProperty('margin')
document.body.style.removeProperty('overflow')
document.documentElement.style.paddingRight = '16px'
done()
})

Expand Down
11 changes: 10 additions & 1 deletion js/tests/unit/offcanvas.spec.js
Expand Up @@ -14,6 +14,15 @@ describe('Offcanvas', () => {
afterEach(() => {
clearFixture()
document.body.classList.remove('offcanvas-open')
document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')
})

beforeEach(() => {
document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')
})

describe('VERSION', () => {
Expand Down Expand Up @@ -177,7 +186,7 @@ describe('Offcanvas', () => {
offCanvas.hide()
})
offCanvasEl.addEventListener('hidden.bs.offcanvas', () => {
expect(document.body.style.overflow).toEqual('auto')
expect(document.body.style.overflow).not.toEqual('hidden')
done()
})
offCanvas.show()
Expand Down
6 changes: 4 additions & 2 deletions js/tests/unit/util/scrollbar.spec.js
Expand Up @@ -28,17 +28,19 @@ describe('ScrollBar', () => {

afterAll(() => {
fixtureEl.remove()
document.documentElement.style.overflowY = 'auto'
document.body.style.overflowY = 'auto'
})

afterEach(() => {
clearFixture()
document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')
})

beforeEach(() => {
document.documentElement.removeAttribute('style')
document.body.removeAttribute('style')
document.body.removeAttribute('data-bs-padding-right')
})

describe('isBodyOverflowing', () => {
Expand Down