forked from malte-wessel/react-custom-scrollbars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniversal.js
110 lines (108 loc) · 5.29 KB
/
universal.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
import { Scrollbars } from 'react-custom-scrollbars';
import { render, unmountComponentAtNode } from 'react-dom';
import React from 'react';
export default function createTests(scrollbarWidth) {
let node;
beforeEach(() => {
node = document.createElement('div');
document.body.appendChild(node);
});
afterEach(() => {
unmountComponentAtNode(node);
document.body.removeChild(node);
});
describe('universal', () => {
describe('default', () => {
describe('when rendered', () => {
it('should hide overflow', done => {
class ScrollbarsTest extends Scrollbars {
// Override componentDidMount, so we can check, how the markup
// looks like on the first rendering
componentDidMount() {}
}
render((
<ScrollbarsTest universal style={{ width: 100, height: 100 }}>
<div style={{ width: 200, height: 200 }}/>
</ScrollbarsTest>
), node, function callback() {
const { view, trackHorizontal, trackVertical } = this;
expect(view.style.position).toEqual('absolute');
expect(view.style.overflow).toEqual('hidden');
expect(view.style.top).toEqual('0px');
expect(view.style.bottom).toEqual('0px');
expect(view.style.left).toEqual('0px');
expect(view.style.right).toEqual('0px');
expect(view.style.marginBottom).toEqual('0px');
expect(view.style.marginRight).toEqual('0px');
expect(trackHorizontal.style.display).toEqual('none');
expect(trackVertical.style.display).toEqual('none');
done();
});
});
});
describe('when componentDidMount', () => {
it('should rerender', done => {
render((
<Scrollbars universal style={{ width: 100, height: 100 }}>
<div style={{ width: 200, height: 200 }}/>
</Scrollbars>
), node, function callback() {
setTimeout(() => {
const { view } = this;
expect(view.style.overflow).toEqual('scroll');
expect(view.style.marginBottom).toEqual(`${-scrollbarWidth}px`);
expect(view.style.marginRight).toEqual(`${-scrollbarWidth}px`);
done();
}, 100);
});
});
});
});
describe('when using autoHeight', () => {
describe('when rendered', () => {
it('should hide overflow', done => {
class ScrollbarsTest extends Scrollbars {
// Override componentDidMount, so we can check, how the markup
// looks like on the first rendering
componentDidMount() {}
}
render((
<ScrollbarsTest universal autoHeight autoHeightMax={100}>
<div style={{ width: 200, height: 200 }}/>
</ScrollbarsTest>
), node, function callback() {
const { view, trackHorizontal, trackVertical } = this;
expect(view.style.position).toEqual('relative');
expect(view.style.overflow).toEqual('hidden');
expect(view.style.marginBottom).toEqual('0px');
expect(view.style.marginRight).toEqual('0px');
expect(view.style.minHeight).toEqual('0px');
expect(view.style.maxHeight).toEqual('100px');
expect(trackHorizontal.style.display).toEqual('none');
expect(trackVertical.style.display).toEqual('none');
done();
});
});
});
describe('when componentDidMount', () => {
it('should rerender', done => {
render((
<Scrollbars universal autoHeight autoHeightMax={100}>
<div style={{ width: 200, height: 200 }}/>
</Scrollbars>
), node, function callback() {
setTimeout(() => {
const { view } = this;
expect(view.style.overflow).toEqual('scroll');
expect(view.style.marginBottom).toEqual(`${-scrollbarWidth}px`);
expect(view.style.marginRight).toEqual(`${-scrollbarWidth}px`);
expect(view.style.minHeight).toEqual(`${scrollbarWidth}px`);
expect(view.style.maxHeight).toEqual(`${100 + scrollbarWidth}px`);
done();
});
});
});
});
});
});
}