height-and-contentHeight.js
7.67 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
(function() {
[ 'height', 'contentHeight' ].forEach(function(heightProp) { describe(heightProp, function() {
var options;
var heightElm;
var asAMethod;
beforeEach(function() {
affix('#cal');
$('#cal').width(900);
options = {
defaultDate: '2014-08-01'
};
});
function init(heightVal) {
if (asAMethod) {
$('#cal').fullCalendar(options);
$('#cal').fullCalendar('option', heightProp, heightVal);
}
else {
options[heightProp] = heightVal;
$('#cal').fullCalendar(options);
}
if (heightProp === 'height') {
heightElm = $('.fc');
}
else {
heightElm = $('.fc-view');
}
}
function expectHeight(heightVal) {
var diff;
if (heightProp === 'height') {
// Firefox is reporting off-by-one difference sometimes, even when things are good :(
diff = Math.abs(heightElm.outerHeight() - heightVal);
expect(diff).toBeLessThan(2); // off-by-one or exactly the same
}
else {
expect(heightElm.outerHeight()).toBe(heightVal);
}
}
$.each({
'as an init option': false,
'as a method': true
}, function(desc, bool) { describe(desc, function() {
beforeEach(function() {
asAMethod = bool;
});
describe('when in month view', function() {
beforeEach(function() {
options.defaultView = 'month';
});
describe('as a number, when there are no events', function() {
it('should be the specified height, with no scrollbars', function() {
init(600);
expect(heightElm.outerHeight()).toBe(600);
expect('.fc-day-grid-container').not.toHaveScrollbars();
});
});
describe('as a number, when there is one tall row of events', function() {
beforeEach(function() {
options.events = repeatClone({ title: 'event', start: '2014-08-04' }, 9);
});
it('should take away height from other rows, but not do scrollbars', function() {
init(600);
var rows = $('.fc-day-grid .fc-row');
var tallRow = rows.eq(1);
var shortRows = rows.not(tallRow); // 0, 2, 3, 4, 5
var shortHeight = shortRows.eq(0).outerHeight();
expectHeight(600);
shortRows.each(function(i, node) {
var rowHeight = $(node).outerHeight();
var diff = Math.abs(rowHeight - shortHeight);
expect(diff).toBeLessThan(10); // all roughly the same
});
expect(tallRow.outerHeight()).toBeGreaterThan(shortHeight * 2); // much taller
expect('.fc-day-grid-container').not.toHaveScrollbars();
});
});
describe('as a number, when there are many tall rows of events', function() {
beforeEach(function() {
options.events = [].concat(
repeatClone({ title: 'event0', start: '2014-07-28' }, 9),
repeatClone({ title: 'event1', start: '2014-08-04' }, 9),
repeatClone({ title: 'event2', start: '2014-08-11' }, 9),
repeatClone({ title: 'event3', start: '2014-08-18' }, 9),
repeatClone({ title: 'event4', start: '2014-08-25' }, 9),
repeatClone({ title: 'event5', start: '2014-09-01' }, 9)
);
});
it('height is correct and scrollbars show up', function() {
init(600);
expectHeight(600);
expect($('.fc-day-grid-container')).toHaveScrollbars();
});
});
describe('as "auto", when there are many tall rows of events', function() {
beforeEach(function() {
options.events = [].concat(
repeatClone({ title: 'event0', start: '2014-07-28' }, 9),
repeatClone({ title: 'event1', start: '2014-08-04' }, 9),
repeatClone({ title: 'event2', start: '2014-08-11' }, 9),
repeatClone({ title: 'event3', start: '2014-08-18' }, 9),
repeatClone({ title: 'event4', start: '2014-08-25' }, 9),
repeatClone({ title: 'event5', start: '2014-09-01' }, 9)
);
});
it('height is really tall and there are no scrollbars', function() {
init('auto');
expect(heightElm.outerHeight()).toBeGreaterThan(1000); // pretty tall
expect($('.fc-day-grid-container')).not.toHaveScrollbars();
});
});
});
[ 'basicWeek', 'basicDay' ].forEach(function(viewName) {
describe('in ' + viewName + ' view', function() {
beforeEach(function() {
options.defaultView = viewName;
});
describe('as a number, when there are no events', function() {
it('should be the specified height, with no scrollbars', function() {
init(600);
expectHeight(600);
expect('.fc-day-grid-container').not.toHaveScrollbars();
});
});
describe('as a number, when there are many events', function() {
beforeEach(function() {
options.events = repeatClone({ title: 'event', start: '2014-08-01' }, 100);
});
it('should have the correct height, with scrollbars', function() {
init(600);
expectHeight(600);
expect('.fc-day-grid-container').toHaveScrollbars();
});
});
describe('as "auto", when there are many events', function() {
beforeEach(function() {
options.events = repeatClone({ title: 'event', start: '2014-08-01' }, 100);
});
it('should be really tall with no scrollbars', function() {
init('auto');
expect(heightElm.outerHeight()).toBeGreaterThan(1000); // pretty tall
expect('.fc-day-grid-container').not.toHaveScrollbars();
});
});
});
});
[ 'agendaWeek', 'agendaDay' ].forEach(function(viewName) {
describe('in ' + viewName + ' view', function() {
beforeEach(function() {
options.defaultView = viewName;
});
$.each({
'with no all-day section': { allDaySlot: false },
'with no all-day events': { },
'with some all-day events': { events: repeatClone({ title: 'event', start: '2014-08-01' }, 6) }
}, function(desc, moreOptions) {
describe(desc, function() {
beforeEach(function() {
$.extend(options, moreOptions);
});
describe('as a number, with only a few slots', function() {
beforeEach(function() {
options.minTime = '06:00:00';
options.maxTime = '10:00:00';
});
it('should be the correct height, with a horizontal rule to occupy space', function() {
init(600);
expectHeight(600);
expect($('.fc-time-grid > hr')).toBeVisible();
});
});
describe('as a number, with many slots', function() {
beforeEach(function() {
options.minTime = '00:00:00';
options.maxTime = '24:00:00';
});
it('should be the correct height, with scrollbars and no filler hr', function() {
init(600);
expectHeight(600);
expect($('.fc-time-grid-container')).toHaveScrollbars();
expect($('.fc-time-grid > hr')).not.toBeVisible();
});
});
describe('as "auto", with only a few slots', function() {
beforeEach(function() {
options.minTime = '06:00:00';
options.maxTime = '10:00:00';
});
it('should be really short with no scrollbars nor horizontal rule', function() {
init('auto');
expect(heightElm.outerHeight()).toBeLessThan(500); // pretty short
expect($('.fc-time-grid-container')).not.toHaveScrollbars();
expect($('.fc-time-grid > hr')).not.toBeVisible();
});
});
describe('as a "auto", with many slots', function() {
beforeEach(function() {
options.minTime = '00:00:00';
options.maxTime = '24:00:00';
});
it('should be really tall with no scrollbars nor horizontal rule', function() {
init('auto');
expect(heightElm.outerHeight()).toBeGreaterThan(900); // pretty tall
expect($('.fc-time-grid-container')).not.toHaveScrollbars();
expect($('.fc-time-grid > hr')).not.toBeVisible();
});
});
});
});
});
});
}); });
}); });
function repeatClone(srcObj, times) {
var a = [];
var i;
for (i = 0; i < times; i++) {
a.push($.extend({}, srcObj));
}
return a;
}
})();