getScrollbarWidths.js
1.7 KB
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
describe('getScrollbarWidths', function() {
	var getScrollbarWidths = $.fullCalendar.getScrollbarWidths;
	defineTests(
		'when margin',
		{ margin: '5px 10px' }
	);
	defineTests(
		'when border',
		{ border: '5px solid red' }
	);
	defineTests(
		'when padding',
		{ padding: '5px 10px' }
	);
	defineTests(
		'when border and padding',
		{ border: '5px solid red', padding: '5px 10px' }
	);
	function defineTests(description, cssProps) {
		describe(description, function() {
			describe('when no scrolling', function() {
				describe('when LTR', function() {
					defineTest(false, 'ltr', cssProps);
				});
				describe('when RTL', function() {
					defineTest(false, 'rtl', cssProps);
				});
			});
			describe('when scrolling', function() {
				describe('when LTR', function() {
					defineTest(true, 'ltr', cssProps);
				});
				describe('when RTL', function() {
					defineTest(true, 'rtl', cssProps);
				});
			});
		});
	}
	function defineTest(isScrolling, dir, cssProps) {
		it('computes correct widths', function() {
			var el = $(
				'<div style="position:absolute" />'
				)
				.css('overflow', isScrolling ? 'scroll' : 'hidden')
				.css('direction', dir)
				.css(cssProps)
				.append('<div style="position:relative;width:100px;height:100px" />')
				.appendTo('body');
			var widths = getScrollbarWidths(el);
			var correctWidths;
			if (isScrolling) {
				correctWidths = getStockScrollbarWidths(dir);
			}
			else {
				correctWidths = { left: 0, right: 0, top: 0, bottom: 0 };
			}
			expect(widths.left).toBe(correctWidths.left);
			expect(widths.right).toBe(correctWidths.right);
			expect(widths.top).toBe(correctWidths.top);
			expect(widths.bottom).toBe(correctWidths.bottom);
			el.remove();
		});
	}
});