-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
scrollbar.cy.js
123 lines (105 loc) · 4.09 KB
/
scrollbar.cy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/// <reference types="cypress" />
import { Swal, SwalWithoutAnimation, ensureClosed } from '../utils'
import { measureScrollbar } from '../../src/utils/dom/measureScrollbar'
import { SHOW_CLASS_TIMEOUT } from '../../src/utils/openPopup'
describe('Vertical scrollbar', () => {
it('should be visible on container and it should be scrolled to top', (done) => {
SwalWithoutAnimation.fire({
imageUrl: 'https://placeholder.pics/svg/300x1500',
imageHeight: 1500,
imageAlt: 'A tall image',
didOpen: () => {
expect(Swal.getContainer().scrollTop).to.equal(0)
setTimeout(() => {
expect(Swal.getContainer().style.overflowY).to.equal('auto')
Swal.close()
done()
}, SHOW_CLASS_TIMEOUT)
},
})
})
it('should be hidden and the according padding-right should be set', (done) => {
ensureClosed()
const talltDiv = document.createElement('div')
talltDiv.innerHTML = Array(100).join('<div>lorem ipsum</div>')
document.body.appendChild(talltDiv)
document.body.style.paddingRight = '30px'
const scrollbarWidth = measureScrollbar()
SwalWithoutAnimation.fire({
title: 'The body has visible scrollbar, I will hide it and adjust padding-right on body',
didClose: () => {
expect(bodyStyles.paddingRight).to.equal('30px')
document.body.removeChild(talltDiv)
done()
},
})
const bodyStyles = window.getComputedStyle(document.body)
expect(bodyStyles.paddingRight).to.equal(`${scrollbarWidth + 30}px`)
expect(bodyStyles.overflow).to.equal('hidden')
Swal.close()
})
it('scrollbarPadding disabled', () => {
const talltDiv = document.createElement('div')
talltDiv.innerHTML = Array(100).join('<div>lorem ipsum</div>')
document.body.appendChild(talltDiv)
document.body.style.paddingRight = '30px'
SwalWithoutAnimation.fire({
title: 'Padding right adjustment disabled',
scrollbarPadding: false,
didClose: () => {
document.body.removeChild(talltDiv)
},
})
const bodyStyles = window.getComputedStyle(document.body)
expect(bodyStyles.paddingRight).to.equal('30px')
Swal.close()
})
it('should not adjust body padding if overflow-y: scroll is set on body', () => {
const talltDiv = document.createElement('div')
talltDiv.innerHTML = Array(100).join('<div>lorem ipsum</div>')
document.body.appendChild(talltDiv)
document.body.style.overflowY = 'scroll'
document.body.style.paddingRight = '30px'
SwalWithoutAnimation.fire({
title: 'no padding right adjustment when overflow-y: scroll is set on body',
didClose: () => {
document.body.removeChild(talltDiv)
},
})
const bodyStyles = window.getComputedStyle(document.body)
expect(bodyStyles.paddingRight).to.equal('30px')
})
it('should be restored before a toast is fired after a modal', (done) => {
const talltDiv = document.createElement('div')
talltDiv.innerHTML = Array(100).join('<div>lorem ipsum</div>')
document.body.appendChild(talltDiv)
document.body.style.paddingRight = '30px'
SwalWithoutAnimation.fire({
title: 'The body has visible scrollbar, I will hide it and adjust padding-right on body',
}).then(() => {
Swal.fire({
text: 'Body padding-right should be restored',
toast: true,
didOpen: () => {
expect(bodyStyles.paddingRight).to.equal('30px')
document.body.removeChild(talltDiv)
done()
},
})
})
const bodyStyles = window.getComputedStyle(document.body)
Swal.close()
})
it('should not add body padding if body has overflow-y: hidden', () => {
const talltDiv = document.createElement('div')
talltDiv.innerHTML = Array(100).join('<div>lorem ipsum</div>')
document.body.appendChild(talltDiv)
document.body.style.paddingRight = '0px'
document.body.style.overflowY = 'hidden'
SwalWithoutAnimation.fire()
const bodyStyles = window.getComputedStyle(document.body)
expect(bodyStyles.paddingRight).to.equal('0px')
document.body.removeChild(talltDiv)
Swal.close()
})
})